コード例 #1
0
async def update(book_id: int, db: DatabaseSession = Depends(get_db)):
    model = db.query(Book).filter(Book.id == book_id).first()
    model.read = True
    db.add(model)
    db.commit()
    return {
        'id': model.id,
    }
コード例 #2
0
async def create(book: BookModel, db: DatabaseSession = Depends(get_db)):
    now = datetime.now()
    model = Book(title=book.title, created_at=now, read=False)
    db.add(model)
    db.commit()
    return {
        'id': model.id,
        'title': model.title,
        'created_at': model.created_at.isoformat()
    }