Les choses sérieuses commencent
This commit is contained in:
parent
7a9fe18463
commit
c63f62721b
41 changed files with 1270 additions and 0 deletions
26
erminig/models/db.py
Normal file
26
erminig/models/db.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue