Added paginated fetching to withdraw link table (#41)
This commit is contained in:
parent
a44820f61f
commit
00064f65d0
4 changed files with 50 additions and 23 deletions
33
crud.py
33
crud.py
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue