mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2025-06-08 21:15:09 +02:00
initial commit
This commit is contained in:
commit
0961d0e47d
15 changed files with 564 additions and 0 deletions
20
crud.py
Normal file
20
crud.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import DECIMAL, cast
|
||||
|
||||
import models, schemas
|
||||
|
||||
def get_items(db: Session) -> list[models.Item]:
|
||||
return db.query(models.Item).order_by(models.Item.type, cast(models.Item.id, DECIMAL))
|
||||
|
||||
|
||||
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()
|
Loading…
Add table
Add a link
Reference in a new issue