Green: implement custom object for arrays, update is ok
This commit is contained in:
parent
68e11a3275
commit
0ac827b95c
1
dev.py
1
dev.py
|
@ -104,6 +104,7 @@ async def update_movie(
|
|||
async def get_movie(id_: str, db: Session = Depends(get_db)):
|
||||
try:
|
||||
movie = crud.get_movie_by_id(db, id_)
|
||||
|
||||
out = {k: v for (k, v) in movie.__dict__.items() if not k.startswith("_")}
|
||||
except LookupError:
|
||||
raise HTTPException(status_code=404, detail=f"No movie found with id {id_}")
|
||||
|
|
21
models.py
21
models.py
|
@ -1,5 +1,20 @@
|
|||
from sqlalchemy import Column, ForeignKey, Integer, String, Float
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Float, types
|
||||
from database import Base
|
||||
import sqlalchemy.types as types
|
||||
|
||||
|
||||
class NaiveStringList(types.TypeDecorator):
|
||||
impl = types.Unicode
|
||||
sep = "\n"
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
return self.sep.join(value)
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
return value.split(self.sep)
|
||||
|
||||
def copy(self, **kw):
|
||||
return NaiveStringList(self.impl.length)
|
||||
|
||||
|
||||
class Movie(Base):
|
||||
|
@ -12,6 +27,8 @@ class Movie(Base):
|
|||
vote_count = Column(Integer)
|
||||
vote_average = Column(Float)
|
||||
|
||||
genres = Column(String) # String array dimention 1
|
||||
genres = Column(NaiveStringList) # LLw
|
||||
# genres = Column(ARRAY(String, dimensions=1)) # String array dimention 1
|
||||
|
||||
description = Column(String)
|
||||
release_date = Column(String)
|
||||
|
|
Loading…
Reference in New Issue