From 9804b6d673bd4bd164891bec18928bb6bd0670aa Mon Sep 17 00:00:00 2001 From: C <0xicl33n@gmail.com> Date: Sat, 11 Oct 2025 13:56:13 -0700 Subject: [PATCH] fix up db fetch and insert --- src/db.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/db.py b/src/db.py index 5e5f4de..02bbbec 100644 --- a/src/db.py +++ b/src/db.py @@ -3,7 +3,11 @@ from time import time time = int(time()) # we dont need no stinkin floats # db = await aiosqlite.connect("edderkop.db") # type: ignore -async def fetch(sqobj): + +async def close(db): + await db.close() + +async def fetch(table, sqobj): """ Asynchronously fetch a record from the REVIEW table by sq_object. @@ -13,21 +17,17 @@ async def fetch(sqobj): dict or None: The fetched record as a dictionary, or None if not found. """ async with aiosqlite.connect("edderkop.db") as db: # type: ignore - db.row_factory = aiosqlite.Row # type: ignore - async with db.execute( - "SELECT * FROM REVIEW WHERE sq_object = ?", (sqobj,) - ) as cursor: - row = await cursor.fetchone() - if row: - return dict(row) - return None + async with db.execute(f"SELECT * FROM {table} WHERE sq_object = {sqobj}") as cursor: + async for row in cursor: + return row -async def upsert(table: str, data: dict, unique_key: str) -> None: + return None + +async def upsert(table: str, data: dict, unique_key: str) -> bool: """ Asynchronously insert or update a record in the specified table. Args: - sq_ib (aiosqlite.Connection): The SQLite database connection. table (str): The name of the table to upsert into. data (dict): A dictionary of column-value pairs to insert or update. unique_key (str): The column name that serves as the unique key for upsert. @@ -50,4 +50,4 @@ async def upsert(table: str, data: dict, unique_key: str) -> None: async with aiosqlite.connect("edderkop.db") as db: # type: ignore async with db.execute(sql, tuple(data.values())) as cursor: await db.commit() - #await db.close() \ No newline at end of file + return True