Skip to content

Commit

Permalink
recommit python example
Browse files Browse the repository at this point in the history
  • Loading branch information
skabbes committed Apr 30, 2022
1 parent a472da5 commit cb65539
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/python/src/authors/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
"""


UPDATE_AUTHOR = """-- name: update_author \\:exec
UPDATE authors
SET
name = coalesce(:p1, name),
bio = coalesce(:p2, bio)
WHERE id = :p3
"""


class Querier:
def __init__(self, conn: sqlalchemy.engine.Connection):
self._conn = conn
Expand Down Expand Up @@ -74,6 +83,9 @@ def list_authors(self) -> Iterator[models.Author]:
bio=row[2],
)

def update_author(self, *, name: Optional[str], bio: Optional[str], id: int) -> None:
self._conn.execute(sqlalchemy.text(UPDATE_AUTHOR), {"p1": name, "p2": bio, "p3": id})


class AsyncQuerier:
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
Expand Down Expand Up @@ -110,3 +122,6 @@ async def list_authors(self) -> AsyncIterator[models.Author]:
name=row[1],
bio=row[2],
)

async def update_author(self, *, name: Optional[str], bio: Optional[str], id: int) -> None:
await self._conn.execute(sqlalchemy.text(UPDATE_AUTHOR), {"p1": name, "p2": bio, "p3": id})

0 comments on commit cb65539

Please sign in to comment.