Skip to content

codegen: Use catalog's default schema #2310

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

Merged
merged 1 commit into from
Jun 7, 2023
Merged
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
9 changes: 5 additions & 4 deletions internal/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"github.com/kyleconroy/sqlc/internal/sql/catalog"
)

func pluginOverride(o config.Override) *plugin.Override {
func pluginOverride(r *compiler.Result, o config.Override) *plugin.Override {
var column string
var table plugin.Identifier

if o.Column != "" {
colParts := strings.Split(o.Column, ".")
switch len(colParts) {
case 2:
table.Schema = r.Catalog.DefaultSchema
table.Name = colParts[0]
column = colParts[1]
case 3:
Expand All @@ -43,10 +44,10 @@ func pluginOverride(o config.Override) *plugin.Override {
}
}

func pluginSettings(cs config.CombinedSettings) *plugin.Settings {
func pluginSettings(r *compiler.Result, cs config.CombinedSettings) *plugin.Settings {
var over []*plugin.Override
for _, o := range cs.Overrides {
over = append(over, pluginOverride(o))
over = append(over, pluginOverride(r, o))
}
return &plugin.Settings{
Version: cs.Global.Version,
Expand Down Expand Up @@ -291,7 +292,7 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {

func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.CodeGenRequest {
return &plugin.CodeGenRequest{
Settings: pluginSettings(settings),
Settings: pluginSettings(r, settings),
Catalog: pluginCatalog(r.Catalog),
Queries: pluginQueries(r),
SqlcVersion: info.Version,
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" && n.Schema != "" {
if o.Table.Schema == "" && schema != "" {
return false
}
if o.Table.Schema != "" && !MatchString(o.Table.Schema, schema) {
Expand Down
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/overrides/sqlite/go/db.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/overrides/sqlite/go/models.go

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

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

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

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

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