Skip to content

Commit be1a27f

Browse files
committed
add flags
1 parent 8010aea commit be1a27f

File tree

32 files changed

+1601
-77
lines changed

32 files changed

+1601
-77
lines changed

internal/codegen/golang/gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type tmplCtx struct {
3737
EmitMethodsWithDBArgument bool
3838
EmitEnumValidMethod bool
3939
EmitAllEnumValues bool
40+
EmitEmbedAlias bool
4041
UsesCopyFrom bool
4142
UsesBatch bool
4243
BuildTags string
@@ -145,6 +146,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
145146
EmitMethodsWithDBArgument: options.EmitMethodsWithDbArgument,
146147
EmitEnumValidMethod: options.EmitEnumValidMethod,
147148
EmitAllEnumValues: options.EmitAllEnumValues,
149+
EmitEmbedAlias: options.EmitEmbedAlias,
148150
UsesCopyFrom: usesCopyFrom(queries),
149151
UsesBatch: usesBatch(queries),
150152
SQLDriver: parseDriver(options.SqlPackage),

internal/codegen/golang/opts/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Options struct {
2424
EmitPointersForNullTypes bool `json:"emit_pointers_for_null_types" yaml:"emit_pointers_for_null_types"`
2525
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
2626
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
27+
EmitEmbedAlias bool `json:"emit_embed_alias,omitempty" yaml:"emit_embed_alias"`
2728
JsonTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
2829
Package string `json:"package" yaml:"package"`
2930
Out string `json:"out" yaml:"out"`

internal/codegen/golang/result.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type goEmbed struct {
123123

124124
// look through all the structs and attempt to find a matching one to embed
125125
// We need the name of the struct and its field names.
126-
func newGoEmbed(columnName string, embed *plugin.Identifier, structs []Struct, defaultSchema string) *goEmbed {
126+
func newGoEmbed(options *opts.Options, columnName string, embed *plugin.Identifier, structs []Struct, defaultSchema string) *goEmbed {
127127
if embed == nil {
128128
return nil
129129
}
@@ -143,7 +143,7 @@ func newGoEmbed(columnName string, embed *plugin.Identifier, structs []Struct, d
143143
copy(fields, s.Fields)
144144

145145
structName := s.Name
146-
if s.Table.Name != columnName {
146+
if options.EmitEmbedAlias && s.Table.Name != columnName {
147147
structName = columnName
148148
}
149149

@@ -290,7 +290,7 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []
290290
columns = append(columns, goColumn{
291291
id: i,
292292
Column: c,
293-
embed: newGoEmbed(c.Name, c.EmbedTable, structs, req.Catalog.DefaultSchema),
293+
embed: newGoEmbed(options, c.Name, c.EmbedTable, structs, req.Catalog.DefaultSchema),
294294
})
295295
}
296296
var err error

internal/config/v_one.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type v1PackageSettings struct {
4141
EmitPointersForNullTypes bool `json:"emit_pointers_for_null_types" yaml:"emit_pointers_for_null_types"`
4242
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
4343
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
44+
EmitEmbedAlias bool `json:"emit_embed_alias,omitempty" yaml:"emit_embed_alias"`
4445
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
4546
SQLPackage string `json:"sql_package" yaml:"sql_package"`
4647
SQLDriver string `json:"sql_driver" yaml:"sql_driver"`
@@ -149,6 +150,7 @@ func (c *V1GenerateSettings) Translate() Config {
149150
EmitPointersForNullTypes: pkg.EmitPointersForNullTypes,
150151
EmitEnumValidMethod: pkg.EmitEnumValidMethod,
151152
EmitAllEnumValues: pkg.EmitAllEnumValues,
153+
EmitEmbedAlias: pkg.EmitEmbedAlias,
152154
Package: pkg.Name,
153155
Out: pkg.Path,
154156
SqlPackage: pkg.SQLPackage,

internal/endtoend/testdata/sqlc_embed/mysql/go/query.sql.go

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/sqlc_embed/postgresql/pgx/go/query.sql.go

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/sqlc_embed/postgresql/stdlib/go/query.sql.go

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)