@@ -298,6 +298,24 @@ class Builder {
298
298
return null ;
299
299
}
300
300
301
+ _buildConditionBetween ( condition , isNot = false ) {
302
+ if ( ! Array . isArray ( condition . value ) || condition . value . length !== 2 ) {
303
+ throw new Error ( 'Value must be an array with two elements for "BETWEEN" condition' ) ;
304
+ }
305
+ this . values . push ( condition . value [ 0 ] || null ) ;
306
+ this . values . push ( condition . value [ 1 ] || null ) ;
307
+ if ( condition . key . indexOf ( '->' ) !== - 1 ) {
308
+ let keys = condition . key . split ( '->' ) ;
309
+ let k = `${ this . _buildFieldKey ( keys [ 0 ] ) } ` ;
310
+ let sql = `JSON_EXTRACT(${ k } , '${ keys [ 1 ] } ') ` ;
311
+ sql += isNot ? 'NOT BETWEEN' : 'BETWEEN' ;
312
+ sql += ' ? AND ?' ;
313
+ return sql ;
314
+ }
315
+ const opt = isNot ? 'NOT BETWEEN' : 'BETWEEN' ;
316
+ return `${ this . _buildFieldKey ( condition . key ) } ${ opt } ? AND ?` ;
317
+ }
318
+
301
319
_buildConditionIn ( condition , isNot = false ) {
302
320
if ( Array . isArray ( condition . value ) && ! condition . value . length ) {
303
321
throw new Error ( 'Value must not be empty for "IN" condition' ) ;
@@ -369,6 +387,10 @@ class Builder {
369
387
return this . _buildConditionIn ( c ) ;
370
388
} else if ( opt === 'not in' ) {
371
389
return this . _buildConditionIn ( c , true ) ;
390
+ } else if ( opt === 'between' ) {
391
+ return this . _buildConditionBetween ( c ) ;
392
+ } else if ( opt === 'not between' ) {
393
+ return this . _buildConditionBetween ( c , true ) ;
372
394
} else if ( opt === 'contain' ) {
373
395
return this . _buildConditionContain ( c ) ;
374
396
} else if ( opt === 'not contain' ) {
0 commit comments