Skip to content

feat: add aiomysql adapter#413

Open
hasansezertasan wants to merge 2 commits intolitestar-org:mainfrom
hasansezertasan:feat/hasansezertasan/add-aiomysql-adapter
Open

feat: add aiomysql adapter#413
hasansezertasan wants to merge 2 commits intolitestar-org:mainfrom
hasansezertasan:feat/hasansezertasan/add-aiomysql-adapter

Conversation

@hasansezertasan
Copy link
Copy Markdown

Summary

  • Add new async MySQL adapter using aiomysql (built on PyMySQL)
  • Mirrors the existing asyncmy adapter structure for consistency
  • Extensions (ADK, Litestar, Events) deferred to follow-up

Closes #412

Motivation

Teams with inherited aiomysql codebases can adopt sqlspec without a driver migration. See #412 for full rationale.

Implementation notes

Key differences from the asyncmy adapter:

Aspect asyncmy aiomysql
Error hierarchy asyncmy.errors.* pymysql.err.* (re-exported)
DB name config key "database" "db"
FIELD_TYPE source asyncmy.constants.FIELD_TYPE pymysql.constants.FIELD_TYPE
Pool creation asyncmy.create_pool() aiomysql.create_pool()
Parameter style QMARK → POSITIONAL_PYFORMAT identical

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 ignore

What's NOT included (deferred)

  • Extension stores (ADK, Litestar, Events)
  • SSCursor server-side streaming support
  • Docs page updates

Test plan

  • Unit tests pass locally (pytest tests/unit/adapters/test_aiomysql/ -v)
  • Integration tests pass in CI (requires MySQL container via pytest-databases)
  • No regressions in existing adapters

Disclosure: This PR was drafted with AI assistance (Claude Code) based on my motivation and direction. Authored by @hasansezertasan — I take responsibility for its content and will engage with any review feedback.

🤖 Generated with Claude Code

hasansezertasan and others added 2 commits April 12, 2026 17:30
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>
@hasansezertasan hasansezertasan marked this pull request as ready for review April 13, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: add aiomysql adapter

1 participant