/
column.go
108 lines (84 loc) · 2.78 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
101
102
103
104
105
106
107
108
package postgres
import "github.com/aodin/aspect"
// ColumnElem expands aspect's ColumnElem by adding PostGres specific operators
// and functions
type ColumnElem struct {
aspect.ColumnElem
}
func (c ColumnElem) operator(i interface{}, op Operator) aspect.BinaryClause {
return aspect.BinaryClause{
Pre: c,
Post: &aspect.Parameter{i},
Sep: " " + string(op) + " ",
}
}
func (c ColumnElem) function(f, name string) ColumnElem {
return ColumnElem{c.SetInner(aspect.BinaryClause{
Pre: c,
Post: &aspect.StringClause{Name: name},
Sep: f,
})}
}
func (c ColumnElem) GetJSON(name string) ColumnElem {
return c.function(" -> ", name)
}
func (c ColumnElem) GetJSONText(name string) ColumnElem {
return c.function(" ->> ", name)
}
func (c ColumnElem) NotEqual(i interface{}) aspect.BinaryClause {
return c.operator(i, NotEqual)
}
func (c ColumnElem) LessThan(i interface{}) aspect.BinaryClause {
return c.operator(i, LessThan)
}
func (c ColumnElem) GreaterThan(i interface{}) aspect.BinaryClause {
return c.operator(i, GreaterThan)
}
func (c ColumnElem) LessThanOrEqual(i interface{}) aspect.BinaryClause {
return c.operator(i, LessThanOrEqual)
}
func (c ColumnElem) GreaterThanOrEqual(i interface{}) aspect.BinaryClause {
return c.operator(i, GreaterThanOrEqual)
}
func (c ColumnElem) Contains(i interface{}) aspect.BinaryClause {
return c.operator(i, Contains)
}
func (c ColumnElem) ContainedBy(i interface{}) aspect.BinaryClause {
return c.operator(i, ContainedBy)
}
func (c ColumnElem) Overlap(i interface{}) aspect.BinaryClause {
return c.operator(i, Overlap)
}
func (c ColumnElem) StrictlyLeftOf(i interface{}) aspect.BinaryClause {
return c.operator(i, StrictlyLeftOf)
}
func (c ColumnElem) StrictlyRightOf(i interface{}) aspect.BinaryClause {
return c.operator(i, StrictlyRightOf)
}
func (c ColumnElem) DoesNotExtendToTheRightOf(i interface{}) aspect.BinaryClause {
return c.operator(i, DoesNotExtendToTheRightOf)
}
func (c ColumnElem) DoesNotExtendToTheLeftOf(i interface{}) aspect.BinaryClause {
return c.operator(i, DoesNotExtendToTheLeftOf)
}
func (c ColumnElem) IsAdjacentTo(i interface{}) aspect.BinaryClause {
return c.operator(i, IsAdjacentTo)
}
func (c ColumnElem) Union(i interface{}) aspect.BinaryClause {
return c.operator(i, Union)
}
func (c ColumnElem) Intersection(i interface{}) aspect.BinaryClause {
return c.operator(i, Intersection)
}
func (c ColumnElem) Difference(i interface{}) aspect.BinaryClause {
return c.operator(i, Difference)
}
// Column wraps an aspect ColumnElem and adds postgres specific functionality
// C wraps an aspect ColumnElem and adds postgres specific functionality
func Column(column aspect.ColumnElem) ColumnElem {
return C(column)
}
// C is a shorthand for Column
func C(column aspect.ColumnElem) ColumnElem {
return ColumnElem{column}
}