Add StringColumn type and expression
Add Projection type Alias refactoring More numeric operations
This commit is contained in:
parent
033ab1d0da
commit
b2f84d048c
16 changed files with 350 additions and 199 deletions
|
|
@ -26,6 +26,31 @@ func (c ColumnInfo) ToGoVarName() string {
|
|||
return snaker.SnakeToCamel(c.Name) + "Column"
|
||||
}
|
||||
|
||||
func (c ColumnInfo) ToSqlBuilderColumnType() string {
|
||||
switch c.DataType {
|
||||
case "boolean":
|
||||
return "BoolColumn"
|
||||
case "smallint":
|
||||
return "IntegerColumn"
|
||||
case "integer":
|
||||
return "IntegerColumn"
|
||||
case "bigint":
|
||||
return "IntegerColumn"
|
||||
case "date", "timestamp without time zone", "timestamp with time zone":
|
||||
return "StringColumn"
|
||||
case "bytea":
|
||||
return "StringColumn"
|
||||
case "text":
|
||||
return "StringColumn"
|
||||
case "real":
|
||||
return "NumericColumn"
|
||||
case "numeric", "double precision":
|
||||
return "NumericColumn"
|
||||
default:
|
||||
return "StringColumn"
|
||||
}
|
||||
}
|
||||
|
||||
func (c ColumnInfo) ToGoType() string {
|
||||
typeStr := c.GoBaseType()
|
||||
if c.IsNullable || c.TableInfo.IsForeignKey(c.Name) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ type {{.ToGoStructName}} struct {
|
|||
|
||||
//Columns
|
||||
{{- range .Columns}}
|
||||
{{.ToGoFieldName}} sqlbuilder.NonAliasColumn
|
||||
{{.ToGoFieldName}} *sqlbuilder.{{.ToSqlBuilderColumnType}}
|
||||
{{- end}}
|
||||
|
||||
AllColumns sqlbuilder.ColumnList
|
||||
|
|
@ -22,7 +22,7 @@ var {{.ToGoVarName}} = new{{.ToGoStructName}}()
|
|||
func new{{.ToGoStructName}}() *{{.ToGoStructName}} {
|
||||
var (
|
||||
{{- range .Columns}}
|
||||
{{.ToGoVarName}} = sqlbuilder.IntColumn("{{.Name}}", {{if .IsNullable}}sqlbuilder.Nullable{{else}}sqlbuilder.NotNullable{{end}})
|
||||
{{.ToGoVarName}} = sqlbuilder.New{{.ToSqlBuilderColumnType}}("{{.Name}}", {{if .IsNullable}}sqlbuilder.Nullable{{else}}sqlbuilder.NotNullable{{end}})
|
||||
{{- end}}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue