2020-01-29 14:22:44 +03:00
|
|
|
package clause
|
|
|
|
|
2020-01-30 10:14:48 +03:00
|
|
|
// Clause
|
|
|
|
type Clause struct {
|
|
|
|
Name string // WHERE
|
|
|
|
Priority float64
|
|
|
|
BeforeExpressions []Expression
|
|
|
|
AfterNameExpressions []Expression
|
|
|
|
AfterExpressions []Expression
|
|
|
|
Expression Expression
|
|
|
|
Builder ClauseBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClauseBuilder clause builder, allows to custmize how to build clause
|
|
|
|
type ClauseBuilder interface {
|
|
|
|
Build(Clause, Builder)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build build clause
|
|
|
|
func (c Clause) Build(builder Builder) {
|
|
|
|
if c.Builder != nil {
|
|
|
|
c.Builder.Build(c, builder)
|
|
|
|
} else {
|
|
|
|
builders := c.BeforeExpressions
|
|
|
|
if c.Name != "" {
|
|
|
|
builders = append(builders, Expr{c.Name})
|
|
|
|
}
|
|
|
|
|
|
|
|
builders = append(builders, c.AfterNameExpressions...)
|
|
|
|
if c.Expression != nil {
|
|
|
|
builders = append(builders, c.Expression)
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, expr := range append(builders, c.AfterExpressions...) {
|
|
|
|
if idx != 0 {
|
|
|
|
builder.WriteByte(' ')
|
|
|
|
}
|
|
|
|
expr.Build(builder)
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 14:22:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Interface clause interface
|
|
|
|
type Interface interface {
|
|
|
|
Name() string
|
2020-01-30 10:14:48 +03:00
|
|
|
Build(Builder)
|
|
|
|
MergeExpression(Expression)
|
2020-01-29 22:03:06 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 10:14:48 +03:00
|
|
|
type OverrideNameInterface interface {
|
|
|
|
OverrideName() string
|
2020-01-29 14:22:44 +03:00
|
|
|
}
|
|
|
|
|
2020-02-02 09:40:44 +03:00
|
|
|
// Column quote with name
|
|
|
|
type Column struct {
|
|
|
|
Table string
|
|
|
|
Name string
|
|
|
|
Alias string
|
|
|
|
Raw bool
|
2020-01-29 14:22:44 +03:00
|
|
|
}
|
|
|
|
|
2020-02-02 09:40:44 +03:00
|
|
|
func ToColumns(value ...interface{}) []Column {
|
|
|
|
return nil
|
2020-01-29 14:22:44 +03:00
|
|
|
}
|
|
|
|
|
2020-02-02 09:40:44 +03:00
|
|
|
// Table quote with name
|
|
|
|
type Table struct {
|
|
|
|
Table string
|
|
|
|
Alias string
|
|
|
|
Raw bool
|
2020-01-29 14:22:44 +03:00
|
|
|
}
|