Spaces:
Sleeping
Sleeping
File size: 1,118 Bytes
9002555 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import logging
from db.repository import Repository, get_db_conn
# Setup logging (configure as needed)
logging.basicConfig(level=logging.INFO)
class UpdateDatabase(Repository):
async def update_record(self, reference):
if "id" not in reference:
raise ValueError("The 'id' parameter is required.")
query = """
UPDATE Metadata
SET title = :title,
category = :category,
author = :author,
year = :year,
publisher = :publisher,
updatedAt = :updatedAt
WHERE id = :id
"""
print(query)
updated_reference = self.update_params(reference, update=True)
print(updated_reference)
try:
await self._exec(query, updated_reference)
logging.info(
f"Record with id {updated_reference['id']} updated successfully."
)
except Exception as e:
logging.error(
f"Error updating record with id {updated_reference['id']}: {e}"
)
raise
|