forked from chuckpreslar/codex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.go
More file actions
122 lines (100 loc) · 3.67 KB
/
table.go
File metadata and controls
122 lines (100 loc) · 3.67 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package codex
// TableNode is a specific BinaryNode
type TableNode struct {
Name string // Table's Name
Alias *string // Table's Alias
Adapter adapter
scopes []ScopeFunc
}
func (self *TableNode) Scopes(scopes ...ScopeFunc) *TableNode {
for _, scope := range scopes {
self.scopes = append(self.scopes, scope)
}
return self
}
// TableNode factory method.
func Table(name string) (relation *TableNode) {
relation = new(TableNode)
relation.Name = name
return
}
// Col returns a Column scoped to this table
func (t *TableNode) Col(name string) *AttributeNode {
return Attribute(Column(name), t)
}
// Star returns a * scoped to this table e.g. renders to '"tablename".*' sql
func (t *TableNode) Star() *AttributeNode {
return Attribute(Star(), t)
}
// Select returns a SelectManager
// appends the columns
func (t *TableNode) Select(cols ...interface{}) *SelectManager {
// convert string to AttributeNode
for i, col := range cols {
if str, ok := col.(string); ok {
cols[i] = t.Col(str)
}
}
return Selection(t).Scopes(t.scopes...).Select(cols...)
}
// Where Returns a pointer to a SelectManager with the initial filter provided.
// see SelectManager.Where()
func (t *TableNode) Where(expr interface{}, args ...interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).Where(expr, args...)
}
// Returns a pointer to a SelectManager with an initial InnerJoinNode.
func (t *TableNode) InnerJoin(expr interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).InnerJoin(expr)
}
// Returns a pointer to a SelectManager with an initial OuterJoinNode.
func (t *TableNode) OuterJoin(expr interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).OuterJoin(expr)
}
// Returns a pointer to a SelectManager with an initial Ordering.
func (t *TableNode) Order(expr interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).Order(expr)
}
// Returns a pointer to a SelectManager with an initial Grouping.
func (t *TableNode) Group(groupings ...interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).Group(groupings...)
}
// Returns a pointer to a SelectManager with an initial Having.
func (t *TableNode) Having(expr interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).Having(expr)
}
// Count Returns a pointer to a new SelectManager
func (t *TableNode) Count(expr interface{}) *SelectManager {
return Selection(t).Scopes(t.scopes...).Count(expr)
}
// // Returns a pointer to a SelectManager with for the given TableNode.
// func (t *TableNode) From(relation *TableNode) *SelectManager {
// return Selection(relation)
// }
// Returns a pointer to a InsertManager with initial the values provided.
func (t *TableNode) Insert(expr ...interface{}) *InsertManager {
return Insertion(t).Insert(expr...)
}
// Returns a pointer to a UpdateManager with initial the columns provided.
func (t *TableNode) Set(expr ...interface{}) *UpdateManager {
return Modification(t).Scopes(t.scopes...).Set(expr...)
}
// Returns a pointer to a DeleteManager with the initial filter provided.
func (t *TableNode) Delete(expr interface{}) *DeleteManager {
return Deletion(t).Scopes(t.scopes...).Delete(expr)
}
// Returns a pointer to a InsertManager initialized with Table
func (t *TableNode) Insertion() *InsertManager {
return Insertion(t)
}
// Returns a pointer to a UpdateManager initialized with Table
func (t *TableNode) Modification() *UpdateManager {
return Modification(t)
}
// Returns a pointer to a SelectManager initialized with Table
func (t *TableNode) Selection() *SelectManager {
return Selection(t)
}
// Returns a pointer to a DeleteManager initialized with Table
func (t *TableNode) Deletion() *DeleteManager {
return Deletion(t)
}