コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
 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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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)