Fix UI DuckDB concurrent access with read-only mode
- Add read_only parameter to DataStorage.connect() - UI now connects in read-only mode to avoid lock conflicts with engine
This commit is contained in:
@@ -27,22 +27,24 @@ class DataStorage:
|
||||
storage.disconnect()
|
||||
"""
|
||||
|
||||
def __init__(self, db_path: Path) -> None:
|
||||
def __init__(self, db_path: Path, *, read_only: bool = False) -> None:
|
||||
"""Initialize storage with database path.
|
||||
|
||||
Args:
|
||||
db_path: Path to DuckDB database file
|
||||
read_only: If True, open database in read-only mode (no locking)
|
||||
"""
|
||||
self.db_path = db_path
|
||||
self._read_only = read_only
|
||||
self._conn: duckdb.DuckDBPyConnection | None = None
|
||||
|
||||
def connect(self) -> None:
|
||||
"""Connect to the database."""
|
||||
# Ensure parent directory exists
|
||||
self.db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not self._read_only:
|
||||
self.db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
self._conn = duckdb.connect(str(self.db_path))
|
||||
logger.info("Connected to DuckDB", path=str(self.db_path))
|
||||
self._conn = duckdb.connect(str(self.db_path), read_only=self._read_only)
|
||||
logger.info("Connected to DuckDB", path=str(self.db_path), read_only=self._read_only)
|
||||
|
||||
def disconnect(self) -> None:
|
||||
"""Close database connection."""
|
||||
|
||||
Reference in New Issue
Block a user