-
Notifications
You must be signed in to change notification settings - Fork 0
/
column.go
100 lines (82 loc) · 1.38 KB
/
column.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package orm
type Column struct {
table TableReference
name string
alias string
}
func (c Column) assign() {}
func (c Column) expr() {}
//func (c Column) selectable() {}
func (c Column) selectedAlias() string {
return c.alias
}
func (c Column) fieldName() string {
return c.name
}
func (c Column) target() TableReference {
return c.table
}
func C(name string) Column {
return Column{name: name}
}
func (c Column) Add(val any) MathExpr {
return MathExpr{
left: c,
op: opAdd,
right: valueOf(val),
}
}
func (c Column) Multi(val any) MathExpr {
return MathExpr{
left: c,
op: opMulti,
right: valueOf(val),
}
}
type value struct {
val any
}
func (v value) expr() {}
func valueOf(val any) Expression {
switch v := val.(type) {
case Expression:
return v
default:
return value{val: val}
}
}
func (c Column) As(alias string) Column {
return Column{
name: c.name,
alias: alias,
}
}
// EQ 例如 C("id").Eq(12)
func (c Column) EQ(arg any) Predicate {
return Predicate{
left: c,
op: opEQ,
right: exprOf(arg),
}
}
func (c Column) LT(arg any) Predicate {
return Predicate{
left: c,
op: opLT,
right: exprOf(arg),
}
}
func (c Column) GT(arg any) Predicate {
return Predicate{
left: c,
op: opGT,
right: exprOf(arg),
}
}
func (c Column) In(arg any) Predicate {
return Predicate{
left: c,
op: opIN,
right: exprOf(arg),
}
}