From 16f80717313d1f33e4f7fa274885293a0f28f9a9 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Fri, 6 Aug 2021 08:55:43 +0100 Subject: [PATCH] fix issue #267 --- lnbits/extensions/lnurlp/crud.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/lnurlp/crud.py b/lnbits/extensions/lnurlp/crud.py index 4d47a592..98c9d540 100644 --- a/lnbits/extensions/lnurlp/crud.py +++ b/lnbits/extensions/lnurlp/crud.py @@ -16,8 +16,14 @@ async def create_pay_link( success_text: Optional[str] = None, success_url: Optional[str] = None, ) -> PayLink: - result = await db.execute( - """ + + if db.type == "POSTGRES" or db.type == "COCKROACH": + returning = "RETURNING id" + else: + returning = "" + + result = await db.fetchone( + f""" INSERT INTO lnurlp.pay_links ( wallet, description, @@ -32,6 +38,7 @@ async def create_pay_link( currency ) VALUES (?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?) + {returning} """, ( wallet_id, @@ -45,7 +52,11 @@ async def create_pay_link( currency, ), ) - link_id = result._result_proxy.lastrowid + if db.type == "POSTGRES" or db.type == "COCKROACH": + link_id = result[0] + else: + link_id = result._result_proxy.lastrowid + link = await get_pay_link(link_id) assert link, "Newly created link couldn't be retrieved" return link @@ -68,7 +79,6 @@ async def get_pay_links(wallet_ids: Union[str, List[str]]) -> List[PayLink]: """, (*wallet_ids,), ) - return [PayLink.from_row(row) for row in rows]