arista.db.connection

Open a SQLite connection with the project conventions enabled.

The pragmas applied here are:

  • foreign_keys = ON — schema enforces FK constraints; without this every CHECK / FK in arista.db.schema becomes silent metadata.

  • journal_mode = WAL — write-ahead logging, gives concurrent reads during bulk insert and is cheap to enable per-connection.

The context manager closes the connection deterministically so the caller doesn’t have to remember.

Functions

open_db(path, *[, create_parents, timeout])

Context manager around sqlite3.connect() with FK pragma.

resolve_db_path([explicit])

Return the canonical DB path per the documented resolution order.

arista.db.connection.open_db(path, *, create_parents=True, timeout=30.0)[source]

Context manager around sqlite3.connect() with FK pragma.

Parameters:
  • path (str | Path) – Database file path. Created on first connect if absent.

  • create_parents (bool) – True (default) creates the parent directory tree if it does not exist — convenient for the /mnt/data/arista/arista.db case where the lab datadrive mount-point exists but the project subdirectory may not.

  • timeout (float) – SQLite lock-wait timeout in seconds.

Yields:

An open sqlite3.Connection with foreign-key enforcement on and the WAL journal mode active.

Return type:

Iterator[Connection]

arista.db.connection.resolve_db_path(explicit=None)[source]

Return the canonical DB path per the documented resolution order.

Parameters:

explicit (str | Path | None) – A user-supplied path (e.g. from --db on the CLI). None means defer to the environment / default.

Returns:

Absolute Path to the target database file. The file itself need not exist yet — callers may open or build it.

Return type:

Path