diff --git a/engine.py b/engine.py index 03ed9b8..eb90d85 100644 --- a/engine.py +++ b/engine.py @@ -18,11 +18,15 @@ class SorterEngine: @contextmanager def get_connection(): """Context manager for efficient DB connections with WAL mode.""" + # Ensure directory exists + db_dir = os.path.dirname(SorterEngine.DB_PATH) + if db_dir and not os.path.exists(db_dir): + os.makedirs(db_dir, exist_ok=True) + conn = sqlite3.connect(SorterEngine.DB_PATH, check_same_thread=False) conn.execute("PRAGMA journal_mode=WAL") # Write-Ahead Logging for speed conn.execute("PRAGMA synchronous=NORMAL") # Faster writes conn.execute("PRAGMA cache_size=2000") # ~2MB cache - conn.row_factory = sqlite3.Row # Efficient row access try: yield conn finally: