in-c4/crud.py

21 lines
553 B
Python
Raw Permalink Normal View History

2022-08-04 05:41:51 +02:00
from sqlalchemy.orm import Session
from sqlalchemy import DECIMAL, cast
import models, schemas
def get_items(db: Session) -> list[models.Item]:
2022-08-06 02:38:47 +02:00
return db.query(models.Item).all()
2022-08-04 05:41:51 +02:00
def put_item(db: Session, id: str, item: schemas.Item):
updated = bool(db.query(models.Item).filter(models.Item.id == id).update(item.dict()))
if not updated:
db.add(models.Item(**item.dict()))
db.commit()
return updated
def delete_item(db: Session, id: str):
db.query(models.Item).filter(models.Item.id == id).delete()
db.commit()