def delete_metadata(dbcon: DBConnection, object_type: str, object_id: int,
keys: Optional[Iterable[str]] = None):
"""Delete metadata for an object.
If keys is given, only delete the specified keys, otherwise delete all
metadata for the object.
"""
async def _run(cur: Cursor) -> None:
if keys:
# noinspection PyTypeChecker
for key in keys:
q = """delete from object_metadata where object_type=%s and object_id=%s and `key`=%s"""
q_args = (object_type, object_id, key) # type: Tuple
await cur.execute(q, q_args)
else:
q = """delete from object_metadata where object_type=%s and object_id=%s"""
q_args = (object_type, object_id)
await cur.execute(q, q_args)
await dbcon.transact(_run)
评论列表
文章目录