-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathquery.py
More file actions
44 lines (34 loc) · 1.07 KB
/
query.py
File metadata and controls
44 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Code generated by sqlc. DO NOT EDIT.
# versions:
# sqlc v1.30.0
# source: query.sql
from typing import Optional
import sqlalchemy
import sqlalchemy.ext.asyncio
from db import models
GET_AUTHOR = """-- name: get_author \\:one
SELECT id, class FROM authors
WHERE id = :p1 LIMIT 1
"""
class Querier:
def __init__(self, conn: sqlalchemy.engine.Connection):
self._conn = conn
def get_author(self, *, id: int) -> Optional[models.Author]:
row = self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id}).first()
if row is None:
return None
return models.Author(
id=row[0],
class_=row[1],
)
class AsyncQuerier:
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
self._conn = conn
async def get_author(self, *, id: int) -> Optional[models.Author]:
row = (await self._conn.execute(sqlalchemy.text(GET_AUTHOR), {"p1": id})).first()
if row is None:
return None
return models.Author(
id=row[0],
class_=row[1],
)