diff --git a/internal/cmd/shim.go b/internal/cmd/shim.go index 16534707b8..b33e98782c 100644 --- a/internal/cmd/shim.go +++ b/internal/cmd/shim.go @@ -19,7 +19,7 @@ func pluginOverride(o config.Override) *plugin.Override { colParts := strings.Split(o.Column, ".") switch len(colParts) { case 2: - table.Schema = "public" + //table.Schema = "public" table.Name = colParts[0] column = colParts[1] case 3: diff --git a/internal/codegen/sdk/sdk.go b/internal/codegen/sdk/sdk.go index 2f97da1bb8..98bcaefa17 100644 --- a/internal/codegen/sdk/sdk.go +++ b/internal/codegen/sdk/sdk.go @@ -32,7 +32,7 @@ func Matches(o *plugin.Override, n *plugin.Identifier, defaultSchema string) boo if o.Table.Catalog != "" && !MatchString(o.Table.Catalog, n.Catalog) { return false } - if o.Table.Schema == "" && schema != "" { + if o.Table.Schema == "" && n.Schema != "" { return false } if o.Table.Schema != "" && !MatchString(o.Table.Schema, schema) { diff --git a/internal/endtoend/testdata/overrides/sqlite/go/db.go b/internal/endtoend/testdata/overrides/sqlite/go/db.go new file mode 100644 index 0000000000..e41f9c22e0 --- /dev/null +++ b/internal/endtoend/testdata/overrides/sqlite/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/overrides/sqlite/go/models.go b/internal/endtoend/testdata/overrides/sqlite/go/models.go new file mode 100644 index 0000000000..263c88806f --- /dev/null +++ b/internal/endtoend/testdata/overrides/sqlite/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import ( + "github.com/kyleconroy/sqlc-testdata/pkg" +) + +type Foo struct { + Other string + Total int64 + Retyped pkg.CustomType +} diff --git a/internal/endtoend/testdata/overrides/sqlite/query.sql b/internal/endtoend/testdata/overrides/sqlite/query.sql new file mode 100644 index 0000000000..e0ac49d1ec --- /dev/null +++ b/internal/endtoend/testdata/overrides/sqlite/query.sql @@ -0,0 +1 @@ +SELECT 1; diff --git a/internal/endtoend/testdata/overrides/sqlite/schema.sql b/internal/endtoend/testdata/overrides/sqlite/schema.sql new file mode 100644 index 0000000000..c0c5fc47dc --- /dev/null +++ b/internal/endtoend/testdata/overrides/sqlite/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + other text NOT NULL, + total bigint NOT NULL, + retyped text NOT NULL +); diff --git a/internal/endtoend/testdata/overrides/sqlite/sqlc.json b/internal/endtoend/testdata/overrides/sqlite/sqlc.json new file mode 100644 index 0000000000..ce7ab410c5 --- /dev/null +++ b/internal/endtoend/testdata/overrides/sqlite/sqlc.json @@ -0,0 +1,18 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "sqlite", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "go_type": "github.com/kyleconroy/sqlc-testdata/pkg.CustomType", + "column": "foo.retyped" + } + ] + } + ] +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/db.go b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/db.go new file mode 100644 index 0000000000..e41f9c22e0 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/models.go b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/models.go new file mode 100644 index 0000000000..b5299bb37b --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/go/models.go @@ -0,0 +1,22 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import () + +type Bar struct { + Other string + AlsoTagged string `also:"tagged"` +} + +type Baz struct { + Other string + AlsoTagged string `also:"tagged"` +} + +type Foo struct { + Other string + Tagged string `a:"b" x:"y,z"` +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/query.sql b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/query.sql new file mode 100644 index 0000000000..e0ac49d1ec --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/query.sql @@ -0,0 +1 @@ +SELECT 1; diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/schema.sql b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/schema.sql new file mode 100644 index 0000000000..4d5233cc37 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/schema.sql @@ -0,0 +1,14 @@ +CREATE TABLE foo ( + other text NOT NULL, + tagged text NOT NULL +); + +CREATE TABLE bar ( + other text NOT NULL, + also_tagged text NOT NULL +); + +CREATE TABLE baz ( + other text NOT NULL, + also_tagged text NOT NULL +); diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/sqlc.json b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/sqlc.json new file mode 100644 index 0000000000..0be626d449 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/sqlite/sqlc.json @@ -0,0 +1,22 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "sqlite", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "go_struct_tag": "a:\"b\" x:\"y,z\"", + "column": "foo.tagged" + }, + { + "go_struct_tag": "also:\"tagged\"", + "column": "*.also_tagged" + } + ] + } + ] +} diff --git a/internal/endtoend/testdata/overrides_go_types/sqlite/go/db.go b/internal/endtoend/testdata/overrides_go_types/sqlite/go/db.go new file mode 100644 index 0000000000..e41f9c22e0 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/sqlite/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/overrides_go_types/sqlite/go/models.go b/internal/endtoend/testdata/overrides_go_types/sqlite/go/models.go new file mode 100644 index 0000000000..cb2b45bf58 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/sqlite/go/models.go @@ -0,0 +1,27 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.18.0 + +package override + +import ( + "github.com/kyleconroy/sqlc-testdata/pkg" +) + +type Bar struct { + Other string + Total int64 + AlsoRetyped pkg.CustomType +} + +type Baz struct { + Other string + Total int64 + AlsoRetyped pkg.CustomType +} + +type Foo struct { + Other string + Total int64 + Retyped pkg.CustomType +} diff --git a/internal/endtoend/testdata/overrides_go_types/sqlite/query.sql b/internal/endtoend/testdata/overrides_go_types/sqlite/query.sql new file mode 100644 index 0000000000..e0ac49d1ec --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/sqlite/query.sql @@ -0,0 +1 @@ +SELECT 1; diff --git a/internal/endtoend/testdata/overrides_go_types/sqlite/schema.sql b/internal/endtoend/testdata/overrides_go_types/sqlite/schema.sql new file mode 100644 index 0000000000..31b183ad86 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/sqlite/schema.sql @@ -0,0 +1,17 @@ +CREATE TABLE foo ( + other text NOT NULL, + total bigint NOT NULL, + retyped text NOT NULL +); + +CREATE TABLE bar ( + other text NOT NULL, + total bigint NOT NULL, + also_retyped text NOT NULL +); + +CREATE TABLE baz ( + other text NOT NULL, + total bigint NOT NULL, + also_retyped text NOT NULL +); diff --git a/internal/endtoend/testdata/overrides_go_types/sqlite/sqlc.json b/internal/endtoend/testdata/overrides_go_types/sqlite/sqlc.json new file mode 100644 index 0000000000..9d4799f4fe --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/sqlite/sqlc.json @@ -0,0 +1,22 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "sqlite", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "go_type": "github.com/kyleconroy/sqlc-testdata/pkg.CustomType", + "column": "foo.retyped" + }, + { + "go_type": "github.com/kyleconroy/sqlc-testdata/pkg.CustomType", + "column": "*.also_retyped" + } + ] + } + ] +}