You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Determine whether the configuration targets a local Ollama instance.
129
+
130
+
Returns:
131
+
`true` if `anthropic_base_url` is set, `anthropic_auth_token` equals `"ollama"`, and the base URL's hostname is `localhost`, `127.0.0.1`, or `::1`; `false` otherwise.
Get a robust SQLite connection with proper settings for concurrent access.
111
-
112
-
This should be used by all code that accesses the database directly via sqlite3
113
-
(not through SQLAlchemy). It ensures consistent settings across all access points.
114
-
115
-
Settings applied:
116
-
- WAL mode for better concurrency (unless on network filesystem)
117
-
- Busy timeout of 30 seconds
118
-
- Synchronous mode NORMAL for balance of safety and performance
119
-
120
-
Args:
121
-
db_path: Path to the SQLite database file
122
-
116
+
Open and configure a sqlite3.Connection optimized for concurrent access.
117
+
118
+
Configures the connection with a 30-second busy timeout, enables WAL journal mode when the database file is on a local filesystem, and sets synchronous mode to NORMAL.
119
+
120
+
Parameters:
121
+
db_path (Path): Path to the SQLite database file.
122
+
123
123
Returns:
124
-
Configured sqlite3.Connection
125
-
124
+
sqlite3.Connection: Configured SQLite connection.
125
+
126
126
Raises:
127
-
sqlite3.Error: If connection cannot be established
127
+
sqlite3.Error: If the database connection or PRAGMA configuration fails.
Context manager for robust SQLite connections with automatic cleanup.
152
-
153
-
Usage:
154
-
with robust_db_connection(db_path) as conn:
155
-
cursor = conn.cursor()
156
-
cursor.execute("SELECT * FROM features")
157
-
158
-
Args:
159
-
db_path: Path to the SQLite database file
160
-
151
+
Context manager that yields a configured sqlite3.Connection and ensures it is closed on exit.
152
+
153
+
Parameters:
154
+
db_path (Path): Path to the SQLite database file.
155
+
161
156
Yields:
162
-
Configured sqlite3.Connection
157
+
sqlite3.Connection: A configured connection to the database; closed when the context exits.
163
158
"""
164
159
conn=None
165
160
try:
@@ -178,22 +173,21 @@ def execute_with_retry(
178
173
max_retries: int=SQLITE_MAX_RETRIES
179
174
) ->Any:
180
175
"""
181
-
Execute a SQLite query with automatic retry on transient errors.
182
-
183
-
Handles SQLITE_BUSY and SQLITE_LOCKED errors with exponential backoff.
184
-
185
-
Args:
186
-
db_path: Path to the SQLite database file
187
-
query: SQL query to execute
188
-
params: Query parameters (tuple)
189
-
fetch: What to fetch - "none", "one", "all"
190
-
max_retries: Maximum number of retry attempts
191
-
176
+
Execute a SQL statement against the given SQLite file and retry on transient lock/busy errors.
177
+
178
+
Parameters:
179
+
db_path (Path): Path to the SQLite database file.
180
+
query (str): SQL statement to execute.
181
+
params (tuple): Parameters to bind to the SQL statement.
182
+
fetch (str): Result mode: "none" commits and returns the number of affected rows, "one" returns a single row (or None), "all" returns all rows as a list.
183
+
max_retries (int): Maximum number of retry attempts for transient errors.
184
+
192
185
Returns:
193
-
Query result based on fetch parameter
194
-
186
+
int | tuple | list | None: For `fetch == "none"`, the number of rows affected; for `fetch == "one"`, a single row tuple or `None`; for `fetch == "all"`, a list of row tuples.
187
+
195
188
Raises:
196
-
sqlite3.Error: If query fails after all retries
189
+
sqlite3.DatabaseError: On database corruption or other database-level errors.
190
+
sqlite3.OperationalError: If the statement fails after all retries (including persistent lock/busy conditions).
197
191
"""
198
192
last_error=None
199
193
delay=SQLITE_RETRY_DELAY_MS/1000# Convert to seconds
@@ -241,13 +235,17 @@ def execute_with_retry(
241
235
242
236
defcheck_database_health(db_path: Path) ->dict:
243
237
"""
244
-
Check the health of a SQLite database.
245
-
238
+
Assess the integrity and journal mode of a SQLite database file.
239
+
240
+
Parameters:
241
+
db_path (Path): Path to the SQLite database file to check.
242
+
246
243
Returns:
247
-
Dict with:
248
-
- healthy (bool): True if database passes integrity check
249
-
- journal_mode (str): Current journal mode (WAL/DELETE/etc)
250
-
- error (str, optional): Error message if unhealthy
244
+
dict: A dictionary containing:
245
+
- healthy (bool): `True` if the database passes PRAGMA integrity_check, `False` otherwise.
246
+
- journal_mode (str, optional): The current journal mode (e.g., "WAL", "DELETE") when available.
247
+
- integrity (str, optional): The raw result of PRAGMA integrity_check when available (e.g., "ok").
248
+
- error (str, optional): Error message when the file is missing or an integrity/IO error occurred.
251
249
"""
252
250
ifnotdb_path.exists():
253
251
return {"healthy": False, "error": "Database file does not exist"}
0 commit comments