Efficient way of passing params in SQLAlchemy
@app.post("/posts", status_code=status.HTTP_201_CREATED)
def create_posts(post: Post, db: Session = Depends(get_db)):
# Like this:
new_post = models.Post(title=post.title, content=post.content, published=post.published)
db.add(new_post)
db.commit()
db.refresh(new_post)
return { "data": new_post }@app.post("/posts", status_code=status.HTTP_201_CREATED)
def create_posts(post: Post, db: Session = Depends(get_db)):
# Like this:
new_post = models.Post(**post.dict())
db.add(new_post)
db.commit()
db.refresh(new_post)
return { "data": new_post }Last updated