-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
32 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,40 @@ | ||
from typing import Optional, Union | ||
from typing import List, Optional, Union | ||
|
||
from lnbits.db import Database | ||
from lnbits.helpers import insert_query, update_query | ||
|
||
from .models import EightBall | ||
|
||
db = Database("ext_eightball") | ||
|
||
|
||
async def create_eightball(data: EightBall) -> EightBall: | ||
await db.execute( | ||
insert_query("eightball.maintable", data), | ||
(*data.dict().values(),), | ||
) | ||
return data | ||
return await db.insert("eightball.maintable", data) | ||
|
||
|
||
async def get_eightball(eightball_id: str) -> Optional[EightBall]: | ||
row = await db.fetchone( | ||
"SELECT * FROM eightball.maintable WHERE id = ?", (eightball_id,) | ||
return await db.fetchone( | ||
"SELECT * FROM eightball.maintable WHERE id = :id", | ||
{"id": eightball_id}, | ||
EightBall, | ||
) | ||
return EightBall(**row) if row else None | ||
|
||
|
||
async def get_eightballs(wallet_ids: Union[str, list[str]]) -> list[EightBall]: | ||
async def get_eightballs(wallet_ids: Union[str, List[str]]) -> List[EightBall]: | ||
if isinstance(wallet_ids, str): | ||
wallet_ids = [wallet_ids] | ||
|
||
q = ",".join(["?"] * len(wallet_ids)) | ||
rows = await db.fetchall( | ||
f"SELECT * FROM eightball.maintable WHERE wallet IN ({q})", (*wallet_ids,) | ||
q = ",".join([f"'{w}'" for w in wallet_ids]) | ||
return await db.fetchall( | ||
f"SELECT * FROM eightball.maintable WHERE wallet IN ({q}) ORDER BY id", | ||
model=EightBall, | ||
) | ||
return [EightBall(**row) for row in rows] | ||
|
||
|
||
async def update_eightball(eightball: EightBall) -> EightBall: | ||
await db.execute( | ||
update_query("eightball.maintable", eightball), | ||
( | ||
*eightball.dict().values(), | ||
eightball.id, | ||
), | ||
) | ||
await db.update("eightball.maintable", eightball) | ||
return eightball | ||
|
||
|
||
async def delete_eightball(eightball_id: str) -> None: | ||
await db.execute("DELETE FROM eightball.maintable WHERE id = ?", (eightball_id,)) | ||
await db.execute( | ||
"DELETE FROM eightball.maintable WHERE id = :id", {"id": eightball_id} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters