foxhound 2.0.16 → 2.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxhound",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -211,12 +211,29 @@ var FoxHoundDialectSQLite = function(pFable)
211
211
  // Close a logical grouping
212
212
  tmpWhere += ' )';
213
213
  }
214
- else if (tmpFilter[i].Operator === 'IN')
214
+ else if (tmpFilter[i].Operator === 'IN' || tmpFilter[i].Operator === 'NOT IN')
215
215
  {
216
216
  tmpColumnParameter = tmpFilter[i].Parameter+'_w'+i;
217
- // Add the column name, operator and parameter name to the list of where value parenthetical
218
- tmpWhere += ' '+escapeColumn(tmpFilter[i].Column, pParameters)+' '+tmpFilter[i].Operator+' ( :'+tmpColumnParameter+' )';
219
- pParameters.query.parameters[tmpColumnParameter] = tmpFilter[i].Value;
217
+ // SQLite (better-sqlite3) cannot bind arrays as a single parameter.
218
+ // Expand the array into individual named parameters for each element.
219
+ var tmpFilterValue = tmpFilter[i].Value;
220
+ if (Array.isArray(tmpFilterValue))
221
+ {
222
+ var tmpParameterNames = [];
223
+ for (var j = 0; j < tmpFilterValue.length; j++)
224
+ {
225
+ var tmpElementParameter = tmpColumnParameter+'_'+j;
226
+ tmpParameterNames.push(':'+tmpElementParameter);
227
+ pParameters.query.parameters[tmpElementParameter] = tmpFilterValue[j];
228
+ }
229
+ tmpWhere += ' '+escapeColumn(tmpFilter[i].Column, pParameters)+' '+tmpFilter[i].Operator+' ( '+tmpParameterNames.join(', ')+' )';
230
+ }
231
+ else
232
+ {
233
+ // If for some reason the value is not an array, fall back to the old behavior
234
+ tmpWhere += ' '+escapeColumn(tmpFilter[i].Column, pParameters)+' '+tmpFilter[i].Operator+' ( :'+tmpColumnParameter+' )';
235
+ pParameters.query.parameters[tmpColumnParameter] = tmpFilterValue;
236
+ }
220
237
  }
221
238
  else if (tmpFilter[i].Operator === 'IS NOT NULL')
222
239
  {
@@ -207,7 +207,7 @@ suite
207
207
  // This is the query generated by the SQLite dialect
208
208
  _Fable.log.trace('Select Query', tmpQuery.query);
209
209
  Expect(tmpQuery.query.body)
210
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM Animal WHERE `Age` = :Age_w0 AND ( `Color` = :Color_w2 OR `Color` = :Color_w3 ) AND `Description` IS NOT NULL AND `IDOffice` IN ( :IDOffice_w6 ) ORDER BY `Age` LIMIT 100;');
210
+ .to.equal('SELECT `Name`, `Age`, `Cost` FROM Animal WHERE `Age` = :Age_w0 AND ( `Color` = :Color_w2 OR `Color` = :Color_w3 ) AND `Description` IS NOT NULL AND `IDOffice` IN ( :IDOffice_w6_0, :IDOffice_w6_1, :IDOffice_w6_2, :IDOffice_w6_3, :IDOffice_w6_4 ) ORDER BY `Age` LIMIT 100;');
211
211
  }
212
212
  );
213
213
  test
@@ -655,7 +655,7 @@ suite
655
655
  // This is the query generated by the SQLite dialect
656
656
  _Fable.log.trace('Select Query', tmpQuery.query);
657
657
  Expect(tmpQuery.query.body)
658
- .to.equal('SELECT `Name`, `Age`, `Cost` FROM Animal WHERE `Age` = :Age_w0 AND ( `Color` = :Color_w2 OR `Color` = :Color_w3 ) AND `Description` IS NOT NULL AND `IDOffice` IN ( :IDOffice_w6 ) AND `Deleted` = :Deleted_w7 LIMIT 100;');
658
+ .to.equal('SELECT `Name`, `Age`, `Cost` FROM Animal WHERE `Age` = :Age_w0 AND ( `Color` = :Color_w2 OR `Color` = :Color_w3 ) AND `Description` IS NOT NULL AND `IDOffice` IN ( :IDOffice_w6_0, :IDOffice_w6_1, :IDOffice_w6_2, :IDOffice_w6_3, :IDOffice_w6_4 ) AND `Deleted` = :Deleted_w7 LIMIT 100;');
659
659
  }
660
660
  );
661
661
  test