Add async SQLAlchemy backend support with union type dispatch#14
Open
Add async SQLAlchemy backend support with union type dispatch#14
Conversation
Extend the database layer to support async SQLAlchemy sessions alongside existing sync sessions. Every public activity tracker function now accepts both Session and AsyncSession via overloaded signatures with isinstance detection — pass an AsyncSession and the call returns an awaitable coroutine, pass a Session (or None) and it executes synchronously as before. The public API names are unchanged. Key changes: - core/db: add async session factory, DatabaseEngine/DatabaseSession type aliases, set_global_async_session/get_global_async_session helpers - activity/models: add async classmethods (aappend_log, aget_by_agent_id, aget_list, aget_pending_ids, aget_active_count) using selectinload for relationship access - activity/tracker: overload create, update, complete, error, cancel_pending, list, detail, count_active for sync/async dispatch - Export DatabaseEngine and DatabaseSession from top-level package - Add aiosqlite dev dependency and comprehensive async test suite https://claude.ai/code/session_011TEKqVAGZi4xhkB5Fqqujv
…tinload Extract SQL statement construction into private _*_stmt() classmethods shared by both sync and async execution paths. Sync methods now use select() instead of the legacy session.query() API, and get_by_agent_id uses explicit selectinload(logs) instead of relying on implicit lazy loading. The async methods are now thin await wrappers with zero duplicated query logic. https://claude.ai/code/session_011TEKqVAGZi4xhkB5Fqqujv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend the database layer to support async SQLAlchemy sessions alongside
existing sync sessions. Every public activity tracker function now accepts
both Session and AsyncSession via overloaded signatures with isinstance
detection — pass an AsyncSession and the call returns an awaitable
coroutine, pass a Session (or None) and it executes synchronously as
before. The public API names are unchanged.
Key changes:
aliases, set_global_async_session/get_global_async_session helpers
aget_list, aget_pending_ids, aget_active_count) using selectinload for
relationship access
cancel_pending, list, detail, count_active for sync/async dispatch
https://claude.ai/code/session_011TEKqVAGZi4xhkB5Fqqujv