Skip to content

Add LeavePlural config option #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ type SQLGen struct {
type SQLGo struct {
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries":`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
}

type SQLKotlin struct {
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
}

type Override struct {
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 @@ -24,6 +24,7 @@ type v1PackageSettings struct {
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Overrides []Override `json:"overrides" yaml:"overrides"`
}

Expand Down Expand Up @@ -103,6 +104,7 @@ func (c *V1GenerateSettings) Translate() Config {
EmitInterface: pkg.EmitInterface,
EmitJSONTags: pkg.EmitJSONTags,
EmitPreparedQueries: pkg.EmitPreparedQueries,
EmitExactTableNames: pkg.EmitExactTableNames,
Package: pkg.Name,
Out: pkg.Path,
Overrides: pkg.Overrides,
Expand Down
6 changes: 5 additions & 1 deletion internal/dinosql/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,13 @@ func (r Result) Structs(settings config.CombinedSettings) []GoStruct {
} else {
tableName = name + "_" + table.Name
}
structName := tableName
if !settings.Go.EmitExactTableNames {
structName = inflection.Singular(structName)
}
s := GoStruct{
Table: core.FQN{Schema: name, Rel: table.Name},
Name: StructName(inflection.Singular(tableName), settings),
Name: StructName(structName, settings),
Comment: table.Comment,
}
for _, column := range table.Columns {
Expand Down
6 changes: 5 additions & 1 deletion internal/dinosql/kotlin/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,13 @@ func (r Result) KtDataClasses(settings config.CombinedSettings) []KtStruct {
} else {
tableName = name + "_" + table.Name
}
structName := KtDataClassName(tableName, settings)
if !settings.Go.EmitExactTableNames {
structName = inflection.Singular(structName)
}
s := KtStruct{
Table: core.FQN{Schema: name, Rel: table.Name},
Name: inflection.Singular(KtDataClassName(tableName, settings)),
Name: structName,
Comment: table.Comment,
}
for _, column := range table.Columns {
Expand Down
6 changes: 5 additions & 1 deletion internal/mysql/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ func (pGen PackageGenerator) enumNameFromColDef(col *sqlparser.ColumnDefinition)
func (r *Result) Structs(settings config.CombinedSettings) []dinosql.GoStruct {
var structs []dinosql.GoStruct
for tableName, cols := range r.Schema.tables {
structName := dinosql.StructName(tableName, settings)
if !(settings.Go.EmitExactTableNames || settings.Kotlin.EmitExactTableNames) {
structName = inflection.Singular(structName)
}
s := dinosql.GoStruct{
Name: inflection.Singular(dinosql.StructName(tableName, settings)),
Name: structName,
Table: core.FQN{tableName, "", ""}, // TODO: Complete hack. Only need for equality check to see if struct can be reused between queries
}

Expand Down