From 2d2e7cb2372624b13e0eb11d0184c5e6113c4022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 13 Jun 2020 09:50:36 +0200 Subject: [PATCH] fix(QueryBuilder): support falsy values in between pairs (#556) --- src/Database/QueryBuilder/Chainable.ts | 2 +- test/database/query-builder.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Database/QueryBuilder/Chainable.ts b/src/Database/QueryBuilder/Chainable.ts index 99f9f718..0e83e78e 100644 --- a/src/Database/QueryBuilder/Chainable.ts +++ b/src/Database/QueryBuilder/Chainable.ts @@ -54,7 +54,7 @@ export abstract class Chainable extends Macroable implements ChainableContract { */ private getBetweenPair (value: any[]): any { const [lhs, rhs] = value - if (!lhs || !rhs) { + if (lhs === undefined || rhs === undefined) { throw new Error('Invalid array for whereBetween value') } diff --git a/test/database/query-builder.spec.ts b/test/database/query-builder.spec.ts index b0d91e34..78c71116 100644 --- a/test/database/query-builder.spec.ts +++ b/test/database/query-builder.spec.ts @@ -2051,12 +2051,12 @@ test.group('Query Builder | whereBetween', (group) => { let db = getQueryBuilder(getQueryClient(connection)) const { sql, bindings } = db .from('users') - .whereBetween('age', [18, 20]) + .whereBetween('age', [0, 20]) .toSQL() const { sql: knexSql, bindings: knexBindings } = connection.client! .from('users') - .whereBetween('age', [18, 20]) + .whereBetween('age', [0, 20]) .toSQL() assert.equal(sql, knexSql)