pipeloom.db¶
pipeloom.db ¶
db.py¶
Low-level, thread-bound SQLite helpers (connection + schema + checkpoint).
Design rules:¶
- Create one connection in the writer thread; never share it across threads.
- Prefer WAL for on-disk DBs to allow concurrent readers during writes.
- Keep pragmas pragmatic: good performance without wrecking durability.
connect ¶
Create and configure a thread-bound SQLite connection.
Must be called from the writer thread. The connection is not safe to pass to worker threads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path
|
Path to SQLite database (may be :memory:). |
required |
wal
|
bool
|
Enable WAL mode for file-backed databases. |
True
|
Returns:
| Type | Description |
|---|---|
Connection
|
sqlite3.Connection |
Source code in pipeloom/db.py
init_schema ¶
Create optional tables used for observability (task_runs).
If you set store_task_status=False, this becomes a no-op and the DB is
entirely yours for domain tables (e.g., ETL outputs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
The SQLite connection to use. |
required |
store_task_status
|
bool
|
If True, create the |
required |
Source code in pipeloom/db.py
wal_checkpoint ¶
wal_checkpoint(conn: Connection, mode: Literal['PASSIVE', 'FULL', 'RESTART', 'TRUNCATE'] = 'TRUNCATE') -> None
Manually checkpoint the WAL into the main DB and (optionally) truncate -wal.
Useful at shutdown or between phases to keep the main file tidy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
The SQLite connection to use. |
required |
mode
|
Literal['PASSIVE', 'FULL', 'RESTART', 'TRUNCATE']
|
The checkpoint mode. - PASSIVE: Only checkpoint if there are no active readers. - FULL: Checkpoint and truncate the WAL. - RESTART: Checkpoint and restart the WAL. - TRUNCATE: Checkpoint and truncate the WAL. |
'TRUNCATE'
|