Skip to content

Commit

Permalink
feat: Add sqlc version to generated Kotlin code (#1512)
Browse files Browse the repository at this point in the history
* feat: Add sqlc version to generated Kotlin code
* Add version to all files
  • Loading branch information
kyleconroy authored Mar 28, 2022
1 parent 51f1ba4 commit 99a069a
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.authors.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.booktest.postgresql

Expand Down
2 changes: 2 additions & 0 deletions examples/kotlin/src/main/kotlin/com/example/jets/Models.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.jets

Expand Down
2 changes: 2 additions & 0 deletions examples/kotlin/src/main/kotlin/com/example/jets/Queries.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.jets

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.jets

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.mysql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.postgresql

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.12.0

package com.example.ondeck.postgresql

Expand Down
9 changes: 9 additions & 0 deletions internal/codegen/kotlin/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/kyleconroy/sqlc/internal/codegen/sdk"
"github.com/kyleconroy/sqlc/internal/inflection"
"github.com/kyleconroy/sqlc/internal/info"
"github.com/kyleconroy/sqlc/internal/metadata"
"github.com/kyleconroy/sqlc/internal/plugin"
)
Expand Down Expand Up @@ -533,6 +534,8 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
}

var ktIfaceTmpl = `// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
package {{.Package}}
Expand Down Expand Up @@ -564,6 +567,8 @@ interface Queries {
`

var ktModelsTmpl = `// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
package {{.Package}}
Expand Down Expand Up @@ -601,6 +606,8 @@ data class {{.Name}} ( {{- range $i, $e := .Fields}}
`

var ktSqlTmpl = `// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc {{.SqlcVersion}}
package {{.Package}}
Expand Down Expand Up @@ -723,6 +730,7 @@ type ktTmplCtx struct {
DataClasses []Struct
Queries []Query
Settings *plugin.Settings
SqlcVersion string

// TODO: Race conditions
SourceName string
Expand Down Expand Up @@ -785,6 +793,7 @@ func Generate(req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
Queries: queries,
Enums: enums,
DataClasses: structs,
SqlcVersion: info.Version,
}

output := map[string]string{}
Expand Down

0 comments on commit 99a069a

Please sign in to comment.