2020-02-02 09:40:44 +03:00
|
|
|
package clause
|
|
|
|
|
|
|
|
// Select select attrs when querying, updating, creating
|
|
|
|
type Select struct {
|
2020-02-07 18:45:35 +03:00
|
|
|
Columns []Column
|
|
|
|
Omits []Column
|
2020-02-02 09:40:44 +03:00
|
|
|
}
|
|
|
|
|
2020-02-04 03:56:15 +03:00
|
|
|
func (s Select) Name() string {
|
|
|
|
return "SELECT"
|
2020-02-02 09:40:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s Select) Build(builder Builder) {
|
2020-02-07 18:45:35 +03:00
|
|
|
if len(s.Columns) > 0 {
|
|
|
|
for idx, column := range s.Columns {
|
2020-02-02 09:40:44 +03:00
|
|
|
if idx > 0 {
|
|
|
|
builder.WriteByte(',')
|
|
|
|
}
|
|
|
|
builder.WriteQuoted(column)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
builder.WriteByte('*')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 18:45:35 +03:00
|
|
|
func (s Select) MergeClause(clause *Clause) {
|
|
|
|
if v, ok := clause.Expression.(Select); ok {
|
|
|
|
s.Columns = append(v.Columns, s.Columns...)
|
|
|
|
s.Omits = append(v.Omits, s.Omits...)
|
2020-02-02 09:40:44 +03:00
|
|
|
}
|
2020-02-07 18:45:35 +03:00
|
|
|
clause.Expression = s
|
2020-02-02 09:40:44 +03:00
|
|
|
}
|