Beispiel #1
0
 async def books_by_title_year(self, *, title: str, year: int) -> AsyncIterator[models.Book]:
     result = await self._conn.stream(sqlalchemy.text(BOOKS_BY_TITLE_YEAR), {"p1": title, "p2": year})
     async for row in result:
         yield models.Book(
             book_id=row[0],
             author_id=row[1],
             isbn=row[2],
             book_type=row[3],
             title=row[4],
             year=row[5],
             available=row[6],
             tags=row[7],
         )
Beispiel #2
0
 async def get_book(self, *, book_id: int) -> Optional[models.Book]:
     row = (await self._conn.execute(sqlalchemy.text(GET_BOOK), {"p1": book_id})).first()
     if row is None:
         return None
     return models.Book(
         book_id=row[0],
         author_id=row[1],
         isbn=row[2],
         book_type=row[3],
         title=row[4],
         year=row[5],
         available=row[6],
         tags=row[7],
     )
Beispiel #3
0
 async def create_book(self, arg: CreateBookParams) -> Optional[models.Book]:
     row = (await self._conn.execute(sqlalchemy.text(CREATE_BOOK), {
         "p1": arg.author_id,
         "p2": arg.isbn,
         "p3": arg.book_type,
         "p4": arg.title,
         "p5": arg.year,
         "p6": arg.available,
         "p7": arg.tags,
     })).first()
     if row is None:
         return None
     return models.Book(
         book_id=row[0],
         author_id=row[1],
         isbn=row[2],
         book_type=row[3],
         title=row[4],
         year=row[5],
         available=row[6],
         tags=row[7],
     )