-
Notifications
You must be signed in to change notification settings - Fork 5
/
where.v
221 lines (189 loc) · 5.33 KB
/
where.v
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
module vsql
// where raw
// status: done
pub fn (mut db DB) where_raw(raw string, args ...string) &DB { // TODO: interface type
count := raw.count('?')
times := if count == -1 { 0 } else { count }
len := args.len
if times != len {
panic('the ? count is not match argument count')
}
mut condition := raw
for arg in args {
condition = condition.replace_once('?', arg)
}
w := Where{
typ: 'where_raw'
condition: condition
}
db.stmt.where << w
return db
}
// where
//make sure the other(and/or/not) where methods must be after where method
fn (mut db DB) check_where_order(operator string) {
if operator == '' {
db.stmt.has_where = true
}
if operator != '' && !db.stmt.has_where {
panic('the other(and/or/not) where methods must be after where method')
}
}
// status:done
fn (mut db DB) where_type(typ string, operator string, condition string) &DB {
db.check_where_order(operator)
w := Where{
typ: typ
operator: operator
condition: condition
}
db.stmt.where << w
return db
}
// status:done
pub fn (mut db DB) where(condition string) &DB {
return db.where_type('where', '', condition)
}
// status:done
pub fn (mut db DB) or_where(condition string) &DB {
return db.where_type('where', 'or', condition)
}
// status:done
pub fn (mut db DB) and_where(condition string) &DB {
return db.where_type('where', 'and', condition)
}
// status:done
pub fn (mut db DB) where_not(condition string) &DB {
return db.where_type('where', 'and not', condition)
}
// status:done
pub fn (mut db DB) or_where_not(condition string) &DB {
return db.where_type('where', 'or not', condition)
}
// where in
fn (mut db DB) where_in_type(typ string, operator string, column string, range []string) &DB {
db.check_where_order(operator)
w := Where{
typ: typ
operator: operator
column_name: column
range: range
}
db.stmt.where << w
return db
}
// status:done
pub fn (mut db DB) where_in(column string, range []string) &DB {
return db.where_in_type('where_in', '', column, range)
}
// status:done
pub fn (mut db DB) or_where_in(column string, range []string) &DB {
return db.where_in_type('where_in', 'or', column, range)
}
// status:done
pub fn (mut db DB) and_where_in(column string, range []string) &DB {
return db.where_in_type('where_in', 'and', column, range)
}
// status:done
pub fn (mut db DB) where_not_in(column string, range []string) &DB {
return db.where_in_type('where_in', 'and not', column, range)
}
// status:done
pub fn (mut db DB) or_where_not_in(column string, range []string) &DB {
return db.where_in_type('where_in', 'or not', column, range)
}
// where null
fn (mut db DB) where_null_type(typ string, operator string, column string) &DB {
db.check_where_order(operator)
w := Where{
typ: typ
operator: operator
column_name: column
}
db.stmt.where << w
return db
}
// status:done
pub fn (mut db DB) where_null(column string) &DB {
return db.where_null_type('where_null', '', column)
}
// status:done
pub fn (mut db DB) or_where_null(column string) &DB {
return db.where_null_type('where_null', 'or', column)
}
// status:done
pub fn (mut db DB) and_where_null(column string) &DB {
return db.where_null_type('where_null', 'and', column)
}
// status:done
pub fn (mut db DB) where_not_null(column string) &DB {
return db.where_null_type('where_null', 'and not', column)
}
// status:done
pub fn (mut db DB) or_where_not_null(column string) &DB {
return db.where_null_type('where_null', 'or not', column)
}
// where between
fn (mut db DB) where_between_type(typ string, operator string, column string, range []string) &DB {
db.check_where_order(operator)
w := Where{
typ: typ
operator: operator
column_name: column
range: range
}
db.stmt.where << w
return db
}
// status:done
pub fn (mut db DB) where_between(column string, range []string) &DB {
return db.where_between_type('where_between', '', column, range)
}
// status:done
pub fn (mut db DB) or_where_between(column string, range []string) &DB {
return db.where_between_type('where_between', 'or', column, range)
}
// status:done
pub fn (mut db DB) and_where_between(column string, range []string) &DB {
return db.where_between_type('where_between', 'and', column, range)
}
// status:done
pub fn (mut db DB) where_not_between(column string, range []string) &DB {
return db.where_between_type('where_between', 'and not', column, range)
}
// status:done
pub fn (mut db DB) or_where_not_between(column string, range []string) &DB {
return db.where_between_type('where_between', 'or not', column, range)
}
// where exists
// status:done
fn (mut db DB) where_exists_type(typ string, operator string, stmt string) &DB {
db.check_where_order(operator)
w := Where{
typ: typ
operator: operator
exist_stmt: stmt
}
db.stmt.where << w
return db
}
// status:done
pub fn (mut db DB) where_exists(stmt string) &DB {
return db.where_exists_type('where_exists', '', stmt)
}
// status:done
pub fn (mut db DB) or_where_exists(stmt string) &DB {
return db.where_exists_type('where_exists', 'or', stmt)
}
// status:done
pub fn (mut db DB) and_where_exists(stmt string) &DB {
return db.where_exists_type('where_exists', 'and', stmt)
}
// status:done
pub fn (mut db DB) where_not_exists(stmt string) &DB {
return db.where_exists_type('where_exists', 'and not', stmt)
}
// status:done
pub fn (mut db DB) or_where_not_exists(stmt string) &DB {
return db.where_exists_type('where_exists', 'or not', stmt)
}