-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathquery.py
More file actions
89 lines (71 loc) · 2.58 KB
/
query.py
File metadata and controls
89 lines (71 loc) · 2.58 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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 querytest import models
DELETE_BAR_BY_ID = """-- name: delete_bar_by_id \\:one
DELETE FROM bars WHERE id = :p1 RETURNING id, name
"""
DELETE_EXCLUSION_BY_ID = """-- name: delete_exclusion_by_id \\:one
DELETE FROM exclusions WHERE id = :p1 RETURNING id, name
"""
DELETE_MY_DATA_BY_ID = """-- name: delete_my_data_by_id \\:one
DELETE FROM my_data WHERE id = :p1 RETURNING id, name
"""
class Querier:
def __init__(self, conn: sqlalchemy.engine.Connection):
self._conn = conn
def delete_bar_by_id(self, *, id: int) -> Optional[models.Bar]:
row = self._conn.execute(sqlalchemy.text(DELETE_BAR_BY_ID), {"p1": id}).first()
if row is None:
return None
return models.Bar(
id=row[0],
name=row[1],
)
def delete_exclusion_by_id(self, *, id: int) -> Optional[models.Exclusions]:
row = self._conn.execute(sqlalchemy.text(DELETE_EXCLUSION_BY_ID), {"p1": id}).first()
if row is None:
return None
return models.Exclusions(
id=row[0],
name=row[1],
)
def delete_my_data_by_id(self, *, id: int) -> Optional[models.MyData]:
row = self._conn.execute(sqlalchemy.text(DELETE_MY_DATA_BY_ID), {"p1": id}).first()
if row is None:
return None
return models.MyData(
id=row[0],
name=row[1],
)
class AsyncQuerier:
def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
self._conn = conn
async def delete_bar_by_id(self, *, id: int) -> Optional[models.Bar]:
row = (await self._conn.execute(sqlalchemy.text(DELETE_BAR_BY_ID), {"p1": id})).first()
if row is None:
return None
return models.Bar(
id=row[0],
name=row[1],
)
async def delete_exclusion_by_id(self, *, id: int) -> Optional[models.Exclusions]:
row = (await self._conn.execute(sqlalchemy.text(DELETE_EXCLUSION_BY_ID), {"p1": id})).first()
if row is None:
return None
return models.Exclusions(
id=row[0],
name=row[1],
)
async def delete_my_data_by_id(self, *, id: int) -> Optional[models.MyData]:
row = (await self._conn.execute(sqlalchemy.text(DELETE_MY_DATA_BY_ID), {"p1": id})).first()
if row is None:
return None
return models.MyData(
id=row[0],
name=row[1],
)