Merge pull request #1334 from motorina0/fix_wrong_tipjar_id

fix: (rollback refactoring) Use the `tipjar` id to fetch the created `tipjar`
This commit is contained in:
calle 2023-01-09 14:31:03 +01:00 committed by GitHub
commit bdf5980a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,7 +33,11 @@ async def create_tip(
async def create_tipjar(data: createTipJar) -> TipJar: async def create_tipjar(data: createTipJar) -> TipJar:
"""Create a new 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""" f"""
INSERT INTO tipjar.TipJars ( INSERT INTO tipjar.TipJars (
name, name,
@ -42,11 +46,16 @@ async def create_tipjar(data: createTipJar) -> TipJar:
onchain onchain
) )
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?)
{returning}
""", """,
(data.name, data.wallet, data.webhook, data.onchain), (data.name, data.wallet, data.webhook, data.onchain),
) )
row = await db.fetchone("SELECT * FROM tipjar.TipJars LIMIT 1") if db.type == SQLITE:
tipjar = TipJar(**row) tipjar_id = result._result_proxy.lastrowid
else:
tipjar_id = result[0]
tipjar = await get_tipjar(tipjar_id)
assert tipjar assert tipjar
return tipjar return tipjar