async def create_user_item(db: Session, item: schemas.ItemCreate, user_id: int): db_item = models.Item(**item.dict(), owner_id=user_id) await db.add(db_item) await db.commit() await db.refresh(db_item) return db_item
def create_user_item(db: Session, item: schemas.ItemCreate, user_id: int): """Create user item""" db_item = models.Item(**item.dict(), owner_id=user_id) db.add(db_item) db.commit() db.refresh(db_item) return db_item
def create_user_item(cls, db: Session, item: schemas.ItemCreate, user_id: int): db_item = cls.database(**item.dict(), owner_id=user_id) db.add(db_item) db.commit() db.refresh(db_item) return db_item
def create_item(item_create: ItemCreate = Body( ..., example={ "name": "An Item", "description": "What it is." }, )): dict_item = item_create.dict() keys, values = ', '.join(dict_item.keys()), ', '.join( map(lambda v: f"'{str(v)}'", dict_item.values())) with db_connection() as db: db.execute(f"insert into items ({keys}) values ({values})") return item_create
def create_user_item(item: schemas.ItemCreate, user_id: int): db_item = models.Item(**item.dict(), owner_id=user_id) db_item.save() return db_item
def create_item(db: Session, item: schemas.ItemCreate): db_item = models.Item(**item.dict()) db.add(db_item) db.commit() db.refresh(db_item) return db_item
async def create_user_item(item: schemas.ItemCreate, user_id: int): query = items.insert().values(**item.dict(), owner_id=user_id) item_id = await database.execute(query) return schemas.Item(**item.dict(), id=item_id, owner_id=user_id)