gorm/clause/insert.go

40 lines
767 B
Go
Raw Normal View History

2020-02-03 05:40:03 +03:00
package clause
type Insert struct {
Table Table
2020-02-07 18:45:35 +03:00
Modifier string
2020-02-03 05:40:03 +03:00
}
// Name insert clause name
func (insert Insert) Name() string {
return "INSERT"
}
// Build build insert clause
func (insert Insert) Build(builder Builder) {
2020-02-07 18:45:35 +03:00
if insert.Modifier != "" {
2020-03-09 12:07:00 +03:00
builder.WriteString(insert.Modifier)
2020-02-03 05:40:03 +03:00
builder.WriteByte(' ')
}
2020-03-09 12:07:00 +03:00
builder.WriteString("INTO ")
2020-02-07 18:45:35 +03:00
if insert.Table.Name == "" {
builder.WriteQuoted(currentTable)
} else {
builder.WriteQuoted(insert.Table)
}
2020-02-03 05:40:03 +03:00
}
2020-02-07 18:45:35 +03:00
// MergeClause merge insert clause
func (insert Insert) MergeClause(clause *Clause) {
if v, ok := clause.Expression.(Insert); ok {
if insert.Modifier == "" {
insert.Modifier = v.Modifier
2020-02-03 05:40:03 +03:00
}
2020-02-07 18:45:35 +03:00
if insert.Table.Name == "" {
2020-02-03 05:40:03 +03:00
insert.Table = v.Table
}
}
2020-02-07 18:45:35 +03:00
clause.Expression = insert
2020-02-03 05:40:03 +03:00
}