mirror of
https://github.com/kevin-DL/fast_api_api_template.git
synced 2026-01-11 09:44:34 +00:00
17 lines
424 B
Python
17 lines
424 B
Python
from sqlalchemy.orm import Session
|
|
|
|
from models.items import Item
|
|
from schemas.items import ItemCreate
|
|
|
|
|
|
def get_items(db: Session, skip: int = 0, limit: int = 100):
|
|
return db.query(Item).offset(skip).limit(limit).all()
|
|
|
|
|
|
def create_user_item(db: Session, item: ItemCreate, user_id: str):
|
|
db_item = Item(**item.dict(), owner_id=user_id)
|
|
db.add(db_item)
|
|
db.commit()
|
|
db.refresh(db_item)
|
|
return db_item
|