forked from coocood/qbs
/
mapper_plus.go
207 lines (182 loc) · 5.15 KB
/
mapper_plus.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package db
type mapperPlus struct {
source *source
query Scope
}
func (mp *mapperPlus) identity() *mapperPlus {
if mp.query != nil {
return mp
} else {
return &mapperPlus{
source: mp.source,
query: mp.source.Identity(),
}
}
}
func (mp *mapperPlus) Identity() Scope {
return mp.Dupe()
}
func (mp *mapperPlus) Dupe() MapperPlus {
return &mapperPlus{source: mp.source, query: mp.query.Identity()}
}
func (mp *mapperPlus) Where(fragment string, args ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.Where(fragment, args...)
return mp
}
func (mp *mapperPlus) Having(fragment string, args ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.Having(fragment, args...)
return mp
}
func (mp *mapperPlus) GroupBy(groupItem string) Scope {
mp = mp.identity()
mp.query = mp.query.GroupBy(groupItem)
return mp
}
func (mp *mapperPlus) EqualTo(column string, val interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.EqualTo(column, val)
return mp
}
func (mp *mapperPlus) Between(column string, lower, upper interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.Between(column, lower, upper)
return mp
}
func (mp *mapperPlus) In(column string, items interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.In(column, items)
return mp
}
func (mp *mapperPlus) Cond(column string, condition COND, val interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.Cond(column, condition, val)
return mp
}
func (mp *mapperPlus) Limit(limit int) Scope {
mp = mp.identity()
mp.query = mp.query.Limit(limit)
return mp
}
func (mp *mapperPlus) Offset(offset int) Scope {
mp = mp.identity()
mp.query = mp.query.Offset(offset)
return mp
}
func (mp *mapperPlus) OrderBy(column, direction string) Scope {
mp = mp.identity()
mp.query = mp.query.OrderBy(column, direction)
return mp
}
func (mp *mapperPlus) Order(ordering string) Scope {
mp = mp.identity()
mp.query = mp.query.Order(ordering)
return mp
}
func (mp *mapperPlus) Reorder(ordering string) Scope {
mp = mp.identity()
mp.query = mp.query.Reorder(ordering)
return mp
}
func (mp *mapperPlus) Find(id, val interface{}) error {
return mp.source.Find(id, val)
}
func (mp *mapperPlus) SelectorSql() string {
return mp.identity().query.SelectorSql()
}
func (mp *mapperPlus) ConditionSql() (string, []interface{}) {
return mp.identity().query.ConditionSql()
}
func (mp *mapperPlus) JoinsSql() string {
return mp.identity().query.JoinsSql()
}
func (mp *mapperPlus) EndingSql() (string, []interface{}) {
return mp.identity().query.EndingSql()
}
func (mp *mapperPlus) Delete() error {
return mp.identity().Delete()
}
func (mp *mapperPlus) Retrieve(val interface{}) error {
return mp.identity().Retrieve(val)
}
func (mp *mapperPlus) RetrieveAll(dest interface{}) error {
return mp.identity().RetrieveAll(dest)
}
func (mp *mapperPlus) Count() (int64, error) {
return mp.identity().Count()
}
func (mp *mapperPlus) Pluck(column, vals interface{}) error {
return mp.identity().Pluck(column, vals)
}
func (mp *mapperPlus) TableName() string {
return mp.source.TableName()
}
func (mp *mapperPlus) PrimaryKeyColumn() string {
return mp.source.PrimaryKeyColumn()
}
func (mp *mapperPlus) UpdateAttribute(column string, val interface{}) error {
return mp.identity().UpdateAttribute(column, val)
}
func (mp *mapperPlus) UpdateAttributes(values Attributes) error {
return mp.identity().UpdateAttributes(values)
}
func (mp *mapperPlus) UpdateSql(sql string, vals ...interface{}) error {
return mp.identity().UpdateSql(sql, vals...)
}
func (mp *mapperPlus) Initialize(val ...interface{}) error {
return mp.source.Initialize(val...)
}
func (mp *mapperPlus) SaveAll(val interface{}) error {
return mp.source.SaveAll(val)
}
func (mp *mapperPlus) LeftJoin(joins ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.LeftJoin(joins...)
return mp
}
func (mp *mapperPlus) InnerJoin(joins ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.InnerJoin(joins...)
return mp
}
func (mp *mapperPlus) FullJoin(joins ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.FullJoin(joins...)
return mp
}
func (mp *mapperPlus) RightJoin(joins ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.RightJoin(joins...)
return mp
}
func (mp *mapperPlus) JoinSql(sql string, args ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.JoinSql(sql, args...)
return mp
}
func (mp *mapperPlus) LeftInclude(include ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.LeftInclude(include...)
return mp
}
func (mp *mapperPlus) InnerInclude(include ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.InnerInclude(include...)
return mp
}
func (mp *mapperPlus) FullInclude(include interface{}, nullRecords interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.FullInclude(include, nullRecords)
return mp
}
func (mp *mapperPlus) RightInclude(include interface{}, nullRecords interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.RightInclude(include, nullRecords)
return mp
}
func (mp *mapperPlus) IncludeSql(il IncludeList, query string, args ...interface{}) Scope {
mp = mp.identity()
mp.query = mp.query.IncludeSql(il, query, args...)
return mp
}