Make it possible to add fully custom columns to table definition
This adds a few different fields to the column SQL builder that were once either calculated or hard-coded: * Import - so you can import the column from anywhere * Type - fully, rather than partially, modifiable to allow any naming convention * TypeFactory - fully, rather than partially defined I also alphabetized some things because the OCD compels me.
This commit is contained in:
parent
b30d7c524d
commit
2053415c76
4 changed files with 70 additions and 42 deletions
|
|
@ -14,7 +14,9 @@ var tableSQLBuilderTemplate = `
|
|||
package {{package}}
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/{{dialect.PackageName}}"
|
||||
{{- range $i, $import := imports .Columns}}
|
||||
"{{$import}}"
|
||||
{{- end}}
|
||||
)
|
||||
|
||||
var {{tableTemplate.InstanceName}} = new{{tableTemplate.TypeName}}("{{schemaName}}", "{{.Name}}", "{{tableTemplate.DefaultAlias}}")
|
||||
|
|
@ -27,7 +29,7 @@ type {{structImplName}} struct {
|
|||
{{- range $i, $c := .Columns}}
|
||||
{{- $field := columnField $c}}
|
||||
{{- if not $field.Skip}}
|
||||
{{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}} {{golangComment .Comment}}
|
||||
{{$field.Name}} {{$field.PackageName}}.{{$field.Type}} {{golangComment .Comment}}
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ func new{{tableTemplate.TypeName}}Impl(schemaName, tableName, alias string) {{st
|
|||
{{- range $i, $c := .Columns}}
|
||||
{{- $field := columnField $c}}
|
||||
{{- if not $field.Skip }}
|
||||
{{$field.Name}}Column = {{dialect.PackageName}}.{{$field.Type}}Column("{{$c.Name}}")
|
||||
{{$field.Name}}Column = {{$field.PackageName}}.{{$field.TypeFactory}}("{{$c.Name}}")
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
allColumns = {{dialect.PackageName}}.ColumnList{ {{columnList .Columns}} }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue