[postgres] Add support for ON CONFLICT clause
This commit is contained in:
parent
eea776a1ac
commit
14e1863456
42 changed files with 827 additions and 277 deletions
|
|
@ -3,6 +3,7 @@ package metadata
|
|||
import (
|
||||
"database/sql"
|
||||
"github.com/go-jet/jet/internal/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TableMetaData metadata struct
|
||||
|
|
@ -67,15 +68,19 @@ func (t TableMetaData) GoStructName() string {
|
|||
return utils.ToGoIdentifier(t.name) + "Table"
|
||||
}
|
||||
|
||||
// GoStructImplName returns go struct impl name for sql builder
|
||||
func (t TableMetaData) GoStructImplName() string {
|
||||
name := utils.ToGoIdentifier(t.name) + "Table"
|
||||
return string(strings.ToLower(name)[0]) + name[1:]
|
||||
}
|
||||
|
||||
// GetTableMetaData returns table info metadata
|
||||
func GetTableMetaData(db *sql.DB, querySet DialectQuerySet, schemaName, tableName string) (tableInfo TableMetaData) {
|
||||
|
||||
tableInfo.SchemaName = schemaName
|
||||
tableInfo.name = tableName
|
||||
|
||||
tableInfo.PrimaryKeys = getPrimaryKeys(db, querySet, schemaName, tableName)
|
||||
tableInfo.Columns = getColumnsMetaData(db, querySet, schemaName, tableName)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
var {{ToGoIdentifier .Name}} = new{{.GoStructName}}()
|
||||
|
||||
type {{.GoStructName}} struct {
|
||||
type {{.GoStructImplName}} struct {
|
||||
{{dialect.PackageName}}.Table
|
||||
|
||||
//Columns
|
||||
|
|
@ -38,32 +38,45 @@ type {{.GoStructName}} struct {
|
|||
MutableColumns {{dialect.PackageName}}.ColumnList
|
||||
}
|
||||
|
||||
type {{.GoStructName}} struct {
|
||||
{{.GoStructImplName}}
|
||||
|
||||
EXCLUDED {{.GoStructImplName}}
|
||||
}
|
||||
|
||||
// creates new {{.GoStructName}} with assigned alias
|
||||
func (a *{{.GoStructName}}) AS(alias string) *{{.GoStructName}} {
|
||||
aliasTable := new{{.GoStructName}}()
|
||||
|
||||
aliasTable.Table.AS(alias)
|
||||
|
||||
return aliasTable
|
||||
}
|
||||
|
||||
func new{{.GoStructName}}() *{{.GoStructName}} {
|
||||
return &{{.GoStructName}}{
|
||||
{{.GoStructImplName}}: new{{.GoStructName}}Impl("{{.SchemaName}}", "{{.Name}}"),
|
||||
EXCLUDED: new{{.GoStructName}}Impl("", "excluded"),
|
||||
}
|
||||
}
|
||||
|
||||
func new{{.GoStructName}}Impl(schemaName, tableName string) {{.GoStructImplName}} {
|
||||
var (
|
||||
{{- range .Columns}}
|
||||
{{ToGoIdentifier .Name}}Column = {{dialect.PackageName}}.{{.SqlBuilderColumnType}}Column("{{.Name}}")
|
||||
{{- end}}
|
||||
allColumns = {{dialect.PackageName}}.ColumnList{ {{template "column-list" .Columns}} }
|
||||
mutableColumns = {{dialect.PackageName}}.ColumnList{ {{template "column-list" .MutableColumns}} }
|
||||
)
|
||||
|
||||
return &{{.GoStructName}}{
|
||||
Table: {{dialect.PackageName}}.NewTable("{{.SchemaName}}", "{{.Name}}", {{template "column-list" .Columns}}),
|
||||
return {{.GoStructImplName}}{
|
||||
Table: {{dialect.PackageName}}.NewTable(schemaName, tableName, allColumns...),
|
||||
|
||||
//Columns
|
||||
{{- range .Columns}}
|
||||
{{ToGoIdentifier .Name}}: {{ToGoIdentifier .Name}}Column,
|
||||
{{- end}}
|
||||
|
||||
AllColumns: {{dialect.PackageName}}.ColumnList{ {{template "column-list" .Columns}} },
|
||||
MutableColumns: {{dialect.PackageName}}.ColumnList{ {{template "column-list" .MutableColumns}} },
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue