2020-02-03 05:40:03 +03:00
|
|
|
package clause
|
|
|
|
|
|
|
|
type Values struct {
|
|
|
|
Columns []Column
|
|
|
|
Values [][]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name from clause name
|
|
|
|
func (Values) Name() string {
|
2020-02-19 07:53:46 +03:00
|
|
|
return "VALUES"
|
2020-02-03 05:40:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build build from clause
|
|
|
|
func (values Values) Build(builder Builder) {
|
|
|
|
if len(values.Columns) > 0 {
|
|
|
|
builder.WriteByte('(')
|
|
|
|
for idx, column := range values.Columns {
|
|
|
|
if idx > 0 {
|
|
|
|
builder.WriteByte(',')
|
|
|
|
}
|
|
|
|
builder.WriteQuoted(column)
|
|
|
|
}
|
|
|
|
builder.WriteByte(')')
|
|
|
|
|
2020-03-09 12:07:00 +03:00
|
|
|
builder.WriteString(" VALUES ")
|
2020-02-03 05:40:03 +03:00
|
|
|
|
|
|
|
for idx, value := range values.Values {
|
|
|
|
if idx > 0 {
|
|
|
|
builder.WriteByte(',')
|
|
|
|
}
|
|
|
|
|
2020-02-07 18:45:35 +03:00
|
|
|
builder.WriteByte('(')
|
2020-03-09 12:07:00 +03:00
|
|
|
builder.AddVar(builder, value...)
|
2020-02-03 05:40:03 +03:00
|
|
|
builder.WriteByte(')')
|
|
|
|
}
|
|
|
|
} else {
|
2020-03-09 12:07:00 +03:00
|
|
|
builder.WriteString("DEFAULT VALUES")
|
2020-02-03 05:40:03 +03:00
|
|
|
}
|
|
|
|
}
|
2020-02-07 18:45:35 +03:00
|
|
|
|
|
|
|
// MergeClause merge values clauses
|
|
|
|
func (values Values) MergeClause(clause *Clause) {
|
2020-02-19 07:53:46 +03:00
|
|
|
clause.Name = ""
|
2020-02-07 18:45:35 +03:00
|
|
|
clause.Expression = values
|
|
|
|
}
|