From b764c93e7c82e2c2ab33c7a1456202a8eddafcf6 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 9 Jan 2023 14:21:14 +0200 Subject: [PATCH] fix: (rollback refactoring) Use the `tipjar` id to fetch the created `tipjar` --- lnbits/extensions/tipjar/crud.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lnbits/extensions/tipjar/crud.py b/lnbits/extensions/tipjar/crud.py index 1b58a43d..080eaf1c 100644 --- a/lnbits/extensions/tipjar/crud.py +++ b/lnbits/extensions/tipjar/crud.py @@ -33,7 +33,11 @@ async def create_tip( async def create_tipjar(data: createTipJar) -> TipJar: """Create a new TipJar""" - await db.execute( + + returning = "" if db.type == SQLITE else "RETURNING ID" + method = db.execute if db.type == SQLITE else db.fetchone + + result = await (method)( f""" INSERT INTO tipjar.TipJars ( name, @@ -42,11 +46,16 @@ async def create_tipjar(data: createTipJar) -> TipJar: onchain ) VALUES (?, ?, ?, ?) + {returning} """, (data.name, data.wallet, data.webhook, data.onchain), ) - row = await db.fetchone("SELECT * FROM tipjar.TipJars LIMIT 1") - tipjar = TipJar(**row) + if db.type == SQLITE: + tipjar_id = result._result_proxy.lastrowid + else: + tipjar_id = result[0] + + tipjar = await get_tipjar(tipjar_id) assert tipjar return tipjar