Auto columns in Inserts removed
This commit is contained in:
parent
a508530f63
commit
12dce9d986
4 changed files with 5 additions and 9 deletions
|
@ -75,7 +75,7 @@ func FilterColumnsByDefault(defaults bool, columns []Column) []Column {
|
||||||
var cols []Column
|
var cols []Column
|
||||||
|
|
||||||
for _, c := range columns {
|
for _, c := range columns {
|
||||||
if (defaults && (len(c.Default) != 0 || c.AutoGenerated)) || (!defaults && len(c.Default) == 0 && !c.AutoGenerated) {
|
if (defaults && len(c.Default) != 0) || (!defaults && len(c.Default) == 0) {
|
||||||
cols = append(cols, c)
|
cols = append(cols, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (m *MSSQLDriver) Columns(schema, tableName string) ([]bdb.Column, error) {
|
||||||
return nil, errors.Wrapf(err, "unable to scan for table %s", tableName)
|
return nil, errors.Wrapf(err, "unable to scan for table %s", tableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto = identity || strings.EqualFold(colType, "timestamp") || strings.EqualFold(colType, "rowversion")
|
auto = strings.EqualFold(colType, "timestamp") || strings.EqualFold(colType, "rowversion")
|
||||||
|
|
||||||
column := bdb.Column{
|
column := bdb.Column{
|
||||||
Name: colName,
|
Name: colName,
|
||||||
|
@ -182,6 +182,8 @@ func (m *MSSQLDriver) Columns(schema, tableName string) ([]bdb.Column, error) {
|
||||||
|
|
||||||
if defaultValue != nil && *defaultValue != "NULL" {
|
if defaultValue != nil && *defaultValue != "NULL" {
|
||||||
column.Default = *defaultValue
|
column.Default = *defaultValue
|
||||||
|
} else if identity || auto {
|
||||||
|
column.Default = "auto"
|
||||||
}
|
}
|
||||||
columns = append(columns, column)
|
columns = append(columns, column)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
var (
|
var (
|
||||||
{{$varNameSingular}}Columns = []string{{"{"}}{{.Table.Columns | columnNames | stringMap .StringFuncs.quoteWrap | join ", "}}{{"}"}}
|
{{$varNameSingular}}Columns = []string{{"{"}}{{.Table.Columns | columnNames | stringMap .StringFuncs.quoteWrap | join ", "}}{{"}"}}
|
||||||
{{if eq .DriverName "mssql" -}}
|
{{if eq .DriverName "mssql" -}}
|
||||||
{{$varNameSingular}}ColumnsWithoutAuto = []string{{"{"}}{{.Table.Columns | filterColumnsByAuto false | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
{{$varNameSingular}}ColumnsWithAuto = []string{{"{"}}{{.Table.Columns | filterColumnsByAuto true | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{$varNameSingular}}ColumnsWithoutDefault = []string{{"{"}}{{.Table.Columns | filterColumnsByDefault false | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
{{$varNameSingular}}ColumnsWithoutDefault = []string{{"{"}}{{.Table.Columns | filterColumnsByDefault false | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
||||||
{{$varNameSingular}}ColumnsWithDefault = []string{{"{"}}{{.Table.Columns | filterColumnsByDefault true | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
{{$varNameSingular}}ColumnsWithDefault = []string{{"{"}}{{.Table.Columns | filterColumnsByDefault true | columnNames | stringMap .StringFuncs.quoteWrap | join ","}}{{"}"}}
|
||||||
|
|
|
@ -50,11 +50,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
|
||||||
|
|
||||||
if !cached {
|
if !cached {
|
||||||
wl, returnColumns := strmangle.InsertColumnSet(
|
wl, returnColumns := strmangle.InsertColumnSet(
|
||||||
{{if ne .DriverName "mssql" -}}
|
|
||||||
{{$varNameSingular}}Columns,
|
{{$varNameSingular}}Columns,
|
||||||
{{- else -}}
|
|
||||||
{{$varNameSingular}}ColumnsWithoutAuto,
|
|
||||||
{{- end}}
|
|
||||||
{{$varNameSingular}}ColumnsWithDefault,
|
{{$varNameSingular}}ColumnsWithDefault,
|
||||||
{{$varNameSingular}}ColumnsWithoutDefault,
|
{{$varNameSingular}}ColumnsWithoutDefault,
|
||||||
nzDefaults,
|
nzDefaults,
|
||||||
|
@ -87,7 +83,6 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
|
||||||
{{end -}}
|
{{end -}}
|
||||||
}
|
}
|
||||||
|
|
||||||
{{if ne .DriverName "mssql" -}}
|
|
||||||
if len(cache.retMapping) != 0 {
|
if len(cache.retMapping) != 0 {
|
||||||
{{if .UseLastInsertID -}}
|
{{if .UseLastInsertID -}}
|
||||||
cache.retQuery = fmt.Sprintf("SELECT {{.LQ}}%s{{.RQ}} FROM {{$schemaTable}} WHERE %s", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"), strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns))
|
cache.retQuery = fmt.Sprintf("SELECT {{.LQ}}%s{{.RQ}} FROM {{$schemaTable}} WHERE %s", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"), strmangle.WhereClause("{{.LQ}}", "{{.RQ}}", {{if .Dialect.IndexPlaceholders}}1{{else}}0{{end}}, {{$varNameSingular}}PrimaryKeyColumns))
|
||||||
|
@ -95,7 +90,6 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
|
||||||
cache.query += fmt.Sprintf(" RETURNING {{.LQ}}%s{{.RQ}}", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"))
|
cache.query += fmt.Sprintf(" RETURNING {{.LQ}}%s{{.RQ}}", strings.Join(returnColumns, "{{.RQ}},{{.LQ}}"))
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
{{end -}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value := reflect.Indirect(reflect.ValueOf(o))
|
value := reflect.Indirect(reflect.ValueOf(o))
|
||||||
|
|
Loading…
Reference in a new issue