storage ¶
SQLite connection lifecycle for persistent caches and benchmarks.
open_database ¶
open_database(path: StrPath, *, timeout: float, validate: Callable[[Connection], None] | None = None) -> sqlite3.Connection
Open a SQLite connection with WAL enabled for file databases.
Use the connection in its creating thread and commit successful writes explicitly. Validation failures close the connection and propagate to callers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | StrPath | Database path, or | required |
timeout | float | Finite, nonnegative lock timeout in seconds. | required |
validate | Callable[[Connection], None] | None | Optional connection check run before journal setup. | None |
Returns:
| Type | Description |
|---|---|
Connection | An open connection owned by the caller. |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Error | If opening the database or configuring its journal fails. |
Source code in src/gdelt_regkg/storage.py
close_database ¶
Roll back pending work and close a SQLite connection.
The connection is closed even if rollback fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection | Connection | None | Connection to close. Passing | required |
Raises:
| Type | Description |
|---|---|
Error | If rollback or closure fails. |