Skip to content

Commit

Permalink
feat: Add sqlc version to generated Go code (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored Mar 28, 2022
1 parent 99a069a commit 031cd20
Show file tree
Hide file tree
Showing 1,286 changed files with 2,590 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/authors/mysql/db.go

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

2 changes: 2 additions & 0 deletions examples/authors/mysql/models.go

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

2 changes: 2 additions & 0 deletions examples/authors/mysql/query.sql.go

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

2 changes: 2 additions & 0 deletions examples/authors/postgresql/db.go

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

2 changes: 2 additions & 0 deletions examples/authors/postgresql/models.go

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

2 changes: 2 additions & 0 deletions examples/authors/postgresql/query.sql.go

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

2 changes: 2 additions & 0 deletions examples/batch/postgresql/batch.go

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

2 changes: 2 additions & 0 deletions examples/batch/postgresql/db.go

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

2 changes: 2 additions & 0 deletions examples/batch/postgresql/models.go

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

2 changes: 2 additions & 0 deletions examples/batch/postgresql/querier.go

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

2 changes: 2 additions & 0 deletions examples/batch/postgresql/query.sql.go

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

2 changes: 2 additions & 0 deletions examples/booktest/mysql/db.go

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

2 changes: 2 additions & 0 deletions examples/booktest/mysql/models.go

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

2 changes: 2 additions & 0 deletions examples/booktest/mysql/query.sql.go

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

2 changes: 2 additions & 0 deletions examples/booktest/postgresql/db.go

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

2 changes: 2 additions & 0 deletions examples/booktest/postgresql/models.go

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

2 changes: 2 additions & 0 deletions examples/booktest/postgresql/query.sql.go

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

2 changes: 2 additions & 0 deletions examples/jets/db.go

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

2 changes: 2 additions & 0 deletions examples/jets/models.go

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

2 changes: 2 additions & 0 deletions examples/jets/query-building.sql.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/mysql/city.sql.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/mysql/db.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/mysql/models.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/mysql/querier.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/mysql/venue.sql.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/postgresql/city.sql.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/postgresql/db.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/postgresql/models.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/postgresql/querier.go

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

2 changes: 2 additions & 0 deletions examples/ondeck/postgresql/venue.sql.go

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

15 changes: 9 additions & 6 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import (
"text/template"

"github.com/kyleconroy/sqlc/internal/codegen/sdk"
"github.com/kyleconroy/sqlc/internal/info"
"github.com/kyleconroy/sqlc/internal/metadata"
"github.com/kyleconroy/sqlc/internal/plugin"
)

type tmplCtx struct {
Q string
Package string
SQLPackage SQLPackage
Enums []Enum
Structs []Struct
GoQueries []Query
Q string
Package string
SQLPackage SQLPackage
Enums []Enum
Structs []Struct
GoQueries []Query
SqlcVersion string

// TODO: Race conditions
SourceName string
Expand Down Expand Up @@ -91,6 +93,7 @@ func generate(req *plugin.CodeGenRequest, enums []Enum, structs []Struct, querie
GoQueries: queries,
Enums: enums,
Structs: structs,
SqlcVersion: info.Version,
}

if tctx.UsesCopyFrom && tctx.SQLPackage != SQLPackagePGX {
Expand Down
14 changes: 13 additions & 1 deletion internal/codegen/golang/templates/template.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{define "dbFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}

package {{.Package}}

Expand All @@ -23,6 +25,8 @@ import (
{{end}}

{{define "interfaceFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}

package {{.Package}}

Expand All @@ -45,6 +49,8 @@ import (
{{end}}

{{define "modelsFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}

package {{.Package}}

Expand Down Expand Up @@ -95,6 +101,8 @@ type {{.Name}} struct { {{- range .Fields}}
{{end}}

{{define "queryFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
// source: {{.SourceName}}

package {{.Package}}
Expand All @@ -118,6 +126,8 @@ import (
{{end}}

{{define "copyfromFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
// source: {{.SourceName}}

package {{.Package}}
Expand All @@ -139,6 +149,8 @@ import (
{{end}}

{{define "batchFile"}}// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
// source: {{.SourceName}}
package {{.Package}}

Expand All @@ -155,4 +167,4 @@ import (
{{if eq .SQLPackage "pgx/v4"}}
{{- template "batchCodePgx" .}}
{{end}}
{{end}}
{{end}}
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/mysql/go/db.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/mysql/go/models.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/mysql/go/query.sql.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/pgx/go/db.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/pgx/go/models.go

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

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/stdlib/go/db.go

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

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

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/pgx/go/db.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/pgx/go/models.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/pgx/go/query.sql.go

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

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/stdlib/go/db.go

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

Loading

0 comments on commit 031cd20

Please sign in to comment.