|
| 1 | +# Code generated by sqlc. DO NOT EDIT. |
| 2 | +# versions: |
| 3 | +# sqlc v1.23.0 |
| 4 | +# source: query.sql |
| 5 | +fromtypingimportAsyncIterator, Iterator, Optional |
| 6 | + |
| 7 | +importsqlalchemy |
| 8 | +importsqlalchemy.ext.asyncio |
| 9 | + |
| 10 | +fromauthorsimportmodels |
| 11 | + |
| 12 | + |
| 13 | +CREATE_AUTHOR="""-- name: create_author \\:one |
| 14 | +INSERT INTO authors ( |
| 15 | + name, bio |
| 16 | +) VALUES ( |
| 17 | + :p1, :p2 |
| 18 | +) |
| 19 | +RETURNING id, name, bio |
| 20 | +""" |
| 21 | + |
| 22 | + |
| 23 | +DELETE_AUTHOR="""-- name: delete_author \\:exec |
| 24 | +DELETE FROM authors |
| 25 | +WHERE id = :p1 |
| 26 | +""" |
| 27 | + |
| 28 | + |
| 29 | +GET_AUTHOR="""-- name: get_author \\:one |
| 30 | +SELECT id, name, bio FROM authors |
| 31 | +WHERE id = :p1 LIMIT 1 |
| 32 | +""" |
| 33 | + |
| 34 | + |
| 35 | +LIST_AUTHORS="""-- name: list_authors \\:many |
| 36 | +SELECT id, name, bio FROM authors |
| 37 | +ORDER BY name |
| 38 | +""" |
| 39 | + |
| 40 | + |
| 41 | +classQuerier: |
| 42 | +def__init__(self, conn: sqlalchemy.engine.Connection): |
| 43 | +self._conn=conn |
| 44 | + |
| 45 | +defcreate_author(self, *, name: str, bio: Optional[str]) ->Optional[models.Author]: |
| 46 | +row=self._conn.execute(sqlalchemy.text(CREATE_AUTHOR),{"p1": name, "p2": bio}).first() |
| 47 | +ifrowisNone: |
| 48 | +returnNone |
| 49 | +returnmodels.Author( |
| 50 | +id=row[0], |
| 51 | +name=row[1], |
| 52 | +bio=row[2], |
| 53 | + ) |
| 54 | + |
| 55 | +defdelete_author(self, *, id: int) ->None: |
| 56 | +self._conn.execute(sqlalchemy.text(DELETE_AUTHOR),{"p1": id}) |
| 57 | + |
| 58 | +defget_author(self, *, id: int) ->Optional[models.Author]: |
| 59 | +row=self._conn.execute(sqlalchemy.text(GET_AUTHOR),{"p1": id}).first() |
| 60 | +ifrowisNone: |
| 61 | +returnNone |
| 62 | +returnmodels.Author( |
| 63 | +id=row[0], |
| 64 | +name=row[1], |
| 65 | +bio=row[2], |
| 66 | + ) |
| 67 | + |
| 68 | +deflist_authors(self) ->Iterator[models.Author]: |
| 69 | +result=self._conn.execute(sqlalchemy.text(LIST_AUTHORS)) |
| 70 | +forrowinresult: |
| 71 | +yieldmodels.Author( |
| 72 | +id=row[0], |
| 73 | +name=row[1], |
| 74 | +bio=row[2], |
| 75 | + ) |
| 76 | + |
| 77 | + |
| 78 | +classAsyncQuerier: |
| 79 | +def__init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection): |
| 80 | +self._conn=conn |
| 81 | + |
| 82 | +asyncdefcreate_author(self, *, name: str, bio: Optional[str]) ->Optional[models.Author]: |
| 83 | +row= (awaitself._conn.execute(sqlalchemy.text(CREATE_AUTHOR),{"p1": name, "p2": bio})).first() |
| 84 | +ifrowisNone: |
| 85 | +returnNone |
| 86 | +returnmodels.Author( |
| 87 | +id=row[0], |
| 88 | +name=row[1], |
| 89 | +bio=row[2], |
| 90 | + ) |
| 91 | + |
| 92 | +asyncdefdelete_author(self, *, id: int) ->None: |
| 93 | +awaitself._conn.execute(sqlalchemy.text(DELETE_AUTHOR),{"p1": id}) |
| 94 | + |
| 95 | +asyncdefget_author(self, *, id: int) ->Optional[models.Author]: |
| 96 | +row= (awaitself._conn.execute(sqlalchemy.text(GET_AUTHOR),{"p1": id})).first() |
| 97 | +ifrowisNone: |
| 98 | +returnNone |
| 99 | +returnmodels.Author( |
| 100 | +id=row[0], |
| 101 | +name=row[1], |
| 102 | +bio=row[2], |
| 103 | + ) |
| 104 | + |
| 105 | +asyncdeflist_authors(self) ->AsyncIterator[models.Author]: |
| 106 | +result=awaitself._conn.stream(sqlalchemy.text(LIST_AUTHORS)) |
| 107 | +asyncforrowinresult: |
| 108 | +yieldmodels.Author( |
| 109 | +id=row[0], |
| 110 | +name=row[1], |
| 111 | +bio=row[2], |
| 112 | + ) |
0 commit comments