Add support for database json types.
This commit is contained in:
parent
37b0a6445b
commit
d84deb8745
6 changed files with 94 additions and 5 deletions
|
|
@ -88,6 +88,8 @@ func (c ColumnInfo) GoBaseType() string {
|
|||
return "float64"
|
||||
case "uuid":
|
||||
return "uuid.UUID"
|
||||
case "json", "jsonb":
|
||||
return "types.JSONText"
|
||||
default:
|
||||
fmt.Println("Unknown go map type: " + c.DataType + ", " + c.EnumName + ", using string instead.")
|
||||
return "string"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ func (t TableInfo) GetImports() []string {
|
|||
imports["time.Time"] = "time"
|
||||
case "uuid.UUID":
|
||||
imports["uuid.UUID"] = "github.com/google/uuid"
|
||||
case "types.JSONText":
|
||||
imports["types.JSONText"] = "github.com/sub0Zero/go-sqlbuilder/types"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,10 +51,15 @@ func (a *{{.ToGoStructName}}) As(alias string) *{{.ToGoStructName}} {
|
|||
|
||||
var DataModelTemplate = `package model
|
||||
|
||||
{{range .GetImports}}
|
||||
import "{{.}}"
|
||||
{{ if .GetImports }}
|
||||
import (
|
||||
{{- range .GetImports}}
|
||||
"{{.}}"
|
||||
{{- end}}
|
||||
)
|
||||
{{end}}
|
||||
|
||||
|
||||
type {{.ToGoModelStructName}} struct {
|
||||
{{- range .Columns}}
|
||||
{{.ToGoDMFieldName}} {{.ToGoType}} {{if .IsUnique}}` + "`sql:\"unique\"`" + ` {{end}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue