26 lines
648 B
Python
26 lines
648 B
Python
import sqlite3
|
|
from erminig.config import Config
|
|
|
|
|
|
def init_db():
|
|
if Config.DB_PATH.exists():
|
|
return
|
|
|
|
conn = sqlite3.connect(Config.DB_PATH)
|
|
with open(Config.BASE_DIR / "schema.sql", "r") as f:
|
|
conn.executescript(f.read())
|
|
conn.commit()
|
|
conn.close()
|
|
print("Base erminig.db initialisée avec succès.")
|
|
|
|
|
|
class ErminigDB:
|
|
def __enter__(self):
|
|
self.conn = sqlite3.connect(Config.DB_PATH)
|
|
self.conn.row_factory = sqlite3.Row
|
|
self.cursor = self.conn.cursor()
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
self.conn.commit()
|
|
self.conn.close()
|