Spaces:
Runtime error
Runtime error
| from databases import Database | |
| import logging | |
| from dotenv import load_dotenv | |
| from db.repository import Repository | |
| load_dotenv() | |
| class InsertDatabase(Repository): | |
| # Example function to insert data asynchronously | |
| async def insert_data(self, params): | |
| # SQL insert query with named placeholders | |
| query = """ | |
| INSERT INTO Metadata (title, category, author, year, publisher, createdAt, updatedAt) | |
| VALUES (:title, :category, :author, :year, :publisher, :createdAt, :updatedAt) | |
| """ | |
| reference = self.update_params(params) | |
| try: | |
| # Execute the query with the provided values | |
| await self._exec(query, reference) | |
| logging.info( | |
| f"Data inserted successfully: {reference['title']}, {reference['author']}" | |
| ) | |
| except Exception as e: | |
| # Log any errors that occur during the database insert operation | |
| logging.error(f"Failed to insert data: {e}") | |
| raise # Re-raise the exception to allow further handling if needed | |