-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathcrud.py
52 lines (33 loc) · 1.17 KB
/
crud.py
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
from app.api.models import NoteSchema
from app.db import notes, async_session
async def post(payload: NoteSchema):
query = notes.insert().values(title=payload.title, description=payload.description)
with async_session() as db:
response = await db.execute(query=query)
return response
async def get(id: int):
query = notes.select().where(id == notes.c.id)
with async_session() as db:
response = await db.execute(query=query)
return response
async def get_all():
query = notes.select()
with async_session() as db:
response = await db.execute(query=query)
return response
async def put(id: int, payload: NoteSchema):
query = (
notes
.update()
.where(id == notes.c.id)
.values(title=payload.title, description=payload.description)
.returning(notes.c.id)
)
with async_session() as db:
response = await db.execute(query=query)
return response
async def delete(id: int):
query = notes.delete().where(id == notes.c.id)
with async_session() as db:
response = await db.execute(query=query)
return response