Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add flags
  • Loading branch information
sapk committed Nov 7, 2023
commit be1a27f1c283e31c3b17f96ce93a68efbf2b212e
2 changes: 2 additions & 0 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type tmplCtx struct {
EmitMethodsWithDBArgument bool
EmitEnumValidMethod bool
EmitAllEnumValues bool
EmitEmbedAlias bool
UsesCopyFrom bool
UsesBatch bool
BuildTags string
Expand Down Expand Up @@ -145,6 +146,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
EmitMethodsWithDBArgument: options.EmitMethodsWithDbArgument,
EmitEnumValidMethod: options.EmitEnumValidMethod,
EmitAllEnumValues: options.EmitAllEnumValues,
EmitEmbedAlias: options.EmitEmbedAlias,
UsesCopyFrom: usesCopyFrom(queries),
UsesBatch: usesBatch(queries),
SQLDriver: parseDriver(options.SqlPackage),
Expand Down
1 change: 1 addition & 0 deletions internal/codegen/golang/opts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Options struct {
EmitPointersForNullTypes bool `json:"emit_pointers_for_null_types" yaml:"emit_pointers_for_null_types"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
EmitEmbedAlias bool `json:"emit_embed_alias,omitempty" yaml:"emit_embed_alias"`
JsonTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Expand Down
6 changes: 3 additions & 3 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type goEmbed struct {

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

structName := s.Name
if s.Table.Name != columnName {
if options.EmitEmbedAlias && s.Table.Name != columnName {
structName = columnName
}

Expand Down Expand Up @@ -290,7 +290,7 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []
columns = append(columns, goColumn{
id: i,
Column: c,
embed: newGoEmbed(c.Name, c.EmbedTable, structs, req.Catalog.DefaultSchema),
embed: newGoEmbed(options, c.Name, c.EmbedTable, structs, req.Catalog.DefaultSchema),
})
}
var err error
Expand Down
2 changes: 2 additions & 0 deletions internal/config/v_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type v1PackageSettings struct {
EmitPointersForNullTypes bool `json:"emit_pointers_for_null_types" yaml:"emit_pointers_for_null_types"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
EmitEmbedAlias bool `json:"emit_embed_alias,omitempty" yaml:"emit_embed_alias"`
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
SQLPackage string `json:"sql_package" yaml:"sql_package"`
SQLDriver string `json:"sql_driver" yaml:"sql_driver"`
Expand Down Expand Up @@ -149,6 +150,7 @@ func (c *V1GenerateSettings) Translate() Config {
EmitPointersForNullTypes: pkg.EmitPointersForNullTypes,
EmitEnumValidMethod: pkg.EmitEnumValidMethod,
EmitAllEnumValues: pkg.EmitAllEnumValues,
EmitEmbedAlias: pkg.EmitEmbedAlias,
Package: pkg.Name,
Out: pkg.Path,
SqlPackage: pkg.SQLPackage,
Expand Down
32 changes: 16 additions & 16 deletions internal/endtoend/testdata/sqlc_embed/mysql/go/query.sql.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.

Loading