22 lines
512 B
Python
22 lines
512 B
Python
"""SQLite connection and schema bootstrap."""
|
|
import sqlite3
|
|
|
|
from db.schema import ACCOUNTS_TABLE_SQL
|
|
from util.runtime_paths import get_db_path
|
|
|
|
|
|
def get_conn():
|
|
return sqlite3.connect(get_db_path())
|
|
|
|
|
|
def init_db():
|
|
conn = get_conn()
|
|
try:
|
|
cur = conn.cursor()
|
|
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='accounts'")
|
|
if not cur.fetchone():
|
|
cur.executescript(ACCOUNTS_TABLE_SQL)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|