emmental/emmental/db/__init__.py

35 lines
958 B
Python

# Copyright 2022 (c) Anna Schumaker
"""Easily work with our underlying sqlite3 database."""
import pathlib
from gi.repository import GObject
from . import connection
from . import settings
from . import table
SQL_SCRIPT = pathlib.Path(__file__).parent / "emmental.sql"
class Connection(connection.Connection):
"""Connect to the database."""
def __init__(self):
"""Initialize a sqlite connection."""
super().__init__()
match self("PRAGMA user_version").fetchone()["user_version"]:
case 0:
with open(SQL_SCRIPT) as f:
self._sql.executescript(f.read())
self.settings = settings.Table(self)
def load(self) -> None:
"""Load the database tables."""
self.settings.load()
@GObject.Signal(arg_types=(table.Table,))
def table_loaded(self, tbl: table.Table) -> None:
"""Signal that a table has been loaded."""
tbl.loaded = True