This commit is contained in:
Soenke committed 2026-09-23 18:14:39 +02:00
1 parent 704d590a42
commit d53fd4790b
2 files changed
+29 -5

No files matched your search

+16 -2
View File
@@ -10,7 +10,21 @@ class Database:
async def connect(self):
if self.conn is None:
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
self.conn = await aiosqlite.connect(DB_PATH)
db_existed = os.path.exists(DB_PATH)
if db_existed:
print(f"Using existing database file at {DB_PATH}")
else:
print(f"Database file not found at {DB_PATH}, creating a new one...")
try:
self.conn = await aiosqlite.connect(DB_PATH)
except aiosqlite.Error as e:
print(f"Failed to open database at {DB_PATH}: {e}")
raise
if not db_existed and not os.path.exists(DB_PATH):
print(f"Warning: database file was expected at {DB_PATH} but still missing after connect.")
try:
await self.conn.executescript("""
@@ -44,7 +58,7 @@ class Database:
await self.conn.commit()
print("Table check/creation completed successfully.")
except aiosqlite.Error as e:
print(f"Failed to check/creation table: {e}")