sqlite
¶
Full name: tenets.storage.sqlite
sqlite¶
SQLite storage utilities for Tenets.
This module centralizes SQLite database path resolution, connection management, and pragmas. All persistent storage (sessions, tenets, config state) should use this utility to open connections inside the configured cache directory.
By default, the cache directory is resolved by TenetsConfig. Do not write inside the installed package directory. When Tenets is installed via pip, the package location may be read-only; the cache directory will be user- or project-local and writable.
Classes¶
SQLitePathsdataclass
¶
Database¶
SQLite database manager applying Tenets pragmas.
Use this to obtain connections to the main Tenets DB file located in the configured cache directory.
Source code in tenets/storage/sqlite.py
Functions¶
connect¶
Open a SQLite connection with configured PRAGMAs applied.
PARAMETER | DESCRIPTION |
---|---|
db_path | Optional custom DB path; defaults to main DB path. |
Source code in tenets/storage/sqlite.py
def connect(self, db_path: Optional[Path] = None) -> sqlite3.Connection:
"""Open a SQLite connection with configured PRAGMAs applied.
Args:
db_path: Optional custom DB path; defaults to main DB path.
Returns:
sqlite3.Connection ready for use.
"""
path = Path(db_path) if db_path else self.paths.main_db
# Enable declared-type and column-name based conversions and allow
# cross-thread usage for tests that access the same connection across threads.
conn = sqlite3.connect(
path,
detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES,
check_same_thread=False,
)
self._apply_pragmas(conn, self.config.cache.sqlite_pragmas)
return conn