Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/authors/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ sql:
engine: mysql
database:
uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}"
analyzer:
database: false
rules:
- sqlc/db-prepare
# - mysql-query-too-costly
Expand Down
3 changes: 3 additions & 0 deletions examples/booktest/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"database": {
"uri": "${VET_TEST_EXAMPLES_MYSQL_BOOKTEST}"
},
"analyzer": {
"database": false
},
"rules": [
"sqlc/db-prepare"
]
Expand Down
3 changes: 3 additions & 0 deletions examples/ondeck/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"database": {
"uri": "${VET_TEST_EXAMPLES_MYSQL_ONDECK}"
},
"analyzer": {
"database": false
},
"rules": [
"sqlc/db-prepare"
],
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20251022142026-3a174f9686a8 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)

replace github.com/go-sql-driver/mysql => github.com/sqlc-dev/mysql v0.0.0-20251129233104-d81e1cac6db2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
Expand Down Expand Up @@ -159,6 +157,8 @@ github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/sqlc-dev/mysql v0.0.0-20251129233104-d81e1cac6db2 h1:kmCAKKtOgK6EXXQX9oPdEASIhgor7TCpWxD8NtcqVcU=
github.com/sqlc-dev/mysql v0.0.0-20251129233104-d81e1cac6db2/go.mod h1:TrDMWzjNTKvJeK2GC8uspG+PWyPLiY9QKvwdWpAdlZE=
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
39 changes: 22 additions & 17 deletions internal/compiler/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,30 @@ func combineAnalysis(prev *analysis, a *analyzer.Analysis) *analysis {
Column: convertColumn(p.Column),
})
}
if len(prev.Columns) == len(cols) {
for i := range prev.Columns {
// Only override column types if the analyzer provides a specific type
// (not "any"), since the catalog-based inference may have better info
if cols[i].DataType != "any" {
prev.Columns[i].DataType = cols[i].DataType
prev.Columns[i].IsArray = cols[i].IsArray
prev.Columns[i].ArrayDims = cols[i].ArrayDims
// Only update columns if the analyzer returned column info
// An empty slice from the analyzer means it couldn't determine columns,
// so we should keep the catalog-inferred columns
if len(cols) > 0 {
if len(prev.Columns) == len(cols) {
for i := range prev.Columns {
// Only override column types if the analyzer provides a specific type
// (not "any"), since the catalog-based inference may have better info
if cols[i].DataType != "any" {
prev.Columns[i].DataType = cols[i].DataType
prev.Columns[i].IsArray = cols[i].IsArray
prev.Columns[i].ArrayDims = cols[i].ArrayDims
}
}
}
} else {
embedding := false
for i := range prev.Columns {
if prev.Columns[i].EmbedTable != nil {
embedding = true
} else {
embedding := false
for i := range prev.Columns {
if prev.Columns[i].EmbedTable != nil {
embedding = true
}
}
if !embedding {
prev.Columns = cols
}
}
if !embedding {
prev.Columns = cols
}
}
if len(prev.Parameters) == len(params) {
Expand Down
10 changes: 10 additions & 0 deletions internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/dbmanager"
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
mysqlanalyze "github.com/sqlc-dev/sqlc/internal/engine/dolphin/analyzer"
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
"github.com/sqlc-dev/sqlc/internal/engine/sqlite"
Expand Down Expand Up @@ -55,6 +56,15 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
c.parser = dolphin.NewParser()
c.catalog = dolphin.NewCatalog()
c.selector = newDefaultSelector()
if conf.Database != nil {
if conf.Analyzer.Database == nil || *conf.Analyzer.Database {
c.analyzer = analyzer.Cached(
mysqlanalyze.New(combo.Global.Servers, *conf.Database),
combo.Global,
*conf.Database,
)
}
}
case config.EnginePostgreSQL:
c.parser = postgresql.NewParser()
c.catalog = postgresql.NewCatalog()
Expand Down
7 changes: 4 additions & 3 deletions internal/endtoend/testdata/create_view/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/create_view/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SELECT * FROM first_view;

-- name: GetSecond :many
SELECT * FROM second_view WHERE val2 = $1;
SELECT * FROM second_view WHERE val2 = ?;
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/cte_count/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/endtoend/testdata/cte_count/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- name: CTECount :many
WITH all_count AS (
SELECT count(*) FROM bar
SELECT count(*) AS count FROM bar
), ready_count AS (
SELECT count(*) FROM bar WHERE ready = true
SELECT count(*) AS count FROM bar WHERE ready = true
)
SELECT all_count.count, ready_count.count
FROM all_count, ready_count;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/cte_filter/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- name: CTEFilter :many
WITH filter_count AS (
SELECT count(*) FROM bar WHERE ready = ?
SELECT count(*) AS count FROM bar WHERE ready = ?
)
SELECT filter_count.count
FROM filter_count;
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/in_union/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/in_union/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- name: GetAuthors :many
SELECT * FROM authors
WHERE author_id IN (SELECT author_id FROM book1 UNION SELECT author_id FROM book2);
WHERE id IN (SELECT author_id FROM book1 UNION SELECT author_id FROM book2);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* name: InsertValues :exec */
INSERT INTO public.foo (a, b) VALUES (?, ?);
INSERT INTO foo (a, b) VALUES (?, ?);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"contexts": ["base"],
"meta": {
"invalid_schema": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SELECT a.id,
p.name as alias_name
FROM authors a
LEFT JOIN authors p
ON (authors.parent_id = p.id);
ON (a.parent_id = p.id);
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/exec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/show_warnings/mysql/exec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["base"]
}
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/vet_explain/mysql/exec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}
41 changes: 23 additions & 18 deletions internal/endtoend/testdata/wrap_errors/mysql/db/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading