diff --git a/internal/codegen/golang/gen.go b/internal/codegen/golang/gen.go index e5762374ba..c5f1956e0d 100644 --- a/internal/codegen/golang/gen.go +++ b/internal/codegen/golang/gen.go @@ -108,6 +108,10 @@ func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenR return nil, err } + if err := validateOpts(options); err != nil { + return nil, err + } + enums := buildEnums(req, options) structs := buildStructs(req, options) queries, err := buildQueries(req, options, structs) diff --git a/internal/codegen/golang/opts.go b/internal/codegen/golang/opts.go index af90dcc6bd..53be536881 100644 --- a/internal/codegen/golang/opts.go +++ b/internal/codegen/golang/opts.go @@ -39,7 +39,7 @@ type opts struct { OmitUnusedStructs bool `json:"omit_unused_structs,omitempty"` BuildTags string `json:"build_tags,omitempty"` - // Unused but left in for parsing convenience + // Unused but included in marshaled json we receive Overrides json.RawMessage `json:"overrides,omitempty"` Rename json.RawMessage `json:"rename,omitempty"` } @@ -59,3 +59,11 @@ func parseOpts(req *plugin.CodeGenRequest) (*opts, error) { return options, nil } + +func validateOpts(opts *opts) error { + if opts.EmitMethodsWithDbArgument && opts.EmitPreparedQueries { + return fmt.Errorf("invalid options: emit_methods_with_db_argument and emit_prepared_queries options are mutually exclusive") + } + + return nil +} diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d643eeb9f0..240a4b4e1c 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -79,13 +79,12 @@ func FuzzConfig(f *testing.F) { func TestInvalidConfig(t *testing.T) { err := Validate(&Config{ SQL: []SQL{{ - Gen: SQLGen{ - Go: &SQLGo{ - EmitMethodsWithDBArgument: true, - EmitPreparedQueries: true, - }, + Database: &Database{ + URI: "", + Managed: false, }, - }}}) + }}, + }) if err == nil { t.Errorf("expected err; got nil") } diff --git a/internal/config/override.go b/internal/config/override.go index f2337a79de..0bb050443b 100644 --- a/internal/config/override.go +++ b/internal/config/override.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/sqlc-dev/sqlc/internal/pattern" - "github.com/sqlc-dev/sqlc/internal/sql/ast" ) type Override struct { @@ -49,39 +48,6 @@ type Override struct { GoStructTags map[string]string } -func (o *Override) Matches(n *ast.TableName, defaultSchema string) bool { - if n == nil { - return false - } - - schema := n.Schema - if n.Schema == "" { - schema = defaultSchema - } - - if o.TableCatalog != nil && !o.TableCatalog.MatchString(n.Catalog) { - return false - } - - if o.TableSchema == nil && schema != "" { - return false - } - - if o.TableSchema != nil && !o.TableSchema.MatchString(schema) { - return false - } - - if o.TableRel == nil && n.Name != "" { - return false - } - - if o.TableRel != nil && !o.TableRel.MatchString(n.Name) { - return false - } - - return true -} - func (o *Override) Parse() (err error) { // validate deprecated postgres_type field diff --git a/internal/config/python_type.go b/internal/config/python_type.go deleted file mode 100644 index e908448057..0000000000 --- a/internal/config/python_type.go +++ /dev/null @@ -1,17 +0,0 @@ -package config - -type PythonType struct { - Module string `json:"module" yaml:"module"` - Name string `json:"name" yaml:"name"` -} - -func (t PythonType) IsSet() bool { - return t.Module != "" || t.Name != "" -} - -func (t PythonType) TypeString() string { - if t.Name != "" && t.Module == "" { - return t.Name - } - return t.Module + "." + t.Name -} diff --git a/internal/config/validate.go b/internal/config/validate.go index 207a888ecf..b374a40c66 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -4,13 +4,6 @@ import "fmt" func Validate(c *Config) error { for _, sql := range c.SQL { - sqlGo := sql.Gen.Go - if sqlGo == nil { - continue - } - if sqlGo.EmitMethodsWithDBArgument && sqlGo.EmitPreparedQueries { - return fmt.Errorf("invalid config: emit_methods_with_db_argument and emit_prepared_queries settings are mutually exclusive") - } if sql.Database != nil { if sql.Database.URI == "" && !sql.Database.Managed { return fmt.Errorf("invalid config: database must be managed or have a non-empty URI")