1
+ import * as Helpers from './Helpers'
2
+
1
3
/** @module Filters **/
2
4
/**
3
5
* All exports are prefixed with an underscore to avoid collisions with reserved keywords (eg: "in")
4
6
*/
5
7
6
-
7
-
8
8
/**
9
9
* Finds all rows whose value on the stated columnName exactly matches the specified filterValue.
10
10
* @param {string } columnName Name of the database column
@@ -153,7 +153,6 @@ export function _is(columnName, filterValue) {
153
153
return `${ columnName } =is.${ filterValue } `
154
154
}
155
155
156
-
157
156
/**
158
157
* Finds all rows whose value on the stated columnName is found on the specified filterArray.
159
158
* @param {string } columnName Name of the database column
@@ -166,9 +165,21 @@ export function _is(columnName, filterValue) {
166
165
* _in('name', ['China', 'France'])
167
166
* //=>
168
167
* 'name=in.(China,France)'
168
+ *
169
+ * @example
170
+ * _in('capitals', ['Beijing,China', 'Paris,France'])
171
+ * //=>
172
+ * 'capitals=in.("Beijing,China","Paris,France")'
173
+ *
174
+ * @example
175
+ * _in('food_supplies', ['carrot (big)', 'carrot (small)'])
176
+ * //=>
177
+ * 'food_supplies=in.("carrot (big)","carrot (small)")'
169
178
*/
170
- export function _in ( columnName , filterArray ) {
171
- return `${ columnName } =in.(${ filterArray . join ( ',' ) } )`
179
+ export function _in ( columnName , filterArray ) {
180
+ let cleanedFilterArray = Helpers . cleanFilterArray ( filterArray )
181
+
182
+ return `${ columnName } =in.(${ cleanedFilterArray . join ( ',' ) } )`
172
183
}
173
184
174
185
/**
@@ -202,12 +213,21 @@ export function _neq(columnName, filterValue) {
202
213
* 'countries=cs.{China,France}'
203
214
*
204
215
* @example
205
- * _cd('food_supplies ', {fruits:1000, meat:800} )
216
+ * _cs('capitals ', ['Beijing,China', 'Paris,France'] )
206
217
* //=>
207
- * 'food_supplies=cd.{"fruits":1000,"meat":800}'
218
+ * 'capitals=cs.{"Beijing,China","Paris,France"}'
219
+ *
220
+ * @example
221
+ * _cs('food_supplies', {fruits:1000, meat:800})
222
+ * //=>
223
+ * 'food_supplies=cs.{"fruits":1000,"meat":800}'
208
224
*/
209
225
export function _cs ( columnName , filterObject ) {
210
- if ( Array . isArray ( filterObject ) ) return `${ columnName } =cs.{${ filterObject . join ( ',' ) } }`
226
+ if ( Array . isArray ( filterObject ) ) {
227
+ let cleanedFilterArray = Helpers . cleanFilterArray ( filterObject )
228
+
229
+ return `${ columnName } =cs.{${ cleanedFilterArray . join ( ',' ) } }`
230
+ }
211
231
return `${ columnName } =cs.${ JSON . stringify ( filterObject ) } `
212
232
}
213
233
@@ -225,12 +245,21 @@ export function _cs(columnName, filterObject) {
225
245
* 'countries=cd.{China,France}'
226
246
*
227
247
* @example
248
+ * _cd('capitals', ['Beijing,China', 'Paris,France'])
249
+ * //=>
250
+ * 'capitals=cd.{"Beijing,China","Paris,France"}'
251
+ *
252
+ * @example
228
253
* _cd('food_supplies', {fruits:1000, meat:800})
229
254
* //=>
230
255
* 'food_supplies=cd.{"fruits":1000,"meat":800}'
231
256
*/
232
257
export function _cd ( columnName , filterObject ) {
233
- if ( Array . isArray ( filterObject ) ) return `${ columnName } =cd.{${ filterObject . join ( ',' ) } }`
258
+ if ( Array . isArray ( filterObject ) ) {
259
+ let cleanedFilterArray = Helpers . cleanFilterArray ( filterObject )
260
+
261
+ return `${ columnName } =cd.{${ cleanedFilterArray . join ( ',' ) } }`
262
+ }
234
263
return `${ columnName } =cd.${ JSON . stringify ( filterObject ) } `
235
264
}
236
265
@@ -241,14 +270,22 @@ export function _cd(columnName, filterObject) {
241
270
* @name ova
242
271
* @function
243
272
* @returns {string }
244
- *
273
+ *
245
274
* @example
246
275
* _ova('allies', ['China', 'France'])
247
276
* //=>
248
277
* 'allies=ov.{China,France}'
278
+ *
279
+ * @example
280
+ * _ova('capitals', ['Beijing,China', 'Paris,France'])
281
+ * //=>
282
+ * 'capitals=ov.{"Beijing,China","Paris,France"}'
283
+ *
249
284
*/
250
285
export function _ova ( columnName , filterArray ) {
251
- return `${ columnName } =ov.{${ filterArray . join ( ',' ) } }`
286
+ let cleanedFilterArray = Helpers . cleanFilterArray ( filterArray )
287
+
288
+ return `${ columnName } =ov.{${ cleanedFilterArray . join ( ',' ) } }`
252
289
}
253
290
254
291
/**
0 commit comments