-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.py
39 lines (26 loc) · 1.05 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
from typing import List
from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
from .models import CreateSatspot, Satspot
db = Database("ext_satspot")
async def create_satspot(data: CreateSatspot, wallet, user) -> List[Satspot]:
satspot = Satspot(**data.dict(), id=urlsafe_short_hash(), wallet=wallet, user=user)
await db.insert("satspot.satspot", satspot)
return await get_satspots(user)
async def update_satspot(satspot: Satspot) -> Satspot:
await db.update("satspot.satspot", satspot)
return satspot
async def get_satspot(satspot_id: str) -> Satspot:
return await db.fetchone(
"SELECT * FROM satspot.satspot WHERE id = :id",
{"id": satspot_id},
Satspot,
)
async def get_satspots(user: str) -> List[Satspot]:
return await db.fetchall(
"SELECT * FROM satspot.satspot WHERE 'user' = :user",
{"user": user},
Satspot,
)
async def delete_satspot(satspot_id: str) -> None:
await db.execute("DELETE FROM satspot.satspot WHERE id = :id", {"id": satspot_id})