-
Notifications
You must be signed in to change notification settings - Fork 3
/
crud.py
42 lines (29 loc) · 1.09 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
from typing import List, Optional
from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
from .models import Copilot, CreateCopilotData
db = Database("ext_copilot")
async def create_copilot(data: CreateCopilotData) -> Copilot:
copilot_id = urlsafe_short_hash()
copilot = Copilot(id=copilot_id, **data.dict())
await db.insert("copilot.newer_copilots", copilot)
return copilot
async def update_copilot(copilot: Copilot) -> Copilot:
await db.update("copilot.newer_copilots", copilot)
return copilot
async def get_copilot(copilot_id: str) -> Optional[Copilot]:
return await db.fetchone(
"SELECT * FROM copilot.newer_copilots WHERE id = :id",
{"id": copilot_id},
Copilot,
)
async def get_copilots(user: str) -> List[Copilot]:
return await db.fetchall(
'SELECT * FROM copilot.newer_copilots WHERE "user" = :user',
{"user": user},
Copilot,
)
async def delete_copilot(copilot_id: str) -> None:
await db.execute(
"DELETE FROM copilot.newer_copilots WHERE id = :id", {"id": copilot_id}
)