Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

@kyleconroykyleconroy commented Oct 5, 2023

94 of the open issues on sqlc are related to the analyzer. There are many cases where the current analyzer produces false positives or false negatives.

sqlx and some other projects have proven that it's possible to extract query metadata from a running database.

This approach is a bit different, in that the database analysis is layered on top of the existing query analyzer. We use the existing analysis for better name and NULL inference.

This PR is an obvious work in progress, but I'm happy enough with the result to share an early peek.

@kyleconroykyleconroy changed the title feat(analyzer): Analyze queryies using a PostgreSQL databasefeat(analyzer): Analyze queries using a running PostgreSQL databaseOct 10, 2023
94 of the open issues on sqlc are related to the analyzer. There are many cases where the current analyzer produces false positives or false negatives. sqlx and some other projects have proven that it's possible to extract query metadata from a running database. This approach is a bit different, in that the database analysis is layered on top of the existing query analyzer. We use the new analysis to provide better type information and support a wider set of cases when the existing analyzer fails.
Add a `contexts` key to exec.json to opt certain tests into or out of database-backed analysis. Fix many incorrect test cases that didn't run against an actual database.
@kyleconroykyleconroyforce-pushed the kyle/analyzer-pg-prepare branch from a762b00 to 48f638bCompareOctober 10, 2023 23:49
@kyleconroykyleconroy marked this pull request as ready for review October 12, 2023 01:24
@kyleconroykyleconroy merged commit bb84596 into mainOct 12, 2023
@kyleconroykyleconroy deleted the kyle/analyzer-pg-prepare branch October 12, 2023 17:32
alfonsodev pushed a commit to ExponentiaTeam/sqlc that referenced this pull request Oct 13, 2025
…qlc-dev#2805) * feat(analyzer): Analyze queries using a running PostgreSQL database 94 of the open issues on sqlc are related to the analyzer. There are many cases where the current analyzer produces false positives or false negatives. sqlx and some other projects have proven that it's possible to extract query metadata from a running database. This approach is a bit different, in that the database analysis is layered on top of the existing query analyzer. We use the new analysis to provide better type information and support a wider set of cases when the existing analyzer fails. * test(analyzer): Update endtoend tests for new analyzer Add a `contexts` key to exec.json to opt certain tests into or out of database-backed analysis. Fix many incorrect test cases that didn't run against an actual database.
Sign up for freeto 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.

3 participants

@kyleconroy@andrewmbenton