Add self join support.
This commit is contained in:
parent
20c6f39665
commit
1cb997fc54
5 changed files with 89 additions and 15 deletions
|
|
@ -23,7 +23,7 @@ func (c ColumnInfo) IsUnique() bool {
|
|||
}
|
||||
|
||||
func (c ColumnInfo) ToGoVarName() string {
|
||||
return snaker.SnakeToCamelLower(c.TableInfo.Name) + snaker.SnakeToCamel(c.Name) + "Column"
|
||||
return snaker.SnakeToCamel(c.Name) + "Column"
|
||||
}
|
||||
|
||||
func (c ColumnInfo) ToGoType() string {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package generator
|
|||
|
||||
var SqlBuilderTableTemplate = `package table
|
||||
|
||||
import "github.com/sub0Zero/go-sqlbuilder/sqlbuilder"
|
||||
import (
|
||||
"github.com/sub0Zero/go-sqlbuilder/sqlbuilder"
|
||||
)
|
||||
|
||||
type {{.ToGoStructName}} struct {
|
||||
sqlbuilder.Table
|
||||
|
|
@ -15,22 +17,36 @@ type {{.ToGoStructName}} struct {
|
|||
AllColumns sqlbuilder.ColumnList
|
||||
}
|
||||
|
||||
var {{.ToGoVarName}} = &{{.ToGoStructName}}{
|
||||
Table: *sqlbuilder.NewTable("{{.DatabaseInfo.SchemaName}}", "{{.Name}}", {{.ToGoColumnFieldList ", "}}),
|
||||
|
||||
//Columns
|
||||
var {{.ToGoVarName}} = new{{.ToGoStructName}}()
|
||||
|
||||
func new{{.ToGoStructName}}() *{{.ToGoStructName}} {
|
||||
var (
|
||||
{{- range .Columns}}
|
||||
{{.ToGoVarName}} = sqlbuilder.IntColumn("{{.Name}}", {{if .IsNullable}}sqlbuilder.Nullable{{else}}sqlbuilder.NotNullable{{end}})
|
||||
{{- end}}
|
||||
)
|
||||
|
||||
return &{{.ToGoStructName}}{
|
||||
Table: *sqlbuilder.NewTable("{{.DatabaseInfo.SchemaName}}", "{{.Name}}", {{.ToGoColumnFieldList ", "}}),
|
||||
|
||||
//Columns
|
||||
{{- range .Columns}}
|
||||
{{.ToGoFieldName}}: {{.ToGoVarName}},
|
||||
{{.ToGoFieldName}}: {{.ToGoVarName}},
|
||||
{{- end}}
|
||||
|
||||
AllColumns: sqlbuilder.ColumnList{ {{.ToGoColumnFieldList ", "}} },
|
||||
AllColumns: sqlbuilder.ColumnList{ {{.ToGoColumnFieldList ", "}} },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (a *{{.ToGoStructName}}) As(alias string) *{{.ToGoStructName}} {
|
||||
aliasTable := new{{.ToGoStructName}}()
|
||||
|
||||
aliasTable.Table.SetAlias(alias)
|
||||
|
||||
return aliasTable
|
||||
}
|
||||
|
||||
var (
|
||||
{{- range .Columns}}
|
||||
{{.ToGoVarName}} = sqlbuilder.IntColumn("{{.Name}}", {{if .IsNullable}}sqlbuilder.Nullable{{else}}sqlbuilder.NotNullable{{end}})
|
||||
{{- end}}
|
||||
)
|
||||
`
|
||||
|
||||
var DataModelTemplate = `package model
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue