Migrate download queue from JSON to SQLite database
- Created QueueRepository adapter in src/server/services/queue_repository.py - Refactored DownloadService to use repository pattern instead of JSON - Updated application startup to initialize download service from database - Updated all test fixtures to use MockQueueRepository - All 1104 tests passing
This commit is contained in:
@@ -264,3 +264,35 @@ def get_sync_session() -> Session:
|
||||
)
|
||||
|
||||
return _sync_session_factory()
|
||||
|
||||
|
||||
def get_async_session_factory() -> AsyncSession:
|
||||
"""Get a new async database session (factory function).
|
||||
|
||||
Creates a new session instance for use in repository patterns.
|
||||
The caller is responsible for committing/rolling back and closing.
|
||||
|
||||
Returns:
|
||||
AsyncSession: New database session for async operations
|
||||
|
||||
Raises:
|
||||
RuntimeError: If database is not initialized
|
||||
|
||||
Example:
|
||||
session = get_async_session_factory()
|
||||
try:
|
||||
result = await session.execute(select(AnimeSeries))
|
||||
await session.commit()
|
||||
return result.scalars().all()
|
||||
except Exception:
|
||||
await session.rollback()
|
||||
raise
|
||||
finally:
|
||||
await session.close()
|
||||
"""
|
||||
if _session_factory is None:
|
||||
raise RuntimeError(
|
||||
"Database not initialized. Call init_db() first."
|
||||
)
|
||||
|
||||
return _session_factory()
|
||||
|
||||
Reference in New Issue
Block a user