From 67dcc7d220e2826796e0890a55f7c89daa764a1a Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 14:38:09 +0200 Subject: [PATCH 01/33] ignore idea files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..38931f95bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +go.sum From fce2639b2b3aff5a7d44f9c5f14e48557daf4fa0 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 14:38:34 +0200 Subject: [PATCH 02/33] ignore go sum --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 38931f95bb..d25a2774c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea go.sum +go.sum +*.sum From baec2f4d52e101ed02bd0090303b6bec48bef8ed Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 14:39:07 +0200 Subject: [PATCH 03/33] Added config test that demonstrate the failed type --- internal/config/config_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index ef12a178b4..9554e87527 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -100,6 +100,16 @@ func TestTypeOverrides(t *testing.T) { "string", true, }, + { + // Attempt to debug the gopkg.in/guregu/null.v3/zero failed fetchin, upstream code do not throw any error and needs to be investigated + Override{ + DBType: "string", + GoType: "gopkg.in/guregu/null.v3/zero", + }, + "gopkg.in/guregu/null.v3/zero", + "zero.String", + false, + }, } { tt := test t.Run(tt.override.GoType, func(t *testing.T) { From d6ee92bc7f941605ac298bf619a301f9dd2f43cf Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 15:51:43 +0200 Subject: [PATCH 04/33] Forgot to include the type name. Added issues # --- internal/config/config_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 9554e87527..b348c649b6 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -101,10 +101,10 @@ func TestTypeOverrides(t *testing.T) { true, }, { - // Attempt to debug the gopkg.in/guregu/null.v3/zero failed fetchin, upstream code do not throw any error and needs to be investigated + // Attempt to debug the gopkg.in/guregu/null.v3/zero failed fetching, upstream code do not throw any error when issuing generate and needs to be investigated. See #462 and #255 Override{ DBType: "string", - GoType: "gopkg.in/guregu/null.v3/zero", + GoType: "gopkg.in/guregu/null.v3/zero.String", }, "gopkg.in/guregu/null.v3/zero", "zero.String", From 1bb9bcf5b20991cb7065beca5c3ba8cd4d41dfc3 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 15:53:10 +0200 Subject: [PATCH 05/33] Attempt to implement a regex matching Regex expressions to match the typ ename and package name. Credits for the regex exp goes to /u/Lee_Dailey on Reddit. --- internal/config/config.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 6e5c4db444..3e947f1031 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,6 +8,7 @@ import ( "go/types" "io" "os" + "regexp" "strings" "github.com/kyleconroy/sqlc/internal/pg" @@ -218,7 +219,20 @@ func (o *Override) Parse() error { if lastSlash == -1 { return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) } - typename = o.GoType[lastSlash+1:] + + // Upstream typename assignment + // typename = o.GoType[lastSlash+1:] + + // Regex to match the type name and the package name + typeNameRegex := regexp.MustCompile(`.+\/(?P.+?)$`) + + // Is there a regex match for the type name? + if ok := typeNameRegex.MatchString(o.GoType); ok { + typename = typeNameRegex.FindStringSubmatch(o.GoType)[1] + } else { + return fmt.Errorf("Type regex match not found") + } + if strings.HasPrefix(typename, "go-") { // a package name beginning with "go-" will give syntax errors in // generated code. We should do the right thing and get the actual @@ -229,7 +243,18 @@ func (o *Override) Parse() error { if strings.HasSuffix(typename, "-go") { typename = typename[:len(typename)-len("-go")] } - o.GoPackage = o.GoType[:lastDot] + // Upstream package name assignment + //o.GoPackage = o.GoType[:lastDot] + + pkgNameRegex := regexp.MustCompile(`(?P.+)\..+$`) + + // Is there a regex match for the package name? + if ok := pkgNameRegex.MatchString(o.GoType); ok { + o.GoPackage = pkgNameRegex.FindStringSubmatch(o.GoType)[1] + } else { + return fmt.Errorf("Package regex match not found") + } + } o.GoTypeName = typename isPointer := o.GoType[0] == '*' From 98c0c89f5acd4feb12f1a4cfc68db9ef4082d401 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 27 Apr 2020 16:42:24 +0200 Subject: [PATCH 06/33] Added a new test case which once again breaks everything --- internal/config/config_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index b348c649b6..8ddc599024 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -110,6 +110,16 @@ func TestTypeOverrides(t *testing.T) { "zero.String", false, }, + { + // See #462 and #255 + Override{ + DBType: "string", + GoType: "gopkg.in/guregu/null.v3.String", + }, + "gopkg.in/guregu/null.v3", + "null.String", + false, + }, } { tt := test t.Run(tt.override.GoType, func(t *testing.T) { From 16e6e6d5155316ca6cf2c04eaecf82032cc5a79b Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 11:24:32 +0200 Subject: [PATCH 07/33] Corrected comment to match what they refer to https://github.com/kyleconroy/sqlc/pull/463#pullrequestreview-401147535 --- .gitignore | 4 ---- internal/config/config.go | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d25a2774c3..0000000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea -go.sum -go.sum -*.sum diff --git a/internal/config/config.go b/internal/config/config.go index 3e947f1031..c6fa88cf4d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -128,10 +128,10 @@ type SQLKotlin struct { } type Override struct { - // name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID` + // Fully qualified name of the Go type to use, e.g. `github.com/segmentio/ksuid.KSUID` GoType string `json:"go_type" yaml:"go_type"` - // fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID` + // The database type to override DBType string `json:"db_type" yaml:"db_type"` Deprecated_PostgresType string `json:"postgres_type" yaml:"postgres_type"` From 5060694049d4174db30a2b09ddfcde2d3407e5e5 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 11:27:49 +0200 Subject: [PATCH 08/33] Changed Null tag as agreed in #463 Fixes #413 --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index c6fa88cf4d..e3aa394c21 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -139,7 +139,7 @@ type Override struct { Engine Engine `json:"engine,omitempty" yaml:"engine"` // True if the GoType should override if the maching postgres type is nullable - Null bool `json:"null" yaml:"null"` + Null bool `json:"is_null" yaml:"is_null"` // fully qualified name of the column, e.g. `accounts.id` Column string `json:"column" yaml:"column"` From a9df5d268f93a226041bff0073ff43e806a80767 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 13:54:22 +0200 Subject: [PATCH 09/33] typo in field tag --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index e3aa394c21..ff1693e5fb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -115,7 +115,7 @@ type SQLGen struct { type SQLGo struct { EmitInterface bool `json:"emit_interface" yaml:"emit_interface"` EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"` - EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries":` + EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"` Package string `json:"package" yaml:"package"` Out string `json:"out" yaml:"out"` Overrides []Override `json:"overrides,omitempty" yaml:"overrides"` From 1b043db6552855093836a88010eafe727471f207 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 15:23:05 +0200 Subject: [PATCH 10/33] Refactored type, import path an pkg name --- internal/config/config.go | 98 +++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index ff1693e5fb..004b10efbf 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,7 +8,6 @@ import ( "go/types" "io" "os" - "regexp" "strings" "github.com/kyleconroy/sqlc/internal/pg" @@ -128,8 +127,8 @@ type SQLKotlin struct { } type Override struct { - // Fully qualified name of the Go type to use, e.g. `github.com/segmentio/ksuid.KSUID` - GoType string `json:"go_type" yaml:"go_type"` + // Import path, package name and type name as you would type them in the IDE + GoTypeParam GoTypeParams `json:"go_type" yaml:"go_type"` // The database type to override DBType string `json:"db_type" yaml:"db_type"` @@ -144,13 +143,26 @@ type Override struct { // fully qualified name of the column, e.g. `accounts.id` Column string `json:"column" yaml:"column"` - ColumnName string - Table pg.FQN + ColumnName string + Table pg.FQN + + GoType string GoTypeName string GoPackage string GoBasicType bool } +type GoTypeParams struct { + // Eg. package "github.com/segmentio/ksuid" which usage is ksuid.KSUID would have: + // ImportPath "github.com/segmentio/ksuid" + // Package name ksuid + // Type name KSUID + + ImportPath string `json:"import" yaml:"import"` + PackageName string `json:"package" yaml:"package"` + TypeName string `json:"type" yaml:"type"` +} + func (o *Override) Parse() error { // validate deprecated postgres_type field @@ -189,9 +201,9 @@ func (o *Override) Parse() error { } // validate GoType - lastDot := strings.LastIndex(o.GoType, ".") - lastSlash := strings.LastIndex(o.GoType, "/") - typename := o.GoType + lastDot := strings.LastIndex(o.GoTypeParam.ImportPath, ".") + lastSlash := strings.LastIndex(o.GoTypeParam.ImportPath, "/") + typename := o.GoTypeParam.TypeName if lastDot == -1 && lastSlash == -1 { // if the type name has no slash and no dot, validate that the type is a basic Go type var found bool @@ -208,59 +220,47 @@ func (o *Override) Parse() error { } } if !found { - return fmt.Errorf("Package override `go_type` specifier %q is not a Go basic type e.g. 'string'", o.GoType) + return fmt.Errorf("Package override `go_type` specifier %q is not a Go basic type e.g. 'string'", o.GoTypeParam.TypeName) } o.GoBasicType = true } else { - // assume the type lives in a Go package - if lastDot == -1 { - return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) - } - if lastSlash == -1 { - return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) - } - - // Upstream typename assignment - // typename = o.GoType[lastSlash+1:] - - // Regex to match the type name and the package name - typeNameRegex := regexp.MustCompile(`.+\/(?P.+?)$`) - - // Is there a regex match for the type name? - if ok := typeNameRegex.MatchString(o.GoType); ok { - typename = typeNameRegex.FindStringSubmatch(o.GoType)[1] - } else { - return fmt.Errorf("Type regex match not found") - } - - if strings.HasPrefix(typename, "go-") { + // TODO need to implement checks for #177, is an import path is set, the package is external otherwise it doesn't need to be imported + /* This checks shouldn't be needed anymore, proper Go type definition responsibility is to the end user given the explicitly set fields. + // assume the type lives in a Go package + if lastDot == -1 { + return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) + } + if lastSlash == -1 { + return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) + } + */ + + if strings.HasPrefix(o.GoTypeParam.PackageName, "go-") { // a package name beginning with "go-" will give syntax errors in // generated code. We should do the right thing and get the actual // import name, but in lieu of that, stripping the leading "go-" may get // us what we want. - typename = typename[len("go-"):] + o.GoTypeParam.PackageName = o.GoTypeParam.PackageName[len("go-"):] } - if strings.HasSuffix(typename, "-go") { - typename = typename[:len(typename)-len("-go")] + if strings.HasSuffix(o.GoTypeParam.PackageName, "-go") { + o.GoTypeParam.PackageName = o.GoTypeParam.PackageName[:len(o.GoTypeParam.PackageName)-len("-go")] } - // Upstream package name assignment - //o.GoPackage = o.GoType[:lastDot] - pkgNameRegex := regexp.MustCompile(`(?P.+)\..+$`) - - // Is there a regex match for the package name? - if ok := pkgNameRegex.MatchString(o.GoType); ok { - o.GoPackage = pkgNameRegex.FindStringSubmatch(o.GoType)[1] - } else { - return fmt.Errorf("Package regex match not found") - } + o.GoPackage = o.GoTypeParam.PackageName } - o.GoTypeName = typename - isPointer := o.GoType[0] == '*' - if isPointer { - o.GoPackage = o.GoPackage[1:] - o.GoTypeName = "*" + o.GoTypeName + if len(o.GoTypeParam.ImportPath) > 0 { + o.GoTypeName = o.GoTypeParam.PackageName + "." + o.GoTypeParam.TypeName + } else { + o.GoTypeName = o.GoTypeParam.TypeName + } + + if len(o.GoTypeParam.ImportPath) > 0 { + isPointer := o.GoTypeParam.ImportPath[0] == '*' + if isPointer { + o.GoPackage = o.GoPackage[1:] + o.GoTypeName = "*" + o.GoTypeName + } } return nil From 23836e5380d8edc12fa24d2ac9270db5a7ee0941 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 15:23:24 +0200 Subject: [PATCH 11/33] Reconfigured the test suites to fit the new strucutre --- internal/config/config_test.go | 50 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 8ddc599024..0f9cd07bb7 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -74,9 +74,13 @@ func TestTypeOverrides(t *testing.T) { { Override{ DBType: "uuid", - GoType: "github.com/segmentio/ksuid.KSUID", + GoTypeParam: GoTypeParams{ + ImportPath: "github.com/segmentio/ksuid", + PackageName: "ksuid", + TypeName: "KSUID", + }, }, - "github.com/segmentio/ksuid", + "ksuid", "ksuid.KSUID", false, }, @@ -94,29 +98,39 @@ func TestTypeOverrides(t *testing.T) { { Override{ DBType: "citext", - GoType: "string", + GoTypeParam: GoTypeParams{ + ImportPath: "", + PackageName: "", + TypeName: "string", + }, }, "", "string", true, }, { - // Attempt to debug the gopkg.in/guregu/null.v3/zero failed fetching, upstream code do not throw any error when issuing generate and needs to be investigated. See #462 and #255 Override{ DBType: "string", - GoType: "gopkg.in/guregu/null.v3/zero.String", + GoTypeParam: GoTypeParams{ + ImportPath: "gopkg.in/guregu/null.v3/zero.String", + PackageName: "zero", + TypeName: "String", + }, }, - "gopkg.in/guregu/null.v3/zero", + "zero", "zero.String", false, }, { - // See #462 and #255 Override{ DBType: "string", - GoType: "gopkg.in/guregu/null.v3.String", + GoTypeParam: GoTypeParams{ + ImportPath: "gopkg.in/guregu/null.v3", + PackageName: "null", + TypeName: "String", + }, }, - "gopkg.in/guregu/null.v3", + "null", "null.String", false, }, @@ -137,6 +151,7 @@ func TestTypeOverrides(t *testing.T) { } }) } + for _, test := range []struct { override Override err string @@ -144,7 +159,22 @@ func TestTypeOverrides(t *testing.T) { { Override{ DBType: "uuid", - GoType: "Pointer", + GoTypeParam: GoTypeParams{ + ImportPath: "", + PackageName: "", + TypeName: "Pointer", + }, + }, + "Package override `go_type` specifier \"Pointer\" is not a Go basic type e.g. 'string'", + }, + { + Override{ + DBType: "uuid", + GoTypeParam: GoTypeParams{ + ImportPath: "", + PackageName: "", + TypeName: "untyped rune", + }, }, "Package override `go_type` specifier \"Pointer\" is not a Go basic type e.g. 'string'", }, From 0f50202c3fc26f2a507a84a538c3f2f88d90a6e1 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 15:39:24 +0200 Subject: [PATCH 12/33] Test case for go basic types updated --- internal/config/config_test.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 0f9cd07bb7..c8f2b557c8 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -176,18 +176,11 @@ func TestTypeOverrides(t *testing.T) { TypeName: "untyped rune", }, }, - "Package override `go_type` specifier \"Pointer\" is not a Go basic type e.g. 'string'", - }, - { - Override{ - DBType: "uuid", - GoType: "untyped rune", - }, "Package override `go_type` specifier \"untyped rune\" is not a Go basic type e.g. 'string'", }, } { tt := test - t.Run(tt.override.GoType, func(t *testing.T) { + t.Run(tt.override.GoTypeParam.TypeName, func(t *testing.T) { err := tt.override.Parse() if err == nil { t.Fatalf("expected pars to fail; got nil") From 2f0571e198dc45ccc72e8d50aaa3ae87c166e6c9 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 15:55:59 +0200 Subject: [PATCH 13/33] Explaining why I'm leaving duplicate fields around This surely needs to be addressed but I fear to make mess in the codebase --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 004b10efbf..28144f4071 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -146,7 +146,7 @@ type Override struct { ColumnName string Table pg.FQN - GoType string + // FIXME The whole sqlc package could be rewritten to fetch these values from the new type GoTypeParams, however, to not mess around too much I left them here. Otherwise it would be needed to refactor in too many places around the codebase. I know for certain that the rest of the code will search these values here hence, I'm leeaving them as such. -- maxiride GoTypeName string GoPackage string GoBasicType bool From bdbebc789eb04393bdfa4d5ff21ed12d91f64f61 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 15:56:12 +0200 Subject: [PATCH 14/33] Changed test names --- internal/config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index c8f2b557c8..3545fbd275 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -136,7 +136,7 @@ func TestTypeOverrides(t *testing.T) { }, } { tt := test - t.Run(tt.override.GoType, func(t *testing.T) { + t.Run(tt.override.GoTypeParam.ImportPath, func(t *testing.T) { if err := tt.override.Parse(); err != nil { t.Fatalf("override parsing failed; %s", err) } From dc04fc5ab7c846ec2f3a81a72ac9e93353afeb39 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 16:41:17 +0200 Subject: [PATCH 15/33] Updated endtoend yaml overrides template --- internal/endtoend/testdata/yaml_overrides/sqlc.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/endtoend/testdata/yaml_overrides/sqlc.yaml b/internal/endtoend/testdata/yaml_overrides/sqlc.yaml index d91ace1235..24dcf0be92 100644 --- a/internal/endtoend/testdata/yaml_overrides/sqlc.yaml +++ b/internal/endtoend/testdata/yaml_overrides/sqlc.yaml @@ -5,7 +5,13 @@ packages: schema: "sql/" queries: "sql/" overrides: - - go_type: "example.com/pkg.CustomType" + - go_type: + import: "example.com/pkg.CustomType" + package: "pkg" + type: "CustomType" column: "foo.retyped" - - go_type: "github.com/lib/pq.StringArray" + - go_type: + import: "github.com/lib/pq.StringArray" + package: "pq" + type: "StringArray" column: "foo.langs" From 72416ab1a8f221c50660f25fbe9da17176fe14d4 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 17:32:50 +0200 Subject: [PATCH 16/33] Change to passing pointer --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 28144f4071..b5913d798b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -128,7 +128,7 @@ type SQLKotlin struct { type Override struct { // Import path, package name and type name as you would type them in the IDE - GoTypeParam GoTypeParams `json:"go_type" yaml:"go_type"` + GoTypeParam *GoTypeParams `json:"go_type" yaml:"go_type"` // The database type to override DBType string `json:"db_type" yaml:"db_type"` From a81f062ef883fa9723eeec417d7305296428dee5 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 17:35:47 +0200 Subject: [PATCH 17/33] - --- internal/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index b5913d798b..28144f4071 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -128,7 +128,7 @@ type SQLKotlin struct { type Override struct { // Import path, package name and type name as you would type them in the IDE - GoTypeParam *GoTypeParams `json:"go_type" yaml:"go_type"` + GoTypeParam GoTypeParams `json:"go_type" yaml:"go_type"` // The database type to override DBType string `json:"db_type" yaml:"db_type"` From ec2e79c54ef4ba42b2635c93b387d84515edec5c Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 18:13:11 +0200 Subject: [PATCH 18/33] Found out there were more test cases scattered around --- internal/endtoend/testdata/mysql_overrides/sqlc.json | 12 ++++++++++-- internal/endtoend/testdata/overrides/sqlc.json | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/endtoend/testdata/mysql_overrides/sqlc.json b/internal/endtoend/testdata/mysql_overrides/sqlc.json index b7cfad6101..c86dfb15b6 100644 --- a/internal/endtoend/testdata/mysql_overrides/sqlc.json +++ b/internal/endtoend/testdata/mysql_overrides/sqlc.json @@ -8,10 +8,18 @@ "queries": "query.sql", "engine": "mysql", "overrides": [{ - "go_type": "example.com/mysql.ID", + "go_type": { + "import": "example.com/mysql.ID", + "package": "mysql", + "type": "ID" + }, "column": "users.id" }, { - "go_type": "example.com/mysql.ID", + "go_type":{ + "import": "example.com/mysql.ID", + "package": "mysql", + "type": "ID" + }, "column": "orders.id" }] } diff --git a/internal/endtoend/testdata/overrides/sqlc.json b/internal/endtoend/testdata/overrides/sqlc.json index f98bb706b7..dc8af11a18 100644 --- a/internal/endtoend/testdata/overrides/sqlc.json +++ b/internal/endtoend/testdata/overrides/sqlc.json @@ -8,11 +8,19 @@ "queries": "sql/", "overrides": [ { - "go_type": "example.com/pkg.CustomType", + "go_type": { + "import": "example.com/pkg.CustomType", + "package": "pkg", + "type": "CustomType" + }, "column": "foo.retyped" }, { - "go_type": "github.com/lib/pq.StringArray", + "go_type": { + "import": "github.com/lib/pq.StringArray", + "package": "pq", + "type": "StringArray" + }, "column": "foo.langs" } ] From 07d899858a316232c04c29d34c2ffa0878c3b4e2 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 18:22:12 +0200 Subject: [PATCH 19/33] More tests I didn't noticed an adapted to the new structs Slippery little devils --- .../testdata/mysql_overrides/sqlc.json | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/endtoend/testdata/mysql_overrides/sqlc.json b/internal/endtoend/testdata/mysql_overrides/sqlc.json index c86dfb15b6..a054cfa818 100644 --- a/internal/endtoend/testdata/mysql_overrides/sqlc.json +++ b/internal/endtoend/testdata/mysql_overrides/sqlc.json @@ -7,25 +7,34 @@ "schema": "schema.sql", "queries": "query.sql", "engine": "mysql", - "overrides": [{ - "go_type": { - "import": "example.com/mysql.ID", - "package": "mysql", - "type": "ID" + "overrides": [ + { + "go_type": { + "import": "example.com/mysql.ID", + "package": "mysql", + "type": "ID" + }, + "column": "users.id" }, - "column": "users.id" - }, { - "go_type":{ - "import": "example.com/mysql.ID", - "package": "mysql", - "type": "ID" - }, - "column": "orders.id" - }] + { + "go_type": { + "import": "example.com/mysql.ID", + "package": "mysql", + "type": "ID" + }, + "column": "orders.id" + } + ] } ], - "overrides": [{ - "go_type": "example.com/mysql.Timestamp", - "db_type": "timestamp" - }] + "overrides": [ + { + "go_type": { + "import": "example.com/mysql.Timestamp", + "package": "mysql", + "type": "Timestamp" + }, + "db_type": "timestamp" + } + ] } From 51bf531443243f8e23a1b756056f80c558421fd5 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 18:49:28 +0200 Subject: [PATCH 20/33] Notes to self --- internal/config/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 28144f4071..4246500f12 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -249,6 +249,7 @@ func (o *Override) Parse() error { o.GoPackage = o.GoTypeParam.PackageName } + if len(o.GoTypeParam.ImportPath) > 0 { o.GoTypeName = o.GoTypeParam.PackageName + "." + o.GoTypeParam.TypeName } else { @@ -258,6 +259,7 @@ func (o *Override) Parse() error { if len(o.GoTypeParam.ImportPath) > 0 { isPointer := o.GoTypeParam.ImportPath[0] == '*' if isPointer { + // FIXME unsure how to handle this, didn't fully understood it yet o.GoPackage = o.GoPackage[1:] o.GoTypeName = "*" + o.GoTypeName } From 38f6dde3a312785ffb370e5bb9cd7915989e32fb Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 18:50:55 +0200 Subject: [PATCH 21/33] Should address endtoend test failure messages See override erros, I'm getting the package name instead of the import path: https://github.com/kyleconroy/sqlc/pull/463/checks?check_run_id=640767819 --- internal/dinosql/gen.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/dinosql/gen.go b/internal/dinosql/gen.go index 3761db64e7..8589ce6fdd 100644 --- a/internal/dinosql/gen.go +++ b/internal/dinosql/gen.go @@ -288,7 +288,7 @@ func interfaceImports(r Generateable, settings config.CombinedSettings) fileImpo if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoPackage + overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath } _, overrideNullTime := overrideTypes["pq.NullTime"] @@ -350,7 +350,7 @@ func modelImports(r Generateable, settings config.CombinedSettings) fileImports if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoPackage + overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath } _, overrideNullTime := overrideTypes["pq.NullTime"] @@ -485,7 +485,7 @@ func queryImports(r Generateable, settings config.CombinedSettings, filename str if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoPackage + overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath } if sliceScan() { From fccd87d6b246b9604f73faec02f9de53ff219450 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 19:22:16 +0200 Subject: [PATCH 22/33] Renaming to avoid confusion on what's what --- internal/config/config.go | 16 ++++++++-------- internal/config/config_test.go | 4 ++-- internal/dinosql/gen.go | 10 +++++----- internal/mysql/gen.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 4246500f12..57faeb6c42 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -147,9 +147,9 @@ type Override struct { Table pg.FQN // FIXME The whole sqlc package could be rewritten to fetch these values from the new type GoTypeParams, however, to not mess around too much I left them here. Otherwise it would be needed to refactor in too many places around the codebase. I know for certain that the rest of the code will search these values here hence, I'm leeaving them as such. -- maxiride - GoTypeName string - GoPackage string - GoBasicType bool + GoImportPath string + GoPackageName string + GoBasicType bool } type GoTypeParams struct { @@ -246,22 +246,22 @@ func (o *Override) Parse() error { o.GoTypeParam.PackageName = o.GoTypeParam.PackageName[:len(o.GoTypeParam.PackageName)-len("-go")] } - o.GoPackage = o.GoTypeParam.PackageName + o.GoPackageName = o.GoTypeParam.PackageName } if len(o.GoTypeParam.ImportPath) > 0 { - o.GoTypeName = o.GoTypeParam.PackageName + "." + o.GoTypeParam.TypeName + o.GoImportPath = o.GoTypeParam.PackageName + "." + o.GoTypeParam.TypeName } else { - o.GoTypeName = o.GoTypeParam.TypeName + o.GoImportPath = o.GoTypeParam.TypeName } if len(o.GoTypeParam.ImportPath) > 0 { isPointer := o.GoTypeParam.ImportPath[0] == '*' if isPointer { // FIXME unsure how to handle this, didn't fully understood it yet - o.GoPackage = o.GoPackage[1:] - o.GoTypeName = "*" + o.GoTypeName + o.GoPackageName = o.GoPackageName[1:] + o.GoImportPath = "*" + o.GoImportPath } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 3545fbd275..118f577397 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -140,10 +140,10 @@ func TestTypeOverrides(t *testing.T) { if err := tt.override.Parse(); err != nil { t.Fatalf("override parsing failed; %s", err) } - if diff := cmp.Diff(tt.typeName, tt.override.GoTypeName); diff != "" { + if diff := cmp.Diff(tt.typeName, tt.override.GoImportPath); diff != "" { t.Errorf("type name mismatch;\n%s", diff) } - if diff := cmp.Diff(tt.pkg, tt.override.GoPackage); diff != "" { + if diff := cmp.Diff(tt.pkg, tt.override.GoPackageName); diff != "" { t.Errorf("package mismatch;\n%s", diff) } if diff := cmp.Diff(tt.basic, tt.override.GoBasicType); diff != "" { diff --git a/internal/dinosql/gen.go b/internal/dinosql/gen.go index 8589ce6fdd..c8755c2db1 100644 --- a/internal/dinosql/gen.go +++ b/internal/dinosql/gen.go @@ -288,7 +288,7 @@ func interfaceImports(r Generateable, settings config.CombinedSettings) fileImpo if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath + overrideTypes[o.GoImportPath] = o.GoTypeParam.ImportPath } _, overrideNullTime := overrideTypes["pq.NullTime"] @@ -350,7 +350,7 @@ func modelImports(r Generateable, settings config.CombinedSettings) fileImports if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath + overrideTypes[o.GoImportPath] = o.GoTypeParam.ImportPath } _, overrideNullTime := overrideTypes["pq.NullTime"] @@ -485,7 +485,7 @@ func queryImports(r Generateable, settings config.CombinedSettings, filename str if o.GoBasicType { continue } - overrideTypes[o.GoTypeName] = o.GoTypeParam.ImportPath + overrideTypes[o.GoImportPath] = o.GoTypeParam.ImportPath } if sliceScan() { @@ -621,7 +621,7 @@ func (r Result) goType(col core.Column, settings config.CombinedSettings) string // package overrides have a higher precedence for _, oride := range settings.Overrides { if oride.Column != "" && oride.ColumnName == col.Name && oride.Table == col.Table { - return oride.GoTypeName + return oride.GoImportPath } } typ := r.goInnerType(col, settings) @@ -638,7 +638,7 @@ func (r Result) goInnerType(col core.Column, settings config.CombinedSettings) s // package overrides have a higher precedence for _, oride := range settings.Overrides { if oride.DBType != "" && oride.DBType == columnType && oride.Null != notNull { - return oride.GoTypeName + return oride.GoImportPath } } diff --git a/internal/mysql/gen.go b/internal/mysql/gen.go index 17ebf51d54..2854364332 100644 --- a/internal/mysql/gen.go +++ b/internal/mysql/gen.go @@ -230,7 +230,7 @@ func (pGen PackageGenerator) goTypeCol(col Column) string { shouldOverride := (oride.DBType != "" && oride.DBType == mySQLType && oride.Null != notNull) || (oride.ColumnName != "" && oride.ColumnName == colName && oride.Table.Rel == col.Table) if shouldOverride { - return oride.GoTypeName + return oride.GoImportPath } } switch t := mySQLType; { From 64274693189d0bacd524d137e092fee85ff06d71 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 19:28:34 +0200 Subject: [PATCH 23/33] Fix import paths I forgot to change them after refactoring --- internal/endtoend/testdata/mysql_overrides/sqlc.json | 6 +++--- internal/endtoend/testdata/overrides/sqlc.json | 4 ++-- internal/endtoend/testdata/yaml_overrides/sqlc.yaml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/endtoend/testdata/mysql_overrides/sqlc.json b/internal/endtoend/testdata/mysql_overrides/sqlc.json index a054cfa818..ba1afacccb 100644 --- a/internal/endtoend/testdata/mysql_overrides/sqlc.json +++ b/internal/endtoend/testdata/mysql_overrides/sqlc.json @@ -10,7 +10,7 @@ "overrides": [ { "go_type": { - "import": "example.com/mysql.ID", + "import": "example.com/mysql", "package": "mysql", "type": "ID" }, @@ -18,7 +18,7 @@ }, { "go_type": { - "import": "example.com/mysql.ID", + "import": "example.com/mysql", "package": "mysql", "type": "ID" }, @@ -30,7 +30,7 @@ "overrides": [ { "go_type": { - "import": "example.com/mysql.Timestamp", + "import": "example.com/mysql", "package": "mysql", "type": "Timestamp" }, diff --git a/internal/endtoend/testdata/overrides/sqlc.json b/internal/endtoend/testdata/overrides/sqlc.json index dc8af11a18..0371be3f23 100644 --- a/internal/endtoend/testdata/overrides/sqlc.json +++ b/internal/endtoend/testdata/overrides/sqlc.json @@ -9,7 +9,7 @@ "overrides": [ { "go_type": { - "import": "example.com/pkg.CustomType", + "import": "example.com/pkg", "package": "pkg", "type": "CustomType" }, @@ -17,7 +17,7 @@ }, { "go_type": { - "import": "github.com/lib/pq.StringArray", + "import": "github.com/lib/pq", "package": "pq", "type": "StringArray" }, diff --git a/internal/endtoend/testdata/yaml_overrides/sqlc.yaml b/internal/endtoend/testdata/yaml_overrides/sqlc.yaml index 24dcf0be92..2d82456887 100644 --- a/internal/endtoend/testdata/yaml_overrides/sqlc.yaml +++ b/internal/endtoend/testdata/yaml_overrides/sqlc.yaml @@ -6,12 +6,12 @@ packages: queries: "sql/" overrides: - go_type: - import: "example.com/pkg.CustomType" + import: "example.com/pkg" package: "pkg" type: "CustomType" column: "foo.retyped" - go_type: - import: "github.com/lib/pq.StringArray" + import: "github.com/lib/pq" package: "pq" type: "StringArray" column: "foo.langs" From 7a545ff4d489f061c3b33e9efb835f4a9630e32d Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 21:12:30 +0200 Subject: [PATCH 24/33] Forgot to change an import path --- internal/config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 118f577397..abf59e95ae 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -112,7 +112,7 @@ func TestTypeOverrides(t *testing.T) { Override{ DBType: "string", GoTypeParam: GoTypeParams{ - ImportPath: "gopkg.in/guregu/null.v3/zero.String", + ImportPath: "gopkg.in/guregu/null.v3/zero", PackageName: "zero", TypeName: "String", }, From 8993da4cac7f65a21df0710dc0f02da35f8970ea Mon Sep 17 00:00:00 2001 From: Maxiride Date: Sun, 3 May 2020 21:22:24 +0000 Subject: [PATCH 25/33] Added new examples with the new generation implemented with the #463 --- examples-complex-import/authors/db.go | 29 +++++++ examples-complex-import/authors/models.go | 13 ++++ examples-complex-import/authors/query.sql | 19 +++++ examples-complex-import/authors/query.sql.go | 81 ++++++++++++++++++++ examples-complex-import/authors/schema.sql | 5 ++ examples-complex-import/authors/sqlc.yaml | 17 ++++ 6 files changed, 164 insertions(+) create mode 100644 examples-complex-import/authors/db.go create mode 100644 examples-complex-import/authors/models.go create mode 100644 examples-complex-import/authors/query.sql create mode 100644 examples-complex-import/authors/query.sql.go create mode 100644 examples-complex-import/authors/schema.sql create mode 100644 examples-complex-import/authors/sqlc.yaml diff --git a/examples-complex-import/authors/db.go b/examples-complex-import/authors/db.go new file mode 100644 index 0000000000..c3c034ae37 --- /dev/null +++ b/examples-complex-import/authors/db.go @@ -0,0 +1,29 @@ +// Code generated by sqlc. DO NOT EDIT. + +package db + +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/examples-complex-import/authors/models.go b/examples-complex-import/authors/models.go new file mode 100644 index 0000000000..d4e2d2bffb --- /dev/null +++ b/examples-complex-import/authors/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. + +package db + +import ( + "gopkg.in/guregu/null.v3/zero" +) + +type Author struct { + ID int64 `json:"id"` + Name string `json:"name"` + Bio zero.String `json:"bio"` +} diff --git a/examples-complex-import/authors/query.sql b/examples-complex-import/authors/query.sql new file mode 100644 index 0000000000..75e38b2caf --- /dev/null +++ b/examples-complex-import/authors/query.sql @@ -0,0 +1,19 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE id = $1 LIMIT 1; + +-- name: ListAuthors :many +SELECT * FROM authors +ORDER BY name; + +-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio +) VALUES ( + $1, $2 +) +RETURNING *; + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $1; diff --git a/examples-complex-import/authors/query.sql.go b/examples-complex-import/authors/query.sql.go new file mode 100644 index 0000000000..38d680d11e --- /dev/null +++ b/examples-complex-import/authors/query.sql.go @@ -0,0 +1,81 @@ +// Code generated by sqlc. DO NOT EDIT. +// source: query.sql + +package db + +import ( + "context" + + "gopkg.in/guregu/null.v3/zero" +) + +const createAuthor = `-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio +) VALUES ( + $1, $2 +) +RETURNING id, name, bio +` + +type CreateAuthorParams struct { + Name string `json:"name"` + Bio zero.String `json:"bio"` +} + +func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { + row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $1 +` + +func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, id) + return err +} + +const getAuthor = `-- name: GetAuthor :one +SELECT id, name, bio FROM authors +WHERE id = $1 LIMIT 1 +` + +func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthor, id) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio FROM authors +ORDER BY name +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/examples-complex-import/authors/schema.sql b/examples-complex-import/authors/schema.sql new file mode 100644 index 0000000000..b4fad78497 --- /dev/null +++ b/examples-complex-import/authors/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE authors ( + id BIGSERIAL PRIMARY KEY, + name text NOT NULL, + bio text +); diff --git a/examples-complex-import/authors/sqlc.yaml b/examples-complex-import/authors/sqlc.yaml new file mode 100644 index 0000000000..fe9192ad04 --- /dev/null +++ b/examples-complex-import/authors/sqlc.yaml @@ -0,0 +1,17 @@ +version: "1" +packages: + - name: "db" + emit_json_tags: true + emit_prepared_queries: false + emit_interface: false + path: "." + queries: "./query.sql" + schema: "./schema.sql" +overrides: + - go_type: + import: "gopkg.in/guregu/null.v3/zero" + package: "zero" + type: "String" + is_null: true + db_type: "text" + From 95567dd856bb290d7461f0dcac42735aadf41e80 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 10:58:58 +0200 Subject: [PATCH 26/33] Added test template for #177 and possible fix idea Not implemented because on L213 we first need to find how to differentiate from a builtin type and custom type. I've left a comment on an idea on how to approach it. --- internal/config/config.go | 10 ++++++++-- internal/config/config_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 57faeb6c42..aca0ff084b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -203,7 +203,13 @@ func (o *Override) Parse() error { // validate GoType lastDot := strings.LastIndex(o.GoTypeParam.ImportPath, ".") lastSlash := strings.LastIndex(o.GoTypeParam.ImportPath, "/") - typename := o.GoTypeParam.TypeName + + + // If the overriding type is "local" (see #177) the config will have the 'import' tag null\zeroed, + // lastDot ==-1 && lasSlash == -1 would return TRUE and we would attempt to find a builtin type, which will not be found. + // FIXME Need to think on how to differentiate from a "local" type and builtin type when the import path is not set. + // As of now the test passes because there is no test for such scenario. + // Possibile fix: check that first letter is uppercase with unicode.IsUpper(o.GoTypeParam.ImportPath[0]) && unicode.IsLetter(o.GoTypeParam.ImportPath[0]) if lastDot == -1 && lastSlash == -1 { // if the type name has no slash and no dot, validate that the type is a basic Go type var found bool @@ -215,7 +221,7 @@ func (o *Override) Parse() error { if info&types.IsUntyped != 0 { continue } - if typename == typ.Name() { + if o.GoTypeParam.TypeName == typ.Name() { found = true } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index abf59e95ae..4f4a7cb50d 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -95,6 +95,21 @@ func TestTypeOverrides(t *testing.T) { // "*ksuid.KSUID", // false, // }, + // + // TODO Add test for config where the import path is not set but the type declared isn't a builtin one but a custom one + //{ + // Override{ + // DBType: "string", + // GoTypeParam: GoTypeParams{ + // ImportPath: "", + // PackageName: "", + // TypeName: "CustomType", + // }, + // }, + // "", + // "CustomType", + // false, + //}, { Override{ DBType: "citext", From 8290e9478869813f0a5cf67e6cc6b2095fd53ec6 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 10:59:18 +0200 Subject: [PATCH 27/33] Moved and renamed the new examples as requested --- examples-complex-import/authors/db.go | 29 ------- examples-complex-import/authors/models.go | 13 ---- examples-complex-import/authors/query.sql | 19 ----- examples-complex-import/authors/query.sql.go | 81 -------------------- examples-complex-import/authors/schema.sql | 5 -- examples-complex-import/authors/sqlc.yaml | 17 ---- 6 files changed, 164 deletions(-) delete mode 100644 examples-complex-import/authors/db.go delete mode 100644 examples-complex-import/authors/models.go delete mode 100644 examples-complex-import/authors/query.sql delete mode 100644 examples-complex-import/authors/query.sql.go delete mode 100644 examples-complex-import/authors/schema.sql delete mode 100644 examples-complex-import/authors/sqlc.yaml diff --git a/examples-complex-import/authors/db.go b/examples-complex-import/authors/db.go deleted file mode 100644 index c3c034ae37..0000000000 --- a/examples-complex-import/authors/db.go +++ /dev/null @@ -1,29 +0,0 @@ -// Code generated by sqlc. DO NOT EDIT. - -package db - -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/examples-complex-import/authors/models.go b/examples-complex-import/authors/models.go deleted file mode 100644 index d4e2d2bffb..0000000000 --- a/examples-complex-import/authors/models.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated by sqlc. DO NOT EDIT. - -package db - -import ( - "gopkg.in/guregu/null.v3/zero" -) - -type Author struct { - ID int64 `json:"id"` - Name string `json:"name"` - Bio zero.String `json:"bio"` -} diff --git a/examples-complex-import/authors/query.sql b/examples-complex-import/authors/query.sql deleted file mode 100644 index 75e38b2caf..0000000000 --- a/examples-complex-import/authors/query.sql +++ /dev/null @@ -1,19 +0,0 @@ --- name: GetAuthor :one -SELECT * FROM authors -WHERE id = $1 LIMIT 1; - --- name: ListAuthors :many -SELECT * FROM authors -ORDER BY name; - --- name: CreateAuthor :one -INSERT INTO authors ( - name, bio -) VALUES ( - $1, $2 -) -RETURNING *; - --- name: DeleteAuthor :exec -DELETE FROM authors -WHERE id = $1; diff --git a/examples-complex-import/authors/query.sql.go b/examples-complex-import/authors/query.sql.go deleted file mode 100644 index 38d680d11e..0000000000 --- a/examples-complex-import/authors/query.sql.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by sqlc. DO NOT EDIT. -// source: query.sql - -package db - -import ( - "context" - - "gopkg.in/guregu/null.v3/zero" -) - -const createAuthor = `-- name: CreateAuthor :one -INSERT INTO authors ( - name, bio -) VALUES ( - $1, $2 -) -RETURNING id, name, bio -` - -type CreateAuthorParams struct { - Name string `json:"name"` - Bio zero.String `json:"bio"` -} - -func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { - row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) - var i Author - err := row.Scan(&i.ID, &i.Name, &i.Bio) - return i, err -} - -const deleteAuthor = `-- name: DeleteAuthor :exec -DELETE FROM authors -WHERE id = $1 -` - -func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error { - _, err := q.db.ExecContext(ctx, deleteAuthor, id) - return err -} - -const getAuthor = `-- name: GetAuthor :one -SELECT id, name, bio FROM authors -WHERE id = $1 LIMIT 1 -` - -func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { - row := q.db.QueryRowContext(ctx, getAuthor, id) - var i Author - err := row.Scan(&i.ID, &i.Name, &i.Bio) - return i, err -} - -const listAuthors = `-- name: ListAuthors :many -SELECT id, name, bio FROM authors -ORDER BY name -` - -func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { - rows, err := q.db.QueryContext(ctx, listAuthors) - if err != nil { - return nil, err - } - defer rows.Close() - var items []Author - for rows.Next() { - var i Author - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} diff --git a/examples-complex-import/authors/schema.sql b/examples-complex-import/authors/schema.sql deleted file mode 100644 index b4fad78497..0000000000 --- a/examples-complex-import/authors/schema.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE authors ( - id BIGSERIAL PRIMARY KEY, - name text NOT NULL, - bio text -); diff --git a/examples-complex-import/authors/sqlc.yaml b/examples-complex-import/authors/sqlc.yaml deleted file mode 100644 index fe9192ad04..0000000000 --- a/examples-complex-import/authors/sqlc.yaml +++ /dev/null @@ -1,17 +0,0 @@ -version: "1" -packages: - - name: "db" - emit_json_tags: true - emit_prepared_queries: false - emit_interface: false - path: "." - queries: "./query.sql" - schema: "./schema.sql" -overrides: - - go_type: - import: "gopkg.in/guregu/null.v3/zero" - package: "zero" - type: "String" - is_null: true - db_type: "text" - From fdaa3a073d4c77e8c2abe986ff11f102315affbf Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 10:59:37 +0200 Subject: [PATCH 28/33] Typo and notes --- internal/config/config.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index aca0ff084b..9047cd0a1b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -137,7 +137,7 @@ type Override struct { // for global overrides only when two different engines are in use Engine Engine `json:"engine,omitempty" yaml:"engine"` - // True if the GoType should override if the maching postgres type is nullable + // True if the GoType should override if the matching postgres type is nullable Null bool `json:"is_null" yaml:"is_null"` // fully qualified name of the column, e.g. `accounts.id` @@ -230,8 +230,12 @@ func (o *Override) Parse() error { } o.GoBasicType = true } else { - // TODO need to implement checks for #177, is an import path is set, the package is external otherwise it doesn't need to be imported - /* This checks shouldn't be needed anymore, proper Go type definition responsibility is to the end user given the explicitly set fields. + // As pointed out, for backwards compatibility this check needs to be performed, however in the current status of the + // PR these checks will always fail with the new config because, if used, the 'import' tag won't have any dot + // except for the niche of complex_go_types + // FIXME, need to implement a check to ensure whether the "legacy" or "new" config structure is used + // Possible quick and dirty fix: check if o.GoTypeParam.TypeName && o.GoTypeParam.PackageName are set + /* // assume the type lives in a Go package if lastDot == -1 { return fmt.Errorf("Package override `go_type` specifier %q is not the proper format, expected 'package.type', e.g. 'github.com/segmentio/ksuid.KSUID'", o.GoType) From a9dbd5da9f21b757eef81e6d1a57d304d4c9ca31 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 11:12:46 +0200 Subject: [PATCH 29/33] Resolving conflicts --- internal/config/config.go | 1 + .../testdata/complex_go_type/authors/db.go | 29 +++++++ .../complex_go_type/authors/models.go | 13 +++ .../complex_go_type/authors/query.sql | 19 +++++ .../complex_go_type/authors/query.sql.go | 81 +++++++++++++++++++ .../complex_go_type/authors/schema.sql | 5 ++ .../complex_go_type/authors/sqlc.yaml | 17 ++++ 7 files changed, 165 insertions(+) create mode 100644 internal/endtoend/testdata/complex_go_type/authors/db.go create mode 100644 internal/endtoend/testdata/complex_go_type/authors/models.go create mode 100644 internal/endtoend/testdata/complex_go_type/authors/query.sql create mode 100644 internal/endtoend/testdata/complex_go_type/authors/query.sql.go create mode 100644 internal/endtoend/testdata/complex_go_type/authors/schema.sql create mode 100644 internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml diff --git a/internal/config/config.go b/internal/config/config.go index 9047cd0a1b..370be3639b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -115,6 +115,7 @@ type SQLGo struct { EmitInterface bool `json:"emit_interface" yaml:"emit_interface"` EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"` EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"` + EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"` Package string `json:"package" yaml:"package"` Out string `json:"out" yaml:"out"` Overrides []Override `json:"overrides,omitempty" yaml:"overrides"` diff --git a/internal/endtoend/testdata/complex_go_type/authors/db.go b/internal/endtoend/testdata/complex_go_type/authors/db.go new file mode 100644 index 0000000000..c3c034ae37 --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/db.go @@ -0,0 +1,29 @@ +// Code generated by sqlc. DO NOT EDIT. + +package db + +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/complex_go_type/authors/models.go b/internal/endtoend/testdata/complex_go_type/authors/models.go new file mode 100644 index 0000000000..d4e2d2bffb --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. + +package db + +import ( + "gopkg.in/guregu/null.v3/zero" +) + +type Author struct { + ID int64 `json:"id"` + Name string `json:"name"` + Bio zero.String `json:"bio"` +} diff --git a/internal/endtoend/testdata/complex_go_type/authors/query.sql b/internal/endtoend/testdata/complex_go_type/authors/query.sql new file mode 100644 index 0000000000..75e38b2caf --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/query.sql @@ -0,0 +1,19 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE id = $1 LIMIT 1; + +-- name: ListAuthors :many +SELECT * FROM authors +ORDER BY name; + +-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio +) VALUES ( + $1, $2 +) +RETURNING *; + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $1; diff --git a/internal/endtoend/testdata/complex_go_type/authors/query.sql.go b/internal/endtoend/testdata/complex_go_type/authors/query.sql.go new file mode 100644 index 0000000000..38d680d11e --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/query.sql.go @@ -0,0 +1,81 @@ +// Code generated by sqlc. DO NOT EDIT. +// source: query.sql + +package db + +import ( + "context" + + "gopkg.in/guregu/null.v3/zero" +) + +const createAuthor = `-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio +) VALUES ( + $1, $2 +) +RETURNING id, name, bio +` + +type CreateAuthorParams struct { + Name string `json:"name"` + Bio zero.String `json:"bio"` +} + +func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { + row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $1 +` + +func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, id) + return err +} + +const getAuthor = `-- name: GetAuthor :one +SELECT id, name, bio FROM authors +WHERE id = $1 LIMIT 1 +` + +func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthor, id) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio FROM authors +ORDER BY name +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/complex_go_type/authors/schema.sql b/internal/endtoend/testdata/complex_go_type/authors/schema.sql new file mode 100644 index 0000000000..b4fad78497 --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE authors ( + id BIGSERIAL PRIMARY KEY, + name text NOT NULL, + bio text +); diff --git a/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml b/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml new file mode 100644 index 0000000000..fe9192ad04 --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml @@ -0,0 +1,17 @@ +version: "1" +packages: + - name: "db" + emit_json_tags: true + emit_prepared_queries: false + emit_interface: false + path: "." + queries: "./query.sql" + schema: "./schema.sql" +overrides: + - go_type: + import: "gopkg.in/guregu/null.v3/zero" + package: "zero" + type: "String" + is_null: true + db_type: "text" + From cffba642307b42a4b8821cbbb0e0237b88b5529e Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 11:20:32 +0200 Subject: [PATCH 30/33] Changed config from YAML to JSON Apparently the endttoend test suite only searches for, and support, JSON configs --- .../complex_go_type/authors/sqlc.json | 25 +++++++++++++++++++ .../complex_go_type/authors/sqlc.yaml | 17 ------------- 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 internal/endtoend/testdata/complex_go_type/authors/sqlc.json delete mode 100644 internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml diff --git a/internal/endtoend/testdata/complex_go_type/authors/sqlc.json b/internal/endtoend/testdata/complex_go_type/authors/sqlc.json new file mode 100644 index 0000000000..029d408373 --- /dev/null +++ b/internal/endtoend/testdata/complex_go_type/authors/sqlc.json @@ -0,0 +1,25 @@ +{ + "version": "1", + "packages": [ + { + "name": "db", + "emit_json_tags": true, + "emit_prepared_queries": false, + "emit_interface": false, + "path": ".", + "queries": "./query.sql", + "schema": "./schema.sql" + } + ], + "overrides": [ + { + "go_type": { + "import": "gopkg.in/guregu/null.v3/zero", + "package": "zero", + "type": "String" + }, + "is_null": true, + "db_type": "text" + } + ] +} \ No newline at end of file diff --git a/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml b/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml deleted file mode 100644 index fe9192ad04..0000000000 --- a/internal/endtoend/testdata/complex_go_type/authors/sqlc.yaml +++ /dev/null @@ -1,17 +0,0 @@ -version: "1" -packages: - - name: "db" - emit_json_tags: true - emit_prepared_queries: false - emit_interface: false - path: "." - queries: "./query.sql" - schema: "./schema.sql" -overrides: - - go_type: - import: "gopkg.in/guregu/null.v3/zero" - package: "zero" - type: "String" - is_null: true - db_type: "text" - From 70e69279c7233754b4e4618164fb38b490cd599c Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 11:31:23 +0200 Subject: [PATCH 31/33] fixed folder structure and config parameters changed the folder structure to be compliant like the all the others and changed the path and name tag as in the other endtoend folders --- .../testdata/complex_go_type/{authors => go}/db.go | 0 .../complex_go_type/{authors => go}/models.go | 0 .../complex_go_type/{authors => go}/query.sql.go | 0 .../testdata/complex_go_type/{authors => }/query.sql | 0 .../testdata/complex_go_type/{authors => }/schema.sql | 0 .../testdata/complex_go_type/{authors => }/sqlc.json | 11 ++++------- 6 files changed, 4 insertions(+), 7 deletions(-) rename internal/endtoend/testdata/complex_go_type/{authors => go}/db.go (100%) rename internal/endtoend/testdata/complex_go_type/{authors => go}/models.go (100%) rename internal/endtoend/testdata/complex_go_type/{authors => go}/query.sql.go (100%) rename internal/endtoend/testdata/complex_go_type/{authors => }/query.sql (100%) rename internal/endtoend/testdata/complex_go_type/{authors => }/schema.sql (100%) rename internal/endtoend/testdata/complex_go_type/{authors => }/sqlc.json (56%) diff --git a/internal/endtoend/testdata/complex_go_type/authors/db.go b/internal/endtoend/testdata/complex_go_type/go/db.go similarity index 100% rename from internal/endtoend/testdata/complex_go_type/authors/db.go rename to internal/endtoend/testdata/complex_go_type/go/db.go diff --git a/internal/endtoend/testdata/complex_go_type/authors/models.go b/internal/endtoend/testdata/complex_go_type/go/models.go similarity index 100% rename from internal/endtoend/testdata/complex_go_type/authors/models.go rename to internal/endtoend/testdata/complex_go_type/go/models.go diff --git a/internal/endtoend/testdata/complex_go_type/authors/query.sql.go b/internal/endtoend/testdata/complex_go_type/go/query.sql.go similarity index 100% rename from internal/endtoend/testdata/complex_go_type/authors/query.sql.go rename to internal/endtoend/testdata/complex_go_type/go/query.sql.go diff --git a/internal/endtoend/testdata/complex_go_type/authors/query.sql b/internal/endtoend/testdata/complex_go_type/query.sql similarity index 100% rename from internal/endtoend/testdata/complex_go_type/authors/query.sql rename to internal/endtoend/testdata/complex_go_type/query.sql diff --git a/internal/endtoend/testdata/complex_go_type/authors/schema.sql b/internal/endtoend/testdata/complex_go_type/schema.sql similarity index 100% rename from internal/endtoend/testdata/complex_go_type/authors/schema.sql rename to internal/endtoend/testdata/complex_go_type/schema.sql diff --git a/internal/endtoend/testdata/complex_go_type/authors/sqlc.json b/internal/endtoend/testdata/complex_go_type/sqlc.json similarity index 56% rename from internal/endtoend/testdata/complex_go_type/authors/sqlc.json rename to internal/endtoend/testdata/complex_go_type/sqlc.json index 029d408373..be0a739423 100644 --- a/internal/endtoend/testdata/complex_go_type/authors/sqlc.json +++ b/internal/endtoend/testdata/complex_go_type/sqlc.json @@ -2,13 +2,10 @@ "version": "1", "packages": [ { - "name": "db", - "emit_json_tags": true, - "emit_prepared_queries": false, - "emit_interface": false, - "path": ".", - "queries": "./query.sql", - "schema": "./schema.sql" + "name": "querytest", + "path": "go", + "queries": "query.sql", + "schema": "schema.sql" } ], "overrides": [ From 71f0c761e435e90ded12cce37572cbc7f18573ea Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 15:35:07 +0200 Subject: [PATCH 32/33] Wrong package name assignment I clearly misunderstood how the endtoend test is performed --- internal/endtoend/testdata/complex_go_type/sqlc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/endtoend/testdata/complex_go_type/sqlc.json b/internal/endtoend/testdata/complex_go_type/sqlc.json index be0a739423..cdd2772217 100644 --- a/internal/endtoend/testdata/complex_go_type/sqlc.json +++ b/internal/endtoend/testdata/complex_go_type/sqlc.json @@ -2,7 +2,7 @@ "version": "1", "packages": [ { - "name": "querytest", + "name": "db", "path": "go", "queries": "query.sql", "schema": "schema.sql" From 1867166690f1fe1de5850b0ccb49a4c01a491b09 Mon Sep 17 00:00:00 2001 From: Maxiride Date: Mon, 4 May 2020 15:43:29 +0200 Subject: [PATCH 33/33] Removed json tags I modified the sqlc.json to not emit them but I forgot to regenerate the code for a proper comparison test --- internal/endtoend/testdata/complex_go_type/go/models.go | 6 +++--- internal/endtoend/testdata/complex_go_type/go/query.sql.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/endtoend/testdata/complex_go_type/go/models.go b/internal/endtoend/testdata/complex_go_type/go/models.go index d4e2d2bffb..b2556d5a5f 100644 --- a/internal/endtoend/testdata/complex_go_type/go/models.go +++ b/internal/endtoend/testdata/complex_go_type/go/models.go @@ -7,7 +7,7 @@ import ( ) type Author struct { - ID int64 `json:"id"` - Name string `json:"name"` - Bio zero.String `json:"bio"` + ID int64 + Name string + Bio zero.String } diff --git a/internal/endtoend/testdata/complex_go_type/go/query.sql.go b/internal/endtoend/testdata/complex_go_type/go/query.sql.go index 38d680d11e..7da7f9458a 100644 --- a/internal/endtoend/testdata/complex_go_type/go/query.sql.go +++ b/internal/endtoend/testdata/complex_go_type/go/query.sql.go @@ -19,8 +19,8 @@ RETURNING id, name, bio ` type CreateAuthorParams struct { - Name string `json:"name"` - Bio zero.String `json:"bio"` + Name string + Bio zero.String } func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) {