Spaces:
Sleeping
Sleeping
File size: 1,067 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 |
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
|