feat: add function to update the extra JSON values

This commit is contained in:
Vlad Stan 2022-12-21 14:57:00 +02:00
parent b68b8a0292
commit dd4a9f10cf

View file

@ -451,6 +451,36 @@ async def update_payment_details(
return
async def update_payment_extra(
payment_hash: str,
extra: dict,
conn: Optional[Connection] = None,
) -> None:
"""
Only update the `extra` field for the payment.
Old values in the `extra` JSON object will be kept unless the new `extra` overwrites them.
"""
row = await (conn or db).fetchone(
"SELECT hash, extra from apipayments WHERE hash = ?",
(payment_hash),
)
if not row:
return
existing_extra = json.loads(row["extra"] if row["extra"] else "{}")
new_extra = {
**existing_extra,
**extra,
}
await (conn or db).execute(
"""
UPDATE apipayments SET extra = ?
WHERE hash = ?
""",
(json.dumps(new_extra), payment_hash),
)
async def delete_payment(checking_id: str, conn: Optional[Connection] = None) -> None:
await (conn or db).execute(
"DELETE FROM apipayments WHERE checking_id = ?", (checking_id,)