BIG rename
This commit is contained in:
1 parent
77db374418
commit
0bc06358e8
19 files changed
+275
-307
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import aiosqlite
|
||||
from time import time
|
||||
|
||||
time = int(time()) # we dont need no stinkin floats
|
||||
|
||||
# db = await aiosqlite.connect("edderkop.db") # type: ignore
|
||||
# db = await aiosqlite.connect("studspider.db") # type: ignore
|
||||
|
||||
|
||||
async def close(db):
|
||||
await db.close()
|
||||
|
||||
|
||||
async def fetch(table, sqobj):
|
||||
"""
|
||||
Asynchronously fetch a record from the REVIEW table by sq_object.
|
||||
@@ -16,13 +19,16 @@ async def fetch(table, sqobj):
|
||||
Returns:
|
||||
dict or None: The fetched record as a dictionary, or None if not found.
|
||||
"""
|
||||
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
|
||||
async with db.execute(f"SELECT * FROM {table} WHERE sq_object = {sqobj}") as cursor:
|
||||
async with aiosqlite.connect("studspider.db") as db: # type: ignore
|
||||
async with db.execute(
|
||||
f"SELECT * FROM {table} WHERE sq_object = {sqobj}"
|
||||
) as cursor:
|
||||
async for row in cursor:
|
||||
return row
|
||||
|
||||
return None
|
||||
|
||||
|
||||
async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
"""
|
||||
Asynchronously insert or update a record in the specified table.
|
||||
@@ -37,9 +43,11 @@ async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
"""
|
||||
print(f"Upserting into {table}: {data}")
|
||||
|
||||
columns = ', '.join(data.keys())
|
||||
placeholders = ', '.join('?' * len(data))
|
||||
updates = ', '.join(f"{col}=excluded.{col}" for col in data.keys() if col != unique_key)
|
||||
columns = ", ".join(data.keys())
|
||||
placeholders = ", ".join("?" * len(data))
|
||||
updates = ", ".join(
|
||||
f"{col}=excluded.{col}" for col in data.keys() if col != unique_key
|
||||
)
|
||||
|
||||
sql = f"""
|
||||
INSERT INTO {table} ({columns})
|
||||
@@ -47,7 +55,7 @@ async def upsert(table: str, data: dict, unique_key: str) -> bool:
|
||||
ON CONFLICT({unique_key}) DO UPDATE SET
|
||||
{updates};
|
||||
"""
|
||||
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
|
||||
async with aiosqlite.connect("studspider.db") as db: # type: ignore
|
||||
async with db.execute(sql, tuple(data.values())) as cursor:
|
||||
await db.commit()
|
||||
return True
|
||||
Reference in new issue
Block a user