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): | |
| 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 | |