parent
d656d41b90
commit
a8eb139360
25 changed files with 3192 additions and 237 deletions
26
crud.py
26
crud.py
|
|
@ -1,12 +1,14 @@
|
|||
from typing import List, Optional
|
||||
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
from lnbits.db import Database
|
||||
|
||||
from . import db
|
||||
from .models import Config, Relay
|
||||
|
||||
db = Database("ext_nostrclient")
|
||||
|
||||
async def get_relays() -> List[Relay]:
|
||||
|
||||
async def get_relays() -> list[Relay]:
|
||||
rows = await db.fetchall("SELECT * FROM nostrclient.relays")
|
||||
return [Relay.from_row(r) for r in rows]
|
||||
|
||||
|
|
@ -37,27 +39,21 @@ async def create_config() -> Config:
|
|||
INSERT INTO nostrclient.config (json_data)
|
||||
VALUES (?)
|
||||
""",
|
||||
(json.dumps(config.dict())),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
(json.dumps(config.dict()),),
|
||||
)
|
||||
row = await db.fetchone("SELECT json_data FROM nostrclient.config", ())
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d))
|
||||
|
||||
|
||||
async def update_config(config: Config) -> Optional[Config]:
|
||||
await db.execute(
|
||||
"""UPDATE nostrclient.config SET json_data = ?""",
|
||||
(json.dumps(config.dict())),
|
||||
)
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
(json.dumps(config.dict()),),
|
||||
)
|
||||
row = await db.fetchone("SELECT json_data FROM nostrclient.config", ())
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d))
|
||||
|
||||
|
||||
async def get_config() -> Optional[Config]:
|
||||
row = await db.fetchone(
|
||||
"SELECT json_data FROM nostrclient.config", ()
|
||||
)
|
||||
row = await db.fetchone("SELECT json_data FROM nostrclient.config", ())
|
||||
return json.loads(row[0], object_hook=lambda d: Config(**d)) if row else None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue