Add MutablColumns list into autogen sql builder table.
This commit is contained in:
parent
67e6fca0ce
commit
d6c59deb1f
11 changed files with 219 additions and 59 deletions
|
|
@ -16,10 +16,24 @@ func (t TableInfo) Name() string {
|
|||
return t.name
|
||||
}
|
||||
|
||||
func (t TableInfo) IsUnique(columnName string) bool {
|
||||
func (t TableInfo) IsPrimaryKey(columnName string) bool {
|
||||
return t.PrimaryKeys[columnName]
|
||||
}
|
||||
|
||||
func (t TableInfo) MutableColumns() []ColumnInfo {
|
||||
ret := []ColumnInfo{}
|
||||
|
||||
for _, column := range t.Columns {
|
||||
if t.IsPrimaryKey(column.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, column)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (t TableInfo) GetImports() []string {
|
||||
imports := map[string]string{}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ type {{.GoStructName}} struct {
|
|||
{{camelize .Name}} jet.Column{{.SqlBuilderColumnType}}
|
||||
{{- end}}
|
||||
|
||||
AllColumns jet.ColumnList
|
||||
AllColumns jet.ColumnList
|
||||
MutableColumns jet.ColumnList
|
||||
}
|
||||
|
||||
// creates new {{.GoStructName}} with assigned alias
|
||||
|
|
@ -63,7 +64,8 @@ func new{{.GoStructName}}() *{{.GoStructName}} {
|
|||
{{camelize .Name}}: {{camelize .Name}}Column,
|
||||
{{- end}}
|
||||
|
||||
AllColumns: jet.ColumnList{ {{template "column-list" .Columns}} },
|
||||
AllColumns: jet.ColumnList{ {{template "column-list" .Columns}} },
|
||||
MutableColumns: jet.ColumnList{ {{template "column-list" .MutableColumns}} },
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +84,7 @@ import (
|
|||
|
||||
type {{camelize .Name}} struct {
|
||||
{{- range .Columns}}
|
||||
{{camelize .Name}} {{.GoModelType}} ` + "{{.GoModelTag ($.IsUnique .Name)}}" + `
|
||||
{{camelize .Name}} {{.GoModelType}} ` + "{{.GoModelTag ($.IsPrimaryKey .Name)}}" + `
|
||||
{{- end}}
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue