Added paginated fetching to withdraw link table (#41)
Some checks failed
/ release (push) Has been cancelled
/ pullrequest (push) Has been cancelled

This commit is contained in:
Julian 2024-07-19 07:22:46 +02:00 committed by GitHub
commit 00064f65d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 23 deletions

33
crud.py
View file

@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Optional, Union
from typing import List, Optional, Tuple
import shortuuid
from lnbits.db import Database
@ -87,19 +87,32 @@ async def get_withdraw_link_by_hash(unique_hash: str, num=0) -> Optional[Withdra
return WithdrawLink.parse_obj(link)
async def get_withdraw_links(wallet_ids: Union[str, List[str]]) -> List[WithdrawLink]:
if isinstance(wallet_ids, str):
wallet_ids = [wallet_ids]
q = ",".join(["?"] * len(wallet_ids))
async def get_withdraw_links(
wallet_ids: List[str], limit: int, offset: int
) -> Tuple[List[WithdrawLink], int]:
rows = await db.fetchall(
f"""
"""
SELECT * FROM withdraw.withdraw_link
WHERE wallet IN ({q}) ORDER BY open_time DESC
""",
WHERE wallet IN ({})
ORDER BY open_time DESC
LIMIT ? OFFSET ?
""".format(
",".join("?" * len(wallet_ids))
),
(*wallet_ids, limit, offset),
)
total = await db.fetchone(
"""
SELECT COUNT(*) as total FROM withdraw.withdraw_link
WHERE wallet IN ({})
""".format(
",".join("?" * len(wallet_ids))
),
(*wallet_ids,),
)
return [WithdrawLink(**row) for row in rows]
return [WithdrawLink(**row) for row in rows], total["total"]
async def remove_unique_withdraw_link(link: WithdrawLink, unique_hash: str) -> None: