fix livestream for postgres compatibility

fix producers create returning id
This commit is contained in:
Tiago vasconcelos 2021-08-13 09:32:34 +01:00 committed by fiatjaf
parent 1c0a4e252a
commit 4ce0ed63c0

View File

@ -160,14 +160,21 @@ async def add_producer(livestream: int, name: str) -> int:
user = await create_account()
wallet = await create_wallet(user_id=user.id, wallet_name="livestream: " + name)
result = 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 livestream.producers (livestream, name, "user", wallet)
VALUES (?, ?, ?, ?)
{returning}
""",
(livestream, name, user.id, wallet.id),
)
return result._result_proxy.lastrowid
if db.type == SQLITE:
return result._result_proxy.lastrowid
else:
return result[0]
async def get_producer(producer_id: int) -> Optional[Producer]: