-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathquery-building.py
More file actions
47 lines (34 loc) · 1.17 KB
/
query-building.py
File metadata and controls
47 lines (34 loc) · 1.17 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
45
46
47
# Code generated by sqlc. DO NOT EDIT.
# versions:
# sqlc v1.28.0
# source: query-building.sql
from typing import AsyncIterator, Optional
import sqlalchemy
import sqlalchemy.ext.asyncio
from jets import models
COUNT_PILOTS = """-- name: count_pilots \\:one
SELECT COUNT(*) FROM pilots
"""
DELETE_PILOT = """-- name: delete_pilot \\:exec
DELETE FROM pilots WHERE id = :p1
"""
LIST_PILOTS = """-- name: list_pilots \\:many
SELECT id, name FROM pilots LIMIT 5
"""
class AsyncQuerier:
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
self._conn = conn
async def count_pilots(self) -> Optional[int]:
row = (await self._conn.execute(sqlalchemy.text(COUNT_PILOTS))).first()
if row is None:
return None
return row[0]
async def delete_pilot(self, *, id: int) -> None:
await self._conn.execute(sqlalchemy.text(DELETE_PILOT), {"p1": id})
async def list_pilots(self) -> AsyncIterator[models.Pilot]:
result = await self._conn.stream(sqlalchemy.text(LIST_PILOTS))
async for row in result:
yield models.Pilot(
id=row[0],
name=row[1],
)