-
Notifications
You must be signed in to change notification settings - Fork 988
feat(mysql): Add database analyzer for MySQL #4201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Draft
Conversation
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
@dosubot
dosubot
bot
added
size:L
This PR changes 100-499 lines, ignoring generated files.
🔧 golang
labels
Nov 29, 2025
Adds a MySQL database analyzer that validates queries against a real MySQL
database during code generation. This is similar to the existing PostgreSQL
and SQLite analyzers.
Key features:
- Creates managed databases (sqlc_managed_{hash}) based on migration content
- Validates query syntax using PrepareContext against real MySQL
- Detects parameter count from ? placeholders
- Gracefully handles missing database connections
Also fixes several MySQL test cases to use correct MySQL syntax:
- Changed 1ドル/2ドル placeholders to ? (MySQL syntax)
- Added AS aliases to count(*) expressions in CTEs
- Fixed column references and table aliases
- Removed PostgreSQL-specific public. schema prefix
Tests requiring MySQL-specific features (HeatWave VECTOR functions, SHOW
WARNINGS in prepared statements, etc.) are restricted to base context.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
@kyleconroy
kyleconroy
force-pushed
the
claude/add-mysql-analyzer-1764455321
branch
3 times, most recently
from
November 29, 2025 23:59
3fc8768 to
e52cd4e
Compare
Updates the MySQL analyzer to use the sqlc-dev/mysql forked driver which exposes column and parameter metadata from COM_STMT_PREPARE responses. This provides more accurate type information directly from MySQL. The forked driver adds a StmtMetadata interface with ColumnMetadata() and ParamMetadata() methods that return type info including DatabaseTypeName, Nullable, Unsigned, and Length fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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
sqlc_managed_{hash}) based on migration content hash for cachingPrepareContextagainst real MySQLImplementation Details
The MySQL analyzer (
internal/engine/dolphin/analyzer/analyze.go) follows the same pattern as the SQLite analyzer:PrepareContextto validate queries against the real databaseTest Fixes
Fixed MySQL test cases that were using PostgreSQL-specific syntax:
1ドル/2ドルplaceholders to?(MySQL syntax)AS countaliases tocount(*)expressions in CTEsauthor_id→id,authors.parent_id→a.parent_id)public.schema prefixTests restricted to
basecontext (incompatible with real MySQL):mysql_vector- requires MySQL HeatWave (DISTANCE/STRING_TO_VECTOR functions)vet_explain- requires MySQL env vars for explain rulesshow_warnings- SHOW WARNINGS not supported in prepared statementsselect_subquery_no_alias- MySQL requires derived tables to have aliasesvalid_group_by_reference- MySQL's ONLY_FULL_GROUP_BY mode incompatibilityinsert_select_invalid,invalid_group_by_reference,invalid_table_alias- expected error messages differTest plan
go test ./...)go test --tags=examples -timeout 20m ./internal/endtoend/...)🤖 Generated with Claude Code