From 580b7c833e96a6a08ba374e3103400256a82657a Mon Sep 17 00:00:00 2001 From: Bertold Kolics Date: Tue, 28 Nov 2023 11:11:04 -0600 Subject: [PATCH] issue#3018: [feat] add omit_sqlc_version to Go code generation --- internal/codegen/golang/gen.go | 2 ++ internal/codegen/golang/opts/options.go | 1 + .../codegen/golang/templates/template.tmpl | 21 +++++++++++-------- internal/config/v_one.go | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/codegen/golang/gen.go b/internal/codegen/golang/gen.go index 54b7427638..cbb86857b1 100644 --- a/internal/codegen/golang/gen.go +++ b/internal/codegen/golang/gen.go @@ -39,6 +39,7 @@ type tmplCtx struct { EmitAllEnumValues bool UsesCopyFrom bool UsesBatch bool + OmitSqlcVersion bool BuildTags string } @@ -185,6 +186,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, Structs: structs, SqlcVersion: req.SqlcVersion, BuildTags: options.BuildTags, + OmitSqlcVersion: options.OmitSqlcVersion, } if tctx.UsesCopyFrom && !tctx.SQLDriver.IsPGX() && options.SqlDriver != SQLDriverGoSQLDriverMySQL { diff --git a/internal/codegen/golang/opts/options.go b/internal/codegen/golang/opts/options.go index 6a1ed2a02a..7325520e78 100644 --- a/internal/codegen/golang/opts/options.go +++ b/internal/codegen/golang/opts/options.go @@ -39,6 +39,7 @@ type Options struct { OutputFilesSuffix string `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"` InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"` QueryParameterLimit *int32 `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"` + OmitSqlcVersion bool `json:"omit_sqlc_version,omitempty" yaml:"omit_sqlc_version"` OmitUnusedStructs bool `json:"omit_unused_structs,omitempty" yaml:"omit_unused_structs"` BuildTags string `json:"build_tags,omitempty" yaml:"build_tags"` } diff --git a/internal/codegen/golang/templates/template.tmpl b/internal/codegen/golang/templates/template.tmpl index 29f29801c6..95400049c2 100644 --- a/internal/codegen/golang/templates/template.tmpl +++ b/internal/codegen/golang/templates/template.tmpl @@ -3,8 +3,9 @@ //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} +{{end}} package {{.Package}} @@ -33,8 +34,9 @@ import ( //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} +{{end}} package {{.Package}} @@ -61,8 +63,9 @@ import ( //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} +{{end}} package {{.Package}} @@ -158,9 +161,9 @@ type {{.Name}} struct { {{- range .Fields}} //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} -// source: {{.SourceName}} +{{end}}// source: {{.SourceName}} package {{.Package}} @@ -187,9 +190,9 @@ import ( //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} -// source: {{.SourceName}} +{{end}}// source: {{.SourceName}} package {{.Package}} @@ -216,9 +219,9 @@ import ( //go:build {{.BuildTags}} {{end}}// Code generated by sqlc. DO NOT EDIT. -// versions: +{{if not .OmitSqlcVersion}}// versions: // sqlc {{.SqlcVersion}} -// source: {{.SourceName}} +{{end}}// source: {{.SourceName}} package {{.Package}} diff --git a/internal/config/v_one.go b/internal/config/v_one.go index a675118697..17c4fcffa8 100644 --- a/internal/config/v_one.go +++ b/internal/config/v_one.go @@ -54,6 +54,7 @@ type v1PackageSettings struct { StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"` StrictOrderBy *bool `json:"strict_order_by" yaml:"strict_order_by"` QueryParameterLimit *int32 `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"` + OmitSqlcVersion bool `json:"omit_sqlc_version,omitempty" yaml:"omit_sqlc_version"` OmitUnusedStructs bool `json:"omit_unused_structs,omitempty" yaml:"omit_unused_structs"` Rules []string `json:"rules" yaml:"rules"` BuildTags string `json:"build_tags,omitempty" yaml:"build_tags"` @@ -162,6 +163,7 @@ func (c *V1GenerateSettings) Translate() Config { OutputCopyfromFileName: pkg.OutputCopyFromFileName, OutputFilesSuffix: pkg.OutputFilesSuffix, QueryParameterLimit: pkg.QueryParameterLimit, + OmitSqlcVersion: pkg.OmitSqlcVersion, OmitUnusedStructs: pkg.OmitUnusedStructs, BuildTags: pkg.BuildTags, },