-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq_field.go
50 lines (39 loc) · 1.01 KB
/
q_field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dal
import "fmt"
// Field creates an expression that represents a FieldRef value
func Field(name string) FieldRef {
return FieldRef{name: name}
}
type OrderExpression interface {
fmt.Stringer
Expression() Expression
Descending() bool
}
type orderExpression struct {
expression Expression
descending bool
}
func (v orderExpression) Expression() Expression {
return v.expression
}
func (v orderExpression) String() string {
if v.descending {
return v.expression.String() + " DESC"
}
return v.expression.String()
}
func (v orderExpression) Descending() bool {
return v.descending
}
func Ascending(expression Expression) OrderExpression {
return orderExpression{expression: expression, descending: false}
}
func AscendingField(name string) OrderExpression {
return Ascending(Field(name))
}
func Descending(expression Expression) OrderExpression {
return orderExpression{expression: expression, descending: true}
}
func DescendingField(name string) OrderExpression {
return Descending(Field(name))
}