Select statement execution and mapping to struct or slice added.

This commit is contained in:
sub0Zero 2019-03-05 18:55:47 +01:00 committed by zer0sub
parent 319c9f757d
commit 75f8e0dfec
6 changed files with 291 additions and 13 deletions

View file

@ -45,10 +45,11 @@ func (c ColumnInfo) GoBaseType() string {
case "smallint":
return "int16"
case "integer":
return "int"
return "int32"
case "bigint":
return "int64"
//case "date" : return "time.Time"
case "date", "timestamp without time zone", "timestamp with time zone":
return "time.Time"
case "bytea":
return "[]byte"
case "text":

View file

@ -15,6 +15,26 @@ type TableInfo struct {
DatabaseInfo *DatabaseInfo
}
func (t TableInfo) GetImports() []string {
imports := map[string]string{}
for _, column := range t.Columns {
columnType := column.GoBaseType()
if columnType == "time.Time" {
imports["time.Time"] = "time"
}
}
ret := []string{}
for _, packageImport := range imports {
ret = append(ret, packageImport)
}
return ret
}
func (t TableInfo) IsForeignKey(columnName string) bool {
_, exist := t.ForeignTableMap[columnName]

View file

@ -11,6 +11,8 @@ type {{.ToGoStructName}} struct {
{{- range .Columns}}
{{.ToGoFieldName}} sqlbuilder.NonAliasColumn
{{- end}}
All []sqlbuilder.Projection
}
var {{.ToGoVarName}} = &{{.ToGoStructName}}{
@ -20,6 +22,8 @@ var {{.ToGoVarName}} = &{{.ToGoStructName}}{
{{- range .Columns}}
{{.ToGoFieldName}}: {{.ToGoVarName}},
{{- end}}
All: []sqlbuilder.Projection{ {{.ToGoColumnFieldList ", "}} },
}
var (
@ -31,6 +35,10 @@ var (
var DataModelTemplate = `package model
{{range .GetImports}}
import "{{.}}"
{{end}}
type {{.ToGoModelStructName}} struct {
{{- range .Columns}}
{{.ToGoDMFieldName}} {{.ToGoType}} {{if .IsUnique}}` + "`sql:\"unique\"`" + ` {{end}}