Skip to content

when we use snowflake generate id #868

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ type tmplCtx struct {
SourceName string

EmitJSONTags bool
Int64ToStringTags bool
EmitDBTags bool
EmitPreparedQueries bool
EmitInterface bool
Expand Down Expand Up @@ -401,6 +402,7 @@ func generate(settings config.CombinedSettings, enums []Enum, structs []Struct,
Settings: settings.Global,
EmitInterface: golang.EmitInterface,
EmitJSONTags: golang.EmitJSONTags,
Int64ToStringTags: golang.Int64ToStringTags,
EmitDBTags: golang.EmitDBTags,
EmitPreparedQueries: golang.EmitPreparedQueries,
EmitEmptySlices: golang.EmitEmptySlices,
Expand Down
18 changes: 14 additions & 4 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ func buildStructs(r *compiler.Result, settings config.CombinedSettings) []Struct
if settings.Go.EmitDBTags {
tags["db:"] = column.Name
}
t := goType(r, compiler.ConvertColumn(table.Rel, column), settings)
if settings.Go.EmitJSONTags {
tags["json:"] = column.Name
if t == "int64" && settings.Go.Int64ToStringTags {
tags["json:"] = column.Name + ",string"
} else {
tags["json:"] = column.Name
}
}
s.Fields = append(s.Fields, Field{
Name: StructName(column.Name, settings),
Type: goType(r, compiler.ConvertColumn(table.Rel, column), settings),
Type: t,
Tags: tags,
Comment: column.Comment,
})
Expand Down Expand Up @@ -258,12 +263,17 @@ func columnsToStruct(r *compiler.Result, name string, columns []goColumn, settin
if settings.Go.EmitDBTags {
tags["db:"] = tagName
}
t := goType(r, c.Column, settings)
if settings.Go.EmitJSONTags {
tags["json:"] = tagName
if t == "int64" && settings.Go.Int64ToStringTags {
tags["json:"] = tagName + ",string"
} else {
tags["json:"] = tagName
}
}
gs.Fields = append(gs.Fields, Field{
Name: fieldName,
Type: goType(r, c.Column, settings),
Type: t,
Tags: tags,
})
seen[colName]++
Expand Down
1 change: 1 addition & 0 deletions internal/codegen/kotlin/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ type ktTmplCtx struct {
SourceName string

EmitJSONTags bool
Int64ToStringTags bool
EmitPreparedQueries bool
EmitInterface bool
}
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type SQLGen struct {
type SQLGo struct {
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
Int64ToStringTags bool `json:"int64_to_string_tags" yaml:"int64_to_string_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
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 @@ -23,6 +23,7 @@ type v1PackageSettings struct {
Queries Paths `json:"queries" yaml:"queries"`
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
Int64ToStringTags bool `json:"int64_to_string_tags" yaml:"int64_to_string_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Expand Down Expand Up @@ -105,6 +106,7 @@ func (c *V1GenerateSettings) Translate() Config {
Go: &SQLGo{
EmitInterface: pkg.EmitInterface,
EmitJSONTags: pkg.EmitJSONTags,
Int64ToStringTags: pkg.Int64ToStringTags,
EmitDBTags: pkg.EmitDBTags,
EmitPreparedQueries: pkg.EmitPreparedQueries,
EmitExactTableNames: pkg.EmitExactTableNames,
Expand Down