Skip to content

Commit d1c48d7

Browse files
author
Kyle Farris
committed
Fixes #34. Updated HISTORY file. Updated create_mock_dbs script to have travis build sqlserver as well (hopefull).
1 parent 392c952 commit d1c48d7

6 files changed

Lines changed: 41 additions & 23 deletions

File tree

HISTORY.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ you spot any mistakes.
66

77
## v2.0.0 (2018-06-15)
88

9-
* Added mssql support
10-
* Updated class files to use new ES6 class syntax for easier-maintainability
9+
### Breaking Changes
1110
* Changed the Query Builder instantiation syntax
11+
* Passing an empty array to `where_in` and `where_not_in` no longer throws an error ([#34](https://github.com/kylefarris/node-querybuilder/issues/34))
12+
13+
# General Enhancements/Changes/Features
14+
* Added mssql (t-sql) support using `tedious` as the underlying driver
15+
* Updated class files to use new ES6 class syntax for easier-maintainability
1216
* Added new options:
1317
** `pool_min` (minimum number of pooled connections (`mssql` driver only))
1418
** `acquireTimeout` (milliseconds before a timeout occurs during the connection acquisition)
1519
* Added new query building method: `returning()` to allow for insert IDs to be returned. See docs for more info.
1620
* Added new tests
21+
22+
### Bug Fixes
1723
* Fixed [#18](https://github.com/kylefarris/node-querybuilder/issues/18)
24+
* Fixed [#23](https://github.com/kylefarris/node-querybuilder/issues/23)
1825
* Fixed [#26](https://github.com/kylefarris/node-querybuilder/issues/26)
26+
* Fixed [#28](https://github.com/kylefarris/node-querybuilder/issues/28)
27+
* Fixed [#30](https://github.com/kylefarris/node-querybuilder/issues/30)
28+
* Fixed [#33](https://github.com/kylefarris/node-querybuilder/issues/33)
1929

2030

2131
## v1.2.0 (2018-05-18)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
TESTS = test/mysql/*.js test/mssql/*.js test/*.js
2-
#TESTS = test/mssql/01-tests-like.js
2+
#TESTS = test/mssql/01-tests-where_in.js
33
#TESTS = test/05-multiple-drivers.js
44
test:
55
mocha --timeout 5000 --reporter spec $(TESTS)

drivers/query_builder.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,21 +540,19 @@ class GenericQueryBuilder {
540540
throw new Error("where_" + (not === '' ? '' : not.toLowerCase() + '_') + "in(): Invalid field name provided.");
541541
}
542542

543-
// Values must be an array...
543+
// `values` must be an array...
544544
if (!Array.isArray(values)) {
545-
throw new Error("where_" + (not === '' ? '' : not.toLowerCase() + '_') + "in(): Invalid second parameter provided--it must be an array of scalar values.");
546-
}
547-
else {
548-
if (values.length == 0) {
549-
throw new Error("where_" + (not === '' ? '' : not.toLowerCase() + '_') + "in(): You have provided an empty list of values to limit resultset by.");
550-
}
545+
throw new Error("where_" + (not === '' ? '' : not.toLowerCase() + '_') + "in(): Invalid second parameter provided--it must be an array of scalar values or an empty array.");
551546
}
552547

548+
// If array is empty, ignore this request
549+
else if (values.length === 0) return;
550+
553551
for (let i in values) {
554552
this.where_in_array.push(this._qb_escape(values[i]));
555553
}
556554

557-
const prefix = (this.where_array.length == 0 ? '' : type);
555+
const prefix = (this.where_array.length === 0 ? '' : type);
558556
const where_in = prefix + this._protect_identifiers(key, false, escape) + not + " IN (" + this.where_in_array.join(', ') + ")";
559557
this.where_array.push(where_in);
560558

test/create_mock_dbs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22
./mysql/create_mysql_mock.sh
3-
#./mssql/create_mssql_mock.sh
3+
./mssql/create_mssql_mock.sh

test/mssql/01-tests-where_in.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('MSSQL: where_in()', () => {
3737
});
3838
it('should not accept anything but a non-empty array of values as second parameter', () => {
3939
qb.reset_query();
40-
expect(() => qb.where_in('planet'), 'nothing provided').to.throw(Error);
4140
expect(() => qb.where_in('planet', null), 'null provided').to.throw(Error);
4241
expect(() => qb.where_in('planet', false), 'false provided').to.throw(Error);
4342
expect(() => qb.where_in('planet', true), 'true provided').to.throw(Error);
@@ -47,17 +46,23 @@ describe('MSSQL: where_in()', () => {
4746
expect(() => qb.where_in('planet', 3.5), 'float provided').to.throw(Error);
4847
expect(() => qb.where_in('planet', NaN), 'NaN provided').to.throw(Error);
4948
expect(() => qb.where_in('planet', Infinity), 'Infinity provided').to.throw(Error);
50-
expect(() => qb.where_in('planet', []), 'empty array provided').to.throw(Error);
5149
expect(() => qb.where_in('planet', ''), 'empty string provided').to.throw(Error);
5250
expect(() => qb.where_in('planet', /foobar/), 'regex provided').to.throw(Error);
5351

52+
expect(() => qb.where_in('planet'), 'nothing provided (empty array is default value)').to.not.throw(Error);
53+
expect(() => qb.where_in('planet', []), 'empty array provided').to.not.throw(Error);
5454
expect(() => qb.where_in('planet', ['Mars','Earth','Venus','Mercury']), 'non-empty array provided').to.not.throw(Error);
5555
});
5656
it('should require both a field name an array of values as first and second parameters, respectively', () => {
5757
qb.reset_query();
5858
qb.where_in('planet_position', [1,2,3]);
5959
qb.where_array.should.eql(['[planet_position] IN (1, 2, 3)']);
6060
});
61+
it('should ignore the request if an empty array is provided to the second parameter', () => {
62+
qb.reset_query();
63+
qb.where_in('planet_position', []);
64+
qb.where_array.should.eql([]);
65+
});
6166
it('should concatenate multiple WHERE IN clauses with AND ', () => {
6267
qb.reset_query();
6368
qb.where_in('planet',['Mercury','Venus','Earth','Mars']);

test/mysql/01-tests-where_in.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ describe('MySQL: where_in()', () => {
3535

3636
expect(() => qb.where_in('planet_position',[1,2,3]), 'valid string provided').to.not.throw(Error);
3737
});
38-
it('should not accept anything but a non-empty array of values as second parameter', () => {
38+
it('should not accept anything but an array of values as second parameter', () => {
3939
qb.reset_query();
40-
expect(() => qb.where_in('planet'), 'nothing provided').to.throw(Error);
4140
expect(() => qb.where_in('planet',null), 'null provided').to.throw(Error);
4241
expect(() => qb.where_in('planet',false), 'false provided').to.throw(Error);
4342
expect(() => qb.where_in('planet',true), 'true provided').to.throw(Error);
@@ -47,31 +46,37 @@ describe('MySQL: where_in()', () => {
4746
expect(() => qb.where_in('planet',3.5), 'float provided').to.throw(Error);
4847
expect(() => qb.where_in('planet',NaN), 'NaN provided').to.throw(Error);
4948
expect(() => qb.where_in('planet',Infinity), 'Infinity provided').to.throw(Error);
50-
expect(() => qb.where_in('planet',[]), 'empty array provided').to.throw(Error);
5149
expect(() => qb.where_in('planet',''), 'empty string provided').to.throw(Error);
5250
expect(() => qb.where_in('planet',/foobar/), 'regex provided').to.throw(Error);
5351

54-
expect(() => qb.where_in('planet',['Mars','Earth','Venus','Mercury']), 'non-empty array provided').to.not.throw(Error);
52+
expect(() => qb.where_in('planet'), 'nothing provided (empty array is default value)').to.not.throw(Error);
53+
expect(() => qb.where_in('planet', []), 'empty array provided').to.not.throw(Error);
54+
expect(() => qb.where_in('planet', ['Mars','Earth','Venus','Mercury']), 'non-empty array provided').to.not.throw(Error);
5555
});
56-
it('should require both a field name an array of values as first and second parameters, respectively', () => {
56+
it('should accept both a field name and array of values as first and second parameters, respectively', () => {
5757
qb.reset_query();
58-
qb.where_in('planet_position',[1,2,3]);
58+
qb.where_in('planet_position', [1,2,3]);
5959
qb.where_array.should.eql(['`planet_position` IN (1, 2, 3)']);
6060
});
61+
it('should ignore the request if an empty array is provided to the second parameter', () => {
62+
qb.reset_query();
63+
qb.where_in('planet_position', []);
64+
qb.where_array.should.eql([]);
65+
});
6166
it('should concatenate multiple WHERE IN clauses with AND ', () => {
6267
qb.reset_query();
6368
qb.where_in('planet',['Mercury','Venus','Earth','Mars']);
64-
qb.where_in('galaxy_id',[123,456,789,0110]);
69+
qb.where_in('galaxy_id', [123, 456, 789, 0110]);
6570
qb.where_array.should.eql(["`planet` IN ('Mercury', 'Venus', 'Earth', 'Mars')","AND `galaxy_id` IN (123, 456, 789, 72)"]);
6671
});
6772
it('should be chainable', () => {
6873
qb.reset_query();
69-
qb.where_in('planet',['Mercury','Venus','Earth','Mars']).where_in('planet_position',[1,2,3,4]);
74+
qb.where_in('planet',['Mercury','Venus','Earth','Mars']).where_in('planet_position', [1,2,3,4]);
7075
qb.where_array.should.eql(["`planet` IN ('Mercury', 'Venus', 'Earth', 'Mars')","AND `planet_position` IN (1, 2, 3, 4)"]);
7176
});
7277
it('should not escape fields if asked not to', () => {
7378
qb.reset_query();
74-
qb.where_in('planet_position',[1,2,3],false);
79+
qb.where_in('planet_position', [1,2,3], false);
7580
qb.where_array.should.eql(['planet_position IN (1, 2, 3)']);
7681
});
7782
});

0 commit comments

Comments
 (0)