aboutsummaryrefslogtreecommitdiff
path: root/src/db_handler.py
diff options
context:
space:
mode:
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