aboutsummaryrefslogtreecommitdiff
path: root/src/db_handler.py
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2026-06-15 21:24:56 +0200
committeruser@node5.net <user@node5.net>2026-06-15 21:24:56 +0200
commit38b8178cce160b3d2e6c8b3256c7655f4d0a27cd (patch)
treeee232c74e786890a4d2bad8b1d89e2b5a5e2c6e6 /src/db_handler.py
parent693525e6444a74980ddfffb32ffe561c53dfcc24 (diff)
internalize needed files for starting the program
Diffstat (limited to 'src/db_handler.py')
-rw-r--r--src/db_handler.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/db_handler.py b/src/db_handler.py
index 471154a..b063692 100644
--- a/src/db_handler.py
+++ b/src/db_handler.py
@@ -1,13 +1,23 @@
import logging
-from dataclasses import dataclass
-
import sqlite3
+import os
logger = logging.getLogger(__name__) # Set the logger name, to the name of the module
class DBHandler:
+ def __init__(self, db_init_script_path: os.PathLike, db_path: str = "blog.node5.net.db"):
+ self.db_init_script_path = db_init_script_path
+ self.db_path = db_path
+ if not os.path.exists(self.db_path):
+ script = open(self.db_init_script_path, "r", encoding="utf-8").read()
+ with self.con_factory() as con:
+ con.executescript(script)
+ con.commit()
+ logger.info("Database initialized from %s", self.db_init_script_path)
+
+
def con_factory(self) -> sqlite3.Connection:
con = sqlite3.connect("blog.node5.net.db")
return con