|
| 1 | + |
1 | 2 | # Code generated by sqlc. DO NOT EDIT.
|
2 | 3 | from typing import AsyncIterator, Iterator, Optional
|
3 | 4 |
|
|
35 | 36 | """
|
36 | 37 |
|
37 | 38 |
|
38 |
| -class Query: |
| 39 | +class Querier: |
39 | 40 | def __init__(self, conn: sqlalchemy.engine.Connection):
|
40 | 41 | self._conn = conn
|
41 | 42 |
|
42 |
| - def create_author(self, name: str, bio: Optional[str]) -> Optional[models.Author]: |
43 |
| - result = self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio}) |
44 |
| - return models.Author(**dict(result.first())) |
45 |
| - |
46 |
| - def delete_author(self, id: int) -> None: |
| 43 | + def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Author]: |
| 44 | + row = self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio}).first() |
| 45 | + if row is None: |
| 46 | + return None |
| 47 | + return models.Author( |
| 48 | + id=row[0], |
| 49 | + name=row[1], |
| 50 | + bio=row[2], |
| 51 | + ) |
| 52 | + |
| 53 | + def delete_author(self, *, id: int) -> None: |
47 | 54 | self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})
|
48 | 55 |
|
49 |
| - def get_author(self, id: int) -> Optional[models.Author]: |
50 |
| - result = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}) |
51 |
| - return models.Author(**dict(result.first())) |
| 56 | + def get_author(self, *, id: int) -> Optional[models.Author]: |
| 57 | + row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first() |
| 58 | + if row is None: |
| 59 | + return None |
| 60 | + return models.Author( |
| 61 | + id=row[0], |
| 62 | + name=row[1], |
| 63 | + bio=row[2], |
| 64 | + ) |
52 | 65 |
|
53 | 66 | def list_authors(self) -> Iterator[models.Author]:
|
54 | 67 | result = self._conn.execute(sqlalchemy.text(LIST_AUTHORS))
|
55 | 68 | for row in result:
|
56 |
| - yield models.Author(**dict(row)) |
| 69 | + yield models.Author( |
| 70 | + id=row[0], |
| 71 | + name=row[1], |
| 72 | + bio=row[2], |
| 73 | + ) |
57 | 74 |
|
58 | 75 |
|
59 |
| -class AsyncQuery: |
| 76 | +class AsyncQuerier: |
60 | 77 | def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
|
61 | 78 | self._conn = conn
|
62 | 79 |
|
63 |
| - async def create_author(self, name: str, bio: Optional[str]) -> Optional[models.Author]: |
64 |
| - result = await self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio}) |
65 |
| - return models.Author(**dict(result.first())) |
66 |
| - |
67 |
| - async def delete_author(self, id: int) -> None: |
| 80 | + async def create_author(self, *, name: str, bio: Optional[str]) -> Optional[models.Author]: |
| 81 | + row = (await self._conn.execute(sqlalchemy.text(CREATE_AUTHOR), {"p1": name, "p2": bio})).first() |
| 82 | + if row is None: |
| 83 | + return None |
| 84 | + return models.Author( |
| 85 | + id=row[0], |
| 86 | + name=row[1], |
| 87 | + bio=row[2], |
| 88 | + ) |
| 89 | + |
| 90 | + async def delete_author(self, *, id: int) -> None: |
68 | 91 | await self._conn.execute(sqlalchemy.text(DELETE_AUTHOR), {"p1": id})
|
69 | 92 |
|
70 |
| - async def get_author(self, id: int) -> Optional[models.Author]: |
71 |
| - result = await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}) |
72 |
| - return models.Author(**dict(result.first())) |
| 93 | + async def get_author(self, *, id: int) -> Optional[models.Author]: |
| 94 | + row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first() |
| 95 | + if row is None: |
| 96 | + return None |
| 97 | + return models.Author( |
| 98 | + id=row[0], |
| 99 | + name=row[1], |
| 100 | + bio=row[2], |
| 101 | + ) |
73 | 102 |
|
74 | 103 | async def list_authors(self) -> AsyncIterator[models.Author]:
|
75 | 104 | result = await self._conn.stream(sqlalchemy.text(LIST_AUTHORS))
|
76 | 105 | async for row in result:
|
77 |
| - yield models.Author(**dict(row)) |
| 106 | + yield models.Author( |
| 107 | + id=row[0], |
| 108 | + name=row[1], |
| 109 | + bio=row[2], |
| 110 | + ) |
| 111 | + |
0 commit comments