feat: add aiomysql adapter#413
Open
hasansezertasan wants to merge 2 commits intolitestar-org:mainfrom
Open
Conversation
Add a new async MySQL adapter using aiomysql (built on PyMySQL), complementing the existing asyncmy adapter. This gives teams with inherited aiomysql codebases a path to adopt sqlspec without a driver migration. Key implementation details: - Exception handling uses pymysql.err.* (aiomysql's underlying error hierarchy) - Connection.cursor() is synchronous (same as asyncmy, despite aiomysql docs) - Pool API uses aiomysql.create_pool() with "db" key (not "database" like asyncmy) - Parameter style: QMARK input -> POSITIONAL_PYFORMAT execution (identical to asyncmy) - Extensions (ADK, Litestar, Events) deferred to follow-up Refs: litestar-org#412 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- cursor() returns a Future on pool-acquired connections, must be awaited - Fix protocol to match (async cursor method) - Run ruff format on all new files to pass pre-commit validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
asyncmyadapter structure for consistencyCloses #412
Motivation
Teams with inherited
aiomysqlcodebases can adopt sqlspec without a driver migration. See #412 for full rationale.Implementation notes
Key differences from the
asyncmyadapter:asyncmy.errors.*pymysql.err.*(re-exported)"database""db"asyncmy.constants.FIELD_TYPEpymysql.constants.FIELD_TYPEasyncmy.create_pool()aiomysql.create_pool()Connection.cursor()is synchronous in both drivers (verified against aiomysql source — the docs are misleading).What's included
sqlspec/adapters/aiomysql/— full driver-only adapter (6 files, ~1,450 LOC)tests/unit/adapters/test_aiomysql/— unit tests (passing)tests/integration/adapters/aiomysql/— integration tests (need MySQL container in CI)pyproject.toml— optional dep, pytest marker, mypy ignoreWhat's NOT included (deferred)
SSCursorserver-side streaming supportTest plan
pytest tests/unit/adapters/test_aiomysql/ -v)pytest-databases)🤖 Generated with Claude Code