Spaces:
Runtime error
Runtime error
Download db/save_data.py from Multimedika/Bot_Development: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Multimedika/Bot_Development/resolve/4a2b28f736a28cfd8d28be2779d27b2e003a38a4/db/save_data.py
- Command line
-
hf download hf://spaces/Multimedika/Bot_Development@4a2b28f736a28cfd8d28be2779d27b2e003a38a4/db/save_data.py
-
curl -L -o save_data.py https://huggingface.co/spaces/Multimedika/Bot_Development/resolve/4a2b28f736a28cfd8d28be2779d27b2e003a38a4/db/save_data.py
1.07 kB
| 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 | |