diff --git a/examples/authors/db_test.go b/examples/authors/db_test.go index 3efcbd7185..697e3652b2 100644 --- a/examples/authors/db_test.go +++ b/examples/authors/db_test.go @@ -10,6 +10,26 @@ import ( "github.com/kyleconroy/sqlc/internal/sqltest" ) +// An example of an application-level structure +type AppAuthor struct { + ID int64 + Name string + Bio string +} + +// A mapper that uses a face interface +func MapToAuthor(a interface { + GetID() int64 + GetName() string + GetBio() sql.NullString +}) AppAuthor { + return AppAuthor{ + ID: a.GetID(), + Name: a.GetName(), + Bio: a.GetBio().String, + } +} + func TestAuthors(t *testing.T) { sdb, cleanup := sqltest.PostgreSQL(t, "schema.sql") defer cleanup() @@ -40,4 +60,5 @@ func TestAuthors(t *testing.T) { t.Fatal(err) } t.Log(fetchedAuthor) + t.Log(MapToAuthor(&fetchedAuthor)) } diff --git a/examples/authors/models.go b/examples/authors/models.go index b6915849c4..41ef90d2dc 100644 --- a/examples/authors/models.go +++ b/examples/authors/models.go @@ -11,3 +11,13 @@ type Author struct { Name string Bio sql.NullString } + +func (t *Author) GetID() int64 { + return t.ID +} +func (t *Author) GetName() string { + return t.Name +} +func (t *Author) GetBio() sql.NullString { + return t.Bio +} diff --git a/examples/booktest/mysql/models.go b/examples/booktest/mysql/models.go index 8008d62916..a2124d5d66 100644 --- a/examples/booktest/mysql/models.go +++ b/examples/booktest/mysql/models.go @@ -31,6 +31,13 @@ type Author struct { Name string } +func (t *Author) GetAuthorID() int { + return t.AuthorID +} +func (t *Author) GetName() string { + return t.Name +} + type Book struct { BookID int AuthorID int @@ -41,3 +48,28 @@ type Book struct { Available time.Time Tags string } + +func (t *Book) GetBookID() int { + return t.BookID +} +func (t *Book) GetAuthorID() int { + return t.AuthorID +} +func (t *Book) GetIsbn() string { + return t.Isbn +} +func (t *Book) GetBookType() BookTypeType { + return t.BookType +} +func (t *Book) GetTitle() string { + return t.Title +} +func (t *Book) GetYr() int { + return t.Yr +} +func (t *Book) GetAvailable() time.Time { + return t.Available +} +func (t *Book) GetTags() string { + return t.Tags +} diff --git a/examples/booktest/postgresql/models.go b/examples/booktest/postgresql/models.go index a760705fe3..b059691d58 100644 --- a/examples/booktest/postgresql/models.go +++ b/examples/booktest/postgresql/models.go @@ -31,6 +31,13 @@ type Author struct { Name string } +func (t *Author) GetAuthorID() int32 { + return t.AuthorID +} +func (t *Author) GetName() string { + return t.Name +} + type Book struct { BookID int32 AuthorID int32 @@ -41,3 +48,28 @@ type Book struct { Available time.Time Tags []string } + +func (t *Book) GetBookID() int32 { + return t.BookID +} +func (t *Book) GetAuthorID() int32 { + return t.AuthorID +} +func (t *Book) GetIsbn() string { + return t.Isbn +} +func (t *Book) GetBooktype() BookType { + return t.Booktype +} +func (t *Book) GetTitle() string { + return t.Title +} +func (t *Book) GetYear() int32 { + return t.Year +} +func (t *Book) GetAvailable() time.Time { + return t.Available +} +func (t *Book) GetTags() []string { + return t.Tags +} diff --git a/examples/jets/models.go b/examples/jets/models.go index 7bc33b6bda..3619e18c68 100644 --- a/examples/jets/models.go +++ b/examples/jets/models.go @@ -12,17 +12,54 @@ type Jet struct { Color string } +func (t *Jet) GetID() int32 { + return t.ID +} +func (t *Jet) GetPilotID() int32 { + return t.PilotID +} +func (t *Jet) GetAge() int32 { + return t.Age +} +func (t *Jet) GetName() string { + return t.Name +} +func (t *Jet) GetColor() string { + return t.Color +} + type Language struct { ID int32 Language string } +func (t *Language) GetID() int32 { + return t.ID +} +func (t *Language) GetLanguage() string { + return t.Language +} + type Pilot struct { ID int32 Name string } +func (t *Pilot) GetID() int32 { + return t.ID +} +func (t *Pilot) GetName() string { + return t.Name +} + type PilotLanguage struct { PilotID int32 LanguageID int32 } + +func (t *PilotLanguage) GetPilotID() int32 { + return t.PilotID +} +func (t *PilotLanguage) GetLanguageID() int32 { + return t.LanguageID +} diff --git a/examples/ondeck/models.go b/examples/ondeck/models.go index 5bc596c551..52d1dd6de6 100644 --- a/examples/ondeck/models.go +++ b/examples/ondeck/models.go @@ -33,6 +33,13 @@ type City struct { Name string `json:"name"` } +func (t *City) GetSlug() string { + return t.Slug +} +func (t *City) GetName() string { + return t.Name +} + // Venues are places where muisc happens type Venue struct { ID int32 `json:"id"` @@ -47,3 +54,36 @@ type Venue struct { Tags []string `json:"tags"` CreatedAt time.Time `json:"created_at"` } + +func (t *Venue) GetID() int32 { + return t.ID +} +func (t *Venue) GetStatus() Status { + return t.Status +} +func (t *Venue) GetStatuses() []Status { + return t.Statuses +} + +// This value appears in public URLs +func (t *Venue) GetSlug() string { + return t.Slug +} +func (t *Venue) GetName() string { + return t.Name +} +func (t *Venue) GetCity() string { + return t.City +} +func (t *Venue) GetSpotifyPlaylist() string { + return t.SpotifyPlaylist +} +func (t *Venue) GetSongkickID() sql.NullString { + return t.SongkickID +} +func (t *Venue) GetTags() []string { + return t.Tags +} +func (t *Venue) GetCreatedAt() time.Time { + return t.CreatedAt +} diff --git a/internal/dinosql/gen.go b/internal/dinosql/gen.go index 168338ebe7..ea51810d2a 100644 --- a/internal/dinosql/gen.go +++ b/internal/dinosql/gen.go @@ -1159,7 +1159,7 @@ func (e *{{.Name}}) Scan(src interface{}) error { } {{end}} -{{range .Structs}} +{{range $s := .Structs}} {{if .Comment}}{{comment .Comment}}{{end}} type {{.Name}} struct { {{- range .Fields}} {{- if .Comment}} @@ -1168,6 +1168,17 @@ type {{.Name}} struct { {{- range .Fields}} {{.Name}} {{.Type}} {{if $.EmitJSONTags}}{{$.Q}}{{.Tag}}{{$.Q}}{{end}} {{- end}} } + +{{- range $f := .Fields}} +{{- if $f.Comment}} +// {{$f.Comment}} +{{- end}} +func (t *{{$s.Name}}) Get{{$f.Name}}() {{$f.Type}} { + return t.{{$f.Name}} +} + +{{- end}} + {{end}} {{end}} diff --git a/internal/endtoend/testdata/alias/go/models.go b/internal/endtoend/testdata/alias/go/models.go index 99f581177b..d1415c5495 100644 --- a/internal/endtoend/testdata/alias/go/models.go +++ b/internal/endtoend/testdata/alias/go/models.go @@ -10,7 +10,18 @@ type Bar struct { ID int32 } +func (t *Bar) GetID() int32 { + return t.ID +} + type Foo struct { ID int32 Bar sql.NullInt32 } + +func (t *Foo) GetID() int32 { + return t.ID +} +func (t *Foo) GetBar() sql.NullInt32 { + return t.Bar +} diff --git a/internal/endtoend/testdata/any/go/models.go b/internal/endtoend/testdata/any/go/models.go index 18039acde9..6794c941d7 100644 --- a/internal/endtoend/testdata/any/go/models.go +++ b/internal/endtoend/testdata/any/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { ID int64 } + +func (t *Bar) GetID() int64 { + return t.ID +} diff --git a/internal/endtoend/testdata/as/go/models.go b/internal/endtoend/testdata/as/go/models.go index d21739e2dd..12eef34e4e 100644 --- a/internal/endtoend/testdata/as/go/models.go +++ b/internal/endtoend/testdata/as/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { Name string } + +func (t *Foo) GetName() string { + return t.Name +} diff --git a/internal/endtoend/testdata/case_stmt_bool/go/models.go b/internal/endtoend/testdata/case_stmt_bool/go/models.go index b443f16b28..fdfcfd8c7e 100644 --- a/internal/endtoend/testdata/case_stmt_bool/go/models.go +++ b/internal/endtoend/testdata/case_stmt_bool/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { ID string } + +func (t *Foo) GetID() string { + return t.ID +} diff --git a/internal/endtoend/testdata/cast_coalesce/go/models.go b/internal/endtoend/testdata/cast_coalesce/go/models.go index 8170fc4b5c..fb9f4861ab 100644 --- a/internal/endtoend/testdata/cast_coalesce/go/models.go +++ b/internal/endtoend/testdata/cast_coalesce/go/models.go @@ -9,3 +9,7 @@ import ( type Foo struct { Bar sql.NullString } + +func (t *Foo) GetBar() sql.NullString { + return t.Bar +} diff --git a/internal/endtoend/testdata/coalesce/go/models.go b/internal/endtoend/testdata/coalesce/go/models.go index 8170fc4b5c..fb9f4861ab 100644 --- a/internal/endtoend/testdata/coalesce/go/models.go +++ b/internal/endtoend/testdata/coalesce/go/models.go @@ -9,3 +9,7 @@ import ( type Foo struct { Bar sql.NullString } + +func (t *Foo) GetBar() sql.NullString { + return t.Bar +} diff --git a/internal/endtoend/testdata/column_as/go/models.go b/internal/endtoend/testdata/column_as/go/models.go index c2291cf4ec..54a2537a24 100644 --- a/internal/endtoend/testdata/column_as/go/models.go +++ b/internal/endtoend/testdata/column_as/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { Email string } + +func (t *Foo) GetEmail() string { + return t.Email +} diff --git a/internal/endtoend/testdata/comparisons/go/models.go b/internal/endtoend/testdata/comparisons/go/models.go index 7c3b98644d..1ebd04c005 100644 --- a/internal/endtoend/testdata/comparisons/go/models.go +++ b/internal/endtoend/testdata/comparisons/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { ID int32 } + +func (t *Bar) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/composite_type/go/models.go b/internal/endtoend/testdata/composite_type/go/models.go index f2ebcd2576..bf296e3c56 100644 --- a/internal/endtoend/testdata/composite_type/go/models.go +++ b/internal/endtoend/testdata/composite_type/go/models.go @@ -10,3 +10,10 @@ type FooPath struct { PointOne sql.NullString PointTwo sql.NullString } + +func (t *FooPath) GetPointOne() sql.NullString { + return t.PointOne +} +func (t *FooPath) GetPointTwo() sql.NullString { + return t.PointTwo +} diff --git a/internal/endtoend/testdata/cte_count/go/models.go b/internal/endtoend/testdata/cte_count/go/models.go index be78cdc955..8248c462a7 100644 --- a/internal/endtoend/testdata/cte_count/go/models.go +++ b/internal/endtoend/testdata/cte_count/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { Ready bool } + +func (t *Bar) GetReady() bool { + return t.Ready +} diff --git a/internal/endtoend/testdata/cte_filter/go/models.go b/internal/endtoend/testdata/cte_filter/go/models.go index be78cdc955..8248c462a7 100644 --- a/internal/endtoend/testdata/cte_filter/go/models.go +++ b/internal/endtoend/testdata/cte_filter/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { Ready bool } + +func (t *Bar) GetReady() bool { + return t.Ready +} diff --git a/internal/endtoend/testdata/datatype/go/models.go b/internal/endtoend/testdata/datatype/go/models.go index ef28d2b855..d2baa87b3f 100644 --- a/internal/endtoend/testdata/datatype/go/models.go +++ b/internal/endtoend/testdata/datatype/go/models.go @@ -15,6 +15,22 @@ type DtCharacter struct { E sql.NullString } +func (t *DtCharacter) GetA() sql.NullString { + return t.A +} +func (t *DtCharacter) GetB() sql.NullString { + return t.B +} +func (t *DtCharacter) GetC() sql.NullString { + return t.C +} +func (t *DtCharacter) GetD() sql.NullString { + return t.D +} +func (t *DtCharacter) GetE() sql.NullString { + return t.E +} + type DtCharacterNotNull struct { A string B string @@ -23,6 +39,22 @@ type DtCharacterNotNull struct { E string } +func (t *DtCharacterNotNull) GetA() string { + return t.A +} +func (t *DtCharacterNotNull) GetB() string { + return t.B +} +func (t *DtCharacterNotNull) GetC() string { + return t.C +} +func (t *DtCharacterNotNull) GetD() string { + return t.D +} +func (t *DtCharacterNotNull) GetE() string { + return t.E +} + type DtDatetime struct { A sql.NullTime B sql.NullTime @@ -34,6 +66,31 @@ type DtDatetime struct { H sql.NullTime } +func (t *DtDatetime) GetA() sql.NullTime { + return t.A +} +func (t *DtDatetime) GetB() sql.NullTime { + return t.B +} +func (t *DtDatetime) GetC() sql.NullTime { + return t.C +} +func (t *DtDatetime) GetD() sql.NullTime { + return t.D +} +func (t *DtDatetime) GetE() sql.NullTime { + return t.E +} +func (t *DtDatetime) GetF() sql.NullTime { + return t.F +} +func (t *DtDatetime) GetG() sql.NullTime { + return t.G +} +func (t *DtDatetime) GetH() sql.NullTime { + return t.H +} + type DtDatetimeNotNull struct { A time.Time B time.Time @@ -45,6 +102,31 @@ type DtDatetimeNotNull struct { H time.Time } +func (t *DtDatetimeNotNull) GetA() time.Time { + return t.A +} +func (t *DtDatetimeNotNull) GetB() time.Time { + return t.B +} +func (t *DtDatetimeNotNull) GetC() time.Time { + return t.C +} +func (t *DtDatetimeNotNull) GetD() time.Time { + return t.D +} +func (t *DtDatetimeNotNull) GetE() time.Time { + return t.E +} +func (t *DtDatetimeNotNull) GetF() time.Time { + return t.F +} +func (t *DtDatetimeNotNull) GetG() time.Time { + return t.G +} +func (t *DtDatetimeNotNull) GetH() time.Time { + return t.H +} + type DtNumeric struct { A int16 B sql.NullInt32 @@ -58,6 +140,37 @@ type DtNumeric struct { J sql.NullInt64 } +func (t *DtNumeric) GetA() int16 { + return t.A +} +func (t *DtNumeric) GetB() sql.NullInt32 { + return t.B +} +func (t *DtNumeric) GetC() sql.NullInt64 { + return t.C +} +func (t *DtNumeric) GetD() sql.NullString { + return t.D +} +func (t *DtNumeric) GetE() sql.NullString { + return t.E +} +func (t *DtNumeric) GetF() sql.NullFloat64 { + return t.F +} +func (t *DtNumeric) GetG() sql.NullFloat64 { + return t.G +} +func (t *DtNumeric) GetH() int16 { + return t.H +} +func (t *DtNumeric) GetI() sql.NullInt32 { + return t.I +} +func (t *DtNumeric) GetJ() sql.NullInt64 { + return t.J +} + type DtNumericNotNull struct { A int16 B int32 @@ -70,3 +183,34 @@ type DtNumericNotNull struct { I int32 J int64 } + +func (t *DtNumericNotNull) GetA() int16 { + return t.A +} +func (t *DtNumericNotNull) GetB() int32 { + return t.B +} +func (t *DtNumericNotNull) GetC() int64 { + return t.C +} +func (t *DtNumericNotNull) GetD() string { + return t.D +} +func (t *DtNumericNotNull) GetE() string { + return t.E +} +func (t *DtNumericNotNull) GetF() float32 { + return t.F +} +func (t *DtNumericNotNull) GetG() float64 { + return t.G +} +func (t *DtNumericNotNull) GetH() int16 { + return t.H +} +func (t *DtNumericNotNull) GetI() int32 { + return t.I +} +func (t *DtNumericNotNull) GetJ() int64 { + return t.J +} diff --git a/internal/endtoend/testdata/experimental_dolphin/go/models.go b/internal/endtoend/testdata/experimental_dolphin/go/models.go index 518b1bade7..85b6848674 100644 --- a/internal/endtoend/testdata/experimental_dolphin/go/models.go +++ b/internal/endtoend/testdata/experimental_dolphin/go/models.go @@ -9,6 +9,17 @@ type Baz struct { Email string } +func (t *Baz) GetName() string { + return t.Name +} +func (t *Baz) GetEmail() string { + return t.Email +} + type Foo struct { Bar string } + +func (t *Foo) GetBar() string { + return t.Bar +} diff --git a/internal/endtoend/testdata/experimental_elephant/go/models.go b/internal/endtoend/testdata/experimental_elephant/go/models.go index 397456ec7f..5151fdce00 100644 --- a/internal/endtoend/testdata/experimental_elephant/go/models.go +++ b/internal/endtoend/testdata/experimental_elephant/go/models.go @@ -31,6 +31,17 @@ type Baz struct { Email string } +func (t *Baz) GetName() string { + return t.Name +} +func (t *Baz) GetEmail() string { + return t.Email +} + type Foo struct { Bar string } + +func (t *Foo) GetBar() string { + return t.Bar +} diff --git a/internal/endtoend/testdata/experimental_lemon/go/models.go b/internal/endtoend/testdata/experimental_lemon/go/models.go index 518b1bade7..85b6848674 100644 --- a/internal/endtoend/testdata/experimental_lemon/go/models.go +++ b/internal/endtoend/testdata/experimental_lemon/go/models.go @@ -9,6 +9,17 @@ type Baz struct { Email string } +func (t *Baz) GetName() string { + return t.Name +} +func (t *Baz) GetEmail() string { + return t.Email +} + type Foo struct { Bar string } + +func (t *Foo) GetBar() string { + return t.Bar +} diff --git a/internal/endtoend/testdata/ext_ltree/go/models.go b/internal/endtoend/testdata/ext_ltree/go/models.go index 7e9881aaeb..7585e0763a 100644 --- a/internal/endtoend/testdata/ext_ltree/go/models.go +++ b/internal/endtoend/testdata/ext_ltree/go/models.go @@ -11,3 +11,13 @@ type Foo struct { NameQuery sql.NullString FtsNameQuery sql.NullString } + +func (t *Foo) GetQualifiedName() sql.NullString { + return t.QualifiedName +} +func (t *Foo) GetNameQuery() sql.NullString { + return t.NameQuery +} +func (t *Foo) GetFtsNameQuery() sql.NullString { + return t.FtsNameQuery +} diff --git a/internal/endtoend/testdata/identical_tables/go/models.go b/internal/endtoend/testdata/identical_tables/go/models.go index 31b9b47eb4..77c0216bfd 100644 --- a/internal/endtoend/testdata/identical_tables/go/models.go +++ b/internal/endtoend/testdata/identical_tables/go/models.go @@ -8,6 +8,14 @@ type Bar struct { ID string } +func (t *Bar) GetID() string { + return t.ID +} + type Foo struct { ID string } + +func (t *Foo) GetID() string { + return t.ID +} diff --git a/internal/endtoend/testdata/in/go/models.go b/internal/endtoend/testdata/in/go/models.go index 7c3b98644d..1ebd04c005 100644 --- a/internal/endtoend/testdata/in/go/models.go +++ b/internal/endtoend/testdata/in/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { ID int32 } + +func (t *Bar) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/insert_cte/go/models.go b/internal/endtoend/testdata/insert_cte/go/models.go index d514e4feaa..c2ab36c85d 100644 --- a/internal/endtoend/testdata/insert_cte/go/models.go +++ b/internal/endtoend/testdata/insert_cte/go/models.go @@ -18,6 +18,31 @@ type Td3Code struct { IsPrivate sql.NullBool } +func (t *Td3Code) GetID() int32 { + return t.ID +} +func (t *Td3Code) GetTsCreated() time.Time { + return t.TsCreated +} +func (t *Td3Code) GetTsUpdated() time.Time { + return t.TsUpdated +} +func (t *Td3Code) GetCreatedBy() string { + return t.CreatedBy +} +func (t *Td3Code) GetUpdatedBy() string { + return t.UpdatedBy +} +func (t *Td3Code) GetCode() sql.NullString { + return t.Code +} +func (t *Td3Code) GetHash() sql.NullString { + return t.Hash +} +func (t *Td3Code) GetIsPrivate() sql.NullBool { + return t.IsPrivate +} + type Td3TestCode struct { ID int32 TsCreated time.Time @@ -27,3 +52,25 @@ type Td3TestCode struct { TestID int32 CodeHash string } + +func (t *Td3TestCode) GetID() int32 { + return t.ID +} +func (t *Td3TestCode) GetTsCreated() time.Time { + return t.TsCreated +} +func (t *Td3TestCode) GetTsUpdated() time.Time { + return t.TsUpdated +} +func (t *Td3TestCode) GetCreatedBy() string { + return t.CreatedBy +} +func (t *Td3TestCode) GetUpdatedBy() string { + return t.UpdatedBy +} +func (t *Td3TestCode) GetTestID() int32 { + return t.TestID +} +func (t *Td3TestCode) GetCodeHash() string { + return t.CodeHash +} diff --git a/internal/endtoend/testdata/insert_select/go/models.go b/internal/endtoend/testdata/insert_select/go/models.go index b9f6dc7049..c7306be1f7 100644 --- a/internal/endtoend/testdata/insert_select/go/models.go +++ b/internal/endtoend/testdata/insert_select/go/models.go @@ -9,7 +9,21 @@ type Bar struct { Ready bool } +func (t *Bar) GetName() string { + return t.Name +} +func (t *Bar) GetReady() bool { + return t.Ready +} + type Foo struct { Name string Meta string } + +func (t *Foo) GetName() string { + return t.Name +} +func (t *Foo) GetMeta() string { + return t.Meta +} diff --git a/internal/endtoend/testdata/join_alias/go/models.go b/internal/endtoend/testdata/join_alias/go/models.go index 072d9099f4..a54e084aee 100644 --- a/internal/endtoend/testdata/join_alias/go/models.go +++ b/internal/endtoend/testdata/join_alias/go/models.go @@ -11,6 +11,17 @@ type Bar struct { Title sql.NullString } +func (t *Bar) GetID() int32 { + return t.ID +} +func (t *Bar) GetTitle() sql.NullString { + return t.Title +} + type Foo struct { ID int32 } + +func (t *Foo) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/join_text_array/go/models.go b/internal/endtoend/testdata/join_text_array/go/models.go index 1344e7ffea..175f6e23fc 100644 --- a/internal/endtoend/testdata/join_text_array/go/models.go +++ b/internal/endtoend/testdata/join_text_array/go/models.go @@ -9,7 +9,21 @@ type Bar struct { Info []string } +func (t *Bar) GetID() string { + return t.ID +} +func (t *Bar) GetInfo() []string { + return t.Info +} + type Foo struct { ID string Bar string } + +func (t *Foo) GetID() string { + return t.ID +} +func (t *Foo) GetBar() string { + return t.Bar +} diff --git a/internal/endtoend/testdata/join_where_clause/go/models.go b/internal/endtoend/testdata/join_where_clause/go/models.go index 55b92580ce..e793214235 100644 --- a/internal/endtoend/testdata/join_where_clause/go/models.go +++ b/internal/endtoend/testdata/join_where_clause/go/models.go @@ -9,6 +9,17 @@ type Bar struct { Owner string } +func (t *Bar) GetID() int32 { + return t.ID +} +func (t *Bar) GetOwner() string { + return t.Owner +} + type Foo struct { Barid int32 } + +func (t *Foo) GetBarid() int32 { + return t.Barid +} diff --git a/internal/endtoend/testdata/limit/go/models.go b/internal/endtoend/testdata/limit/go/models.go index c7700695cd..a6f5bed63e 100644 --- a/internal/endtoend/testdata/limit/go/models.go +++ b/internal/endtoend/testdata/limit/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { Bar bool } + +func (t *Foo) GetBar() bool { + return t.Bar +} diff --git a/internal/endtoend/testdata/lower/go/models.go b/internal/endtoend/testdata/lower/go/models.go index d90fb10d47..d416a5c857 100644 --- a/internal/endtoend/testdata/lower/go/models.go +++ b/internal/endtoend/testdata/lower/go/models.go @@ -8,3 +8,10 @@ type Foo struct { Bar string Bat string } + +func (t *Foo) GetBar() string { + return t.Bar +} +func (t *Foo) GetBat() string { + return t.Bat +} diff --git a/internal/endtoend/testdata/lower_switched_order/go/models.go b/internal/endtoend/testdata/lower_switched_order/go/models.go index d90fb10d47..d416a5c857 100644 --- a/internal/endtoend/testdata/lower_switched_order/go/models.go +++ b/internal/endtoend/testdata/lower_switched_order/go/models.go @@ -8,3 +8,10 @@ type Foo struct { Bar string Bat string } + +func (t *Foo) GetBar() string { + return t.Bar +} +func (t *Foo) GetBat() string { + return t.Bat +} diff --git a/internal/endtoend/testdata/macaddr/go/models.go b/internal/endtoend/testdata/macaddr/go/models.go index 0681470ceb..9671f151ec 100644 --- a/internal/endtoend/testdata/macaddr/go/models.go +++ b/internal/endtoend/testdata/macaddr/go/models.go @@ -10,3 +10,10 @@ type Foo struct { Bar bool Addr net.HardwareAddr } + +func (t *Foo) GetBar() bool { + return t.Bar +} +func (t *Foo) GetAddr() net.HardwareAddr { + return t.Addr +} diff --git a/internal/endtoend/testdata/mathmatical_operator/go/models.go b/internal/endtoend/testdata/mathmatical_operator/go/models.go index ca9cda8055..6eb597379e 100644 --- a/internal/endtoend/testdata/mathmatical_operator/go/models.go +++ b/internal/endtoend/testdata/mathmatical_operator/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { Num int32 } + +func (t *Foo) GetNum() int32 { + return t.Num +} diff --git a/internal/endtoend/testdata/multifrom/go/models.go b/internal/endtoend/testdata/multifrom/go/models.go index c71c6a9097..da0c798aae 100644 --- a/internal/endtoend/testdata/multifrom/go/models.go +++ b/internal/endtoend/testdata/multifrom/go/models.go @@ -8,6 +8,14 @@ type Bar struct { Login string } +func (t *Bar) GetLogin() string { + return t.Login +} + type Foo struct { Email string } + +func (t *Foo) GetEmail() string { + return t.Email +} diff --git a/internal/endtoend/testdata/mysql_enums/go/models.go b/internal/endtoend/testdata/mysql_enums/go/models.go index ffbd3edc8e..67b06a8731 100644 --- a/internal/endtoend/testdata/mysql_enums/go/models.go +++ b/internal/endtoend/testdata/mysql_enums/go/models.go @@ -68,3 +68,13 @@ type Example struct { UserID UserIDType LastName LastNameType } + +func (t *Example) GetFirstName() FirstNameType { + return t.FirstName +} +func (t *Example) GetUserID() UserIDType { + return t.UserID +} +func (t *Example) GetLastName() LastNameType { + return t.LastName +} diff --git a/internal/endtoend/testdata/mysql_overrides/go/models.go b/internal/endtoend/testdata/mysql_overrides/go/models.go index cd74d6a1b1..61f3ae6439 100644 --- a/internal/endtoend/testdata/mysql_overrides/go/models.go +++ b/internal/endtoend/testdata/mysql_overrides/go/models.go @@ -36,6 +36,16 @@ type Order struct { UserID int } +func (t *Order) GetID() mysql.ID { + return t.ID +} +func (t *Order) GetPrice() float64 { + return t.Price +} +func (t *Order) GetUserID() int { + return t.UserID +} + type User struct { ID mysql.ID FirstName string @@ -44,3 +54,22 @@ type User struct { JobStatus JobStatusType Created mysql.Timestamp } + +func (t *User) GetID() mysql.ID { + return t.ID +} +func (t *User) GetFirstName() string { + return t.FirstName +} +func (t *User) GetLastName() sql.NullString { + return t.LastName +} +func (t *User) GetAge() int { + return t.Age +} +func (t *User) GetJobStatus() JobStatusType { + return t.JobStatus +} +func (t *User) GetCreated() mysql.Timestamp { + return t.Created +} diff --git a/internal/endtoend/testdata/mysql_param/go/models.go b/internal/endtoend/testdata/mysql_param/go/models.go index 4b6cc6075d..6c8b6f4df4 100644 --- a/internal/endtoend/testdata/mysql_param/go/models.go +++ b/internal/endtoend/testdata/mysql_param/go/models.go @@ -34,6 +34,16 @@ type Order struct { UserID int } +func (t *Order) GetID() int { + return t.ID +} +func (t *Order) GetPrice() float64 { + return t.Price +} +func (t *Order) GetUserID() int { + return t.UserID +} + type User struct { ID int FirstName string @@ -41,3 +51,19 @@ type User struct { Age int JobStatus JobStatusType } + +func (t *User) GetID() int { + return t.ID +} +func (t *User) GetFirstName() string { + return t.FirstName +} +func (t *User) GetLastName() sql.NullString { + return t.LastName +} +func (t *User) GetAge() int { + return t.Age +} +func (t *User) GetJobStatus() JobStatusType { + return t.JobStatus +} diff --git a/internal/endtoend/testdata/mysql_parse/go/models.go b/internal/endtoend/testdata/mysql_parse/go/models.go index cc62ede78b..69a1ec1171 100644 --- a/internal/endtoend/testdata/mysql_parse/go/models.go +++ b/internal/endtoend/testdata/mysql_parse/go/models.go @@ -34,6 +34,16 @@ type Order struct { UserID int `json:"user_id"` } +func (t *Order) GetID() int { + return t.ID +} +func (t *Order) GetPrice() float64 { + return t.Price +} +func (t *Order) GetUserID() int { + return t.UserID +} + type User struct { ID int `json:"id"` FirstName string `json:"first_name"` @@ -41,3 +51,19 @@ type User struct { Age int `json:"age"` JobStatus JobStatusType `json:"job_status"` } + +func (t *User) GetID() int { + return t.ID +} +func (t *User) GetFirstName() string { + return t.FirstName +} +func (t *User) GetLastName() sql.NullString { + return t.LastName +} +func (t *User) GetAge() int { + return t.Age +} +func (t *User) GetJobStatus() JobStatusType { + return t.JobStatus +} diff --git a/internal/endtoend/testdata/named_param/go/models.go b/internal/endtoend/testdata/named_param/go/models.go index 36b40a056b..aea88a0fca 100644 --- a/internal/endtoend/testdata/named_param/go/models.go +++ b/internal/endtoend/testdata/named_param/go/models.go @@ -8,3 +8,10 @@ type Foo struct { Name string Bio string } + +func (t *Foo) GetName() string { + return t.Name +} +func (t *Foo) GetBio() string { + return t.Bio +} diff --git a/internal/endtoend/testdata/ondeck/models.go b/internal/endtoend/testdata/ondeck/models.go index 168667f881..2a0a838492 100644 --- a/internal/endtoend/testdata/ondeck/models.go +++ b/internal/endtoend/testdata/ondeck/models.go @@ -32,6 +32,13 @@ type City struct { Name string } +func (t *City) GetSlug() string { + return t.Slug +} +func (t *City) GetName() string { + return t.Name +} + type Venue struct { ID int32 CreateAt time.Time @@ -42,3 +49,28 @@ type Venue struct { SpotifyPlaylist string SongkickID sql.NullString } + +func (t *Venue) GetID() int32 { + return t.ID +} +func (t *Venue) GetCreateAt() time.Time { + return t.CreateAt +} +func (t *Venue) GetStatus() Status { + return t.Status +} +func (t *Venue) GetSlug() string { + return t.Slug +} +func (t *Venue) GetName() string { + return t.Name +} +func (t *Venue) GetCity() string { + return t.City +} +func (t *Venue) GetSpotifyPlaylist() string { + return t.SpotifyPlaylist +} +func (t *Venue) GetSongkickID() sql.NullString { + return t.SongkickID +} diff --git a/internal/endtoend/testdata/overrides/go/models.go b/internal/endtoend/testdata/overrides/go/models.go index fb93846885..f4ad3d0e71 100644 --- a/internal/endtoend/testdata/overrides/go/models.go +++ b/internal/endtoend/testdata/overrides/go/models.go @@ -15,3 +15,22 @@ type Foo struct { Retyped pkg.CustomType Langs pq.StringArray } + +func (t *Foo) GetOther() string { + return t.Other +} +func (t *Foo) GetTotal() int64 { + return t.Total +} +func (t *Foo) GetTags() []string { + return t.Tags +} +func (t *Foo) GetByteSeq() []byte { + return t.ByteSeq +} +func (t *Foo) GetRetyped() pkg.CustomType { + return t.Retyped +} +func (t *Foo) GetLangs() pq.StringArray { + return t.Langs +} diff --git a/internal/endtoend/testdata/schema_scoped_create/go/models.go b/internal/endtoend/testdata/schema_scoped_create/go/models.go index 5c9241aabd..6e503478a7 100644 --- a/internal/endtoend/testdata/schema_scoped_create/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_create/go/models.go @@ -8,3 +8,10 @@ type FooBar struct { ID int32 Name string } + +func (t *FooBar) GetID() int32 { + return t.ID +} +func (t *FooBar) GetName() string { + return t.Name +} diff --git a/internal/endtoend/testdata/schema_scoped_delete/go/models.go b/internal/endtoend/testdata/schema_scoped_delete/go/models.go index 15c48626a7..bcf0cd7b87 100644 --- a/internal/endtoend/testdata/schema_scoped_delete/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_delete/go/models.go @@ -7,3 +7,7 @@ import () type FooBar struct { ID int32 } + +func (t *FooBar) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/schema_scoped_enum/go/models.go b/internal/endtoend/testdata/schema_scoped_enum/go/models.go index a33cd031ca..cfa76d6e75 100644 --- a/internal/endtoend/testdata/schema_scoped_enum/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_enum/go/models.go @@ -28,3 +28,7 @@ func (e *FooTypeUserRole) Scan(src interface{}) error { type FooUser struct { Role FooTypeUserRole } + +func (t *FooUser) GetRole() FooTypeUserRole { + return t.Role +} diff --git a/internal/endtoend/testdata/schema_scoped_filter/go/models.go b/internal/endtoend/testdata/schema_scoped_filter/go/models.go index 15c48626a7..bcf0cd7b87 100644 --- a/internal/endtoend/testdata/schema_scoped_filter/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_filter/go/models.go @@ -7,3 +7,7 @@ import () type FooBar struct { ID int32 } + +func (t *FooBar) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/schema_scoped_list/go/models.go b/internal/endtoend/testdata/schema_scoped_list/go/models.go index 15c48626a7..bcf0cd7b87 100644 --- a/internal/endtoend/testdata/schema_scoped_list/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_list/go/models.go @@ -7,3 +7,7 @@ import () type FooBar struct { ID int32 } + +func (t *FooBar) GetID() int32 { + return t.ID +} diff --git a/internal/endtoend/testdata/schema_scoped_update/go/models.go b/internal/endtoend/testdata/schema_scoped_update/go/models.go index 5c9241aabd..6e503478a7 100644 --- a/internal/endtoend/testdata/schema_scoped_update/go/models.go +++ b/internal/endtoend/testdata/schema_scoped_update/go/models.go @@ -8,3 +8,10 @@ type FooBar struct { ID int32 Name string } + +func (t *FooBar) GetID() int32 { + return t.ID +} +func (t *FooBar) GetName() string { + return t.Name +} diff --git a/internal/endtoend/testdata/select_column_cast/go/models.go b/internal/endtoend/testdata/select_column_cast/go/models.go index c7700695cd..a6f5bed63e 100644 --- a/internal/endtoend/testdata/select_column_cast/go/models.go +++ b/internal/endtoend/testdata/select_column_cast/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { Bar bool } + +func (t *Foo) GetBar() bool { + return t.Bar +} diff --git a/internal/endtoend/testdata/star/go/models.go b/internal/endtoend/testdata/star/go/models.go index 059a5cf2ea..f4e394d721 100644 --- a/internal/endtoend/testdata/star/go/models.go +++ b/internal/endtoend/testdata/star/go/models.go @@ -8,6 +8,14 @@ type Bar struct { Bid int32 } +func (t *Bar) GetBid() int32 { + return t.Bid +} + type Foo struct { Fid int32 } + +func (t *Foo) GetFid() int32 { + return t.Fid +} diff --git a/internal/endtoend/testdata/star_expansion/go/models.go b/internal/endtoend/testdata/star_expansion/go/models.go index ce7117644a..73b89c0637 100644 --- a/internal/endtoend/testdata/star_expansion/go/models.go +++ b/internal/endtoend/testdata/star_expansion/go/models.go @@ -10,3 +10,10 @@ type Foo struct { A sql.NullString B sql.NullString } + +func (t *Foo) GetA() sql.NullString { + return t.A +} +func (t *Foo) GetB() sql.NullString { + return t.B +} diff --git a/internal/endtoend/testdata/star_expansion_cte/go/models.go b/internal/endtoend/testdata/star_expansion_cte/go/models.go index 3e32636373..6cd936f45b 100644 --- a/internal/endtoend/testdata/star_expansion_cte/go/models.go +++ b/internal/endtoend/testdata/star_expansion_cte/go/models.go @@ -11,7 +11,21 @@ type Bar struct { D sql.NullString } +func (t *Bar) GetC() sql.NullString { + return t.C +} +func (t *Bar) GetD() sql.NullString { + return t.D +} + type Foo struct { A sql.NullString B sql.NullString } + +func (t *Foo) GetA() sql.NullString { + return t.A +} +func (t *Foo) GetB() sql.NullString { + return t.B +} diff --git a/internal/endtoend/testdata/star_expansion_from_cte/go/models.go b/internal/endtoend/testdata/star_expansion_from_cte/go/models.go index 3e32636373..6cd936f45b 100644 --- a/internal/endtoend/testdata/star_expansion_from_cte/go/models.go +++ b/internal/endtoend/testdata/star_expansion_from_cte/go/models.go @@ -11,7 +11,21 @@ type Bar struct { D sql.NullString } +func (t *Bar) GetC() sql.NullString { + return t.C +} +func (t *Bar) GetD() sql.NullString { + return t.D +} + type Foo struct { A sql.NullString B sql.NullString } + +func (t *Foo) GetA() sql.NullString { + return t.A +} +func (t *Foo) GetB() sql.NullString { + return t.B +} diff --git a/internal/endtoend/testdata/star_expansion_join/go/models.go b/internal/endtoend/testdata/star_expansion_join/go/models.go index 3e32636373..6cd936f45b 100644 --- a/internal/endtoend/testdata/star_expansion_join/go/models.go +++ b/internal/endtoend/testdata/star_expansion_join/go/models.go @@ -11,7 +11,21 @@ type Bar struct { D sql.NullString } +func (t *Bar) GetC() sql.NullString { + return t.C +} +func (t *Bar) GetD() sql.NullString { + return t.D +} + type Foo struct { A sql.NullString B sql.NullString } + +func (t *Foo) GetA() sql.NullString { + return t.A +} +func (t *Foo) GetB() sql.NullString { + return t.B +} diff --git a/internal/endtoend/testdata/star_expansion_reserved/go/models.go b/internal/endtoend/testdata/star_expansion_reserved/go/models.go index 696d7e3a5c..81c04bf24b 100644 --- a/internal/endtoend/testdata/star_expansion_reserved/go/models.go +++ b/internal/endtoend/testdata/star_expansion_reserved/go/models.go @@ -9,3 +9,7 @@ import ( type Foo struct { Group sql.NullString } + +func (t *Foo) GetGroup() sql.NullString { + return t.Group +} diff --git a/internal/endtoend/testdata/star_expansion_subquery/go/models.go b/internal/endtoend/testdata/star_expansion_subquery/go/models.go index ce7117644a..73b89c0637 100644 --- a/internal/endtoend/testdata/star_expansion_subquery/go/models.go +++ b/internal/endtoend/testdata/star_expansion_subquery/go/models.go @@ -10,3 +10,10 @@ type Foo struct { A sql.NullString B sql.NullString } + +func (t *Foo) GetA() sql.NullString { + return t.A +} +func (t *Foo) GetB() sql.NullString { + return t.B +} diff --git a/internal/endtoend/testdata/table_name/go/models.go b/internal/endtoend/testdata/table_name/go/models.go index 99f581177b..d1415c5495 100644 --- a/internal/endtoend/testdata/table_name/go/models.go +++ b/internal/endtoend/testdata/table_name/go/models.go @@ -10,7 +10,18 @@ type Bar struct { ID int32 } +func (t *Bar) GetID() int32 { + return t.ID +} + type Foo struct { ID int32 Bar sql.NullInt32 } + +func (t *Foo) GetID() int32 { + return t.ID +} +func (t *Foo) GetBar() sql.NullInt32 { + return t.Bar +} diff --git a/internal/endtoend/testdata/text_array/go/models.go b/internal/endtoend/testdata/text_array/go/models.go index 0492fe3a51..75f6ecab07 100644 --- a/internal/endtoend/testdata/text_array/go/models.go +++ b/internal/endtoend/testdata/text_array/go/models.go @@ -7,3 +7,7 @@ import () type Bar struct { Tags []string } + +func (t *Bar) GetTags() []string { + return t.Tags +} diff --git a/internal/endtoend/testdata/two_joins/go/models.go b/internal/endtoend/testdata/two_joins/go/models.go index ede1f2cdc4..264731a3b6 100644 --- a/internal/endtoend/testdata/two_joins/go/models.go +++ b/internal/endtoend/testdata/two_joins/go/models.go @@ -8,11 +8,26 @@ type Bar struct { ID int32 } +func (t *Bar) GetID() int32 { + return t.ID +} + type Baz struct { ID int32 } +func (t *Baz) GetID() int32 { + return t.ID +} + type Foo struct { BarID int32 BazID int32 } + +func (t *Foo) GetBarID() int32 { + return t.BarID +} +func (t *Foo) GetBazID() int32 { + return t.BazID +} diff --git a/internal/endtoend/testdata/unknown_func/go/models.go b/internal/endtoend/testdata/unknown_func/go/models.go index b443f16b28..fdfcfd8c7e 100644 --- a/internal/endtoend/testdata/unknown_func/go/models.go +++ b/internal/endtoend/testdata/unknown_func/go/models.go @@ -7,3 +7,7 @@ import () type Foo struct { ID string } + +func (t *Foo) GetID() string { + return t.ID +} diff --git a/internal/endtoend/testdata/update_set/go/models.go b/internal/endtoend/testdata/update_set/go/models.go index 1484d8fc4e..72c17b3219 100644 --- a/internal/endtoend/testdata/update_set/go/models.go +++ b/internal/endtoend/testdata/update_set/go/models.go @@ -8,3 +8,10 @@ type Foo struct { Name string Slug string } + +func (t *Foo) GetName() string { + return t.Name +} +func (t *Foo) GetSlug() string { + return t.Slug +} diff --git a/internal/endtoend/testdata/update_set_multiple/go/models.go b/internal/endtoend/testdata/update_set_multiple/go/models.go index 1484d8fc4e..72c17b3219 100644 --- a/internal/endtoend/testdata/update_set_multiple/go/models.go +++ b/internal/endtoend/testdata/update_set_multiple/go/models.go @@ -8,3 +8,10 @@ type Foo struct { Name string Slug string } + +func (t *Foo) GetName() string { + return t.Name +} +func (t *Foo) GetSlug() string { + return t.Slug +} diff --git a/internal/endtoend/testdata/yaml_overrides/go/models.go b/internal/endtoend/testdata/yaml_overrides/go/models.go index fb93846885..f4ad3d0e71 100644 --- a/internal/endtoend/testdata/yaml_overrides/go/models.go +++ b/internal/endtoend/testdata/yaml_overrides/go/models.go @@ -15,3 +15,22 @@ type Foo struct { Retyped pkg.CustomType Langs pq.StringArray } + +func (t *Foo) GetOther() string { + return t.Other +} +func (t *Foo) GetTotal() int64 { + return t.Total +} +func (t *Foo) GetTags() []string { + return t.Tags +} +func (t *Foo) GetByteSeq() []byte { + return t.ByteSeq +} +func (t *Foo) GetRetyped() pkg.CustomType { + return t.Retyped +} +func (t *Foo) GetLangs() pq.StringArray { + return t.Langs +}