Spaces:
Runtime error
Runtime error
| 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): | |
| print("update record", reference) | |
| if "id" not in reference: | |
| raise ValueError("The 'id' parameter is required.") | |
| query = """ | |
| UPDATE metadata | |
| SET title = :title, | |
| category_id = :category_id, | |
| author = :author, | |
| year = :year, | |
| publisher = :publisher | |
| WHERE id = :id | |
| """ | |
| print(query) | |
| print(reference) | |
| try: | |
| await self._exec(query, reference) | |
| logging.info( | |
| f"Record with id {reference['id']} updated successfully." | |
| ) | |
| except Exception as e: | |
| logging.error( | |
| f"Error updating record with id {reference['id']}: {e}" | |
| ) | |
| raise | |