foxhound 1.0.39 → 1.0.42

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": "1.0.39",
3
+ "version": "1.0.42",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -780,7 +780,7 @@ var FoxHoundDialectALASQL = function()
780
780
  try
781
781
  {
782
782
  var tmpQueryTemplate = libUnderscore.template(pParameters.queryOverride);
783
- return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct});
783
+ return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct, _Params: pParameters});
784
784
  }
785
785
  catch (pError)
786
786
  {
@@ -828,7 +828,7 @@ var FoxHoundDialectALASQL = function()
828
828
  {
829
829
  var tmpTableName = generateTableName(pParameters);
830
830
  let tmpDeleteTrackingState = pParameters.query.disableDeleteTracking;
831
- pParameters.query.disableDeleteTracking = false;
831
+ pParameters.query.disableDeleteTracking = true;
832
832
  var tmpWhere = generateWhere(pParameters);
833
833
  var tmpUpdateUndeleteSetters = generateUpdateUndeleteSetters(pParameters);
834
834
  pParameters.query.disableDeleteTracking = tmpDeleteTrackingState;
@@ -861,7 +861,7 @@ var FoxHoundDialectALASQL = function()
861
861
  try
862
862
  {
863
863
  var tmpQueryTemplate = libUnderscore.template(pParameters.queryOverride);
864
- return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct});
864
+ return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct, _Params: pParameters});
865
865
  }
866
866
  catch (pError)
867
867
  {
@@ -113,12 +113,21 @@ var FoxHoundDialectMySQL = function()
113
113
  let pFieldNames = pFieldName.split('.');
114
114
  if (pFieldNames.length > 1)
115
115
  {
116
- return "`" + cleanseQuoting(pFieldNames[0]) + "`.`" + cleanseQuoting(pFieldNames[1]) + "`";
116
+ const cleansedFieldName = cleanseQuoting(pFieldNames[1]);
117
+ if (cleansedFieldName === '*')
118
+ {
119
+ // do not put * as `*`
120
+ return "`" + cleanseQuoting(pFieldNames[0]) + "`.*";
121
+ }
122
+ return "`" + cleanseQuoting(pFieldNames[0]) + "`.`" + cleansedFieldName + "`";
117
123
  }
118
- else
124
+ const cleansedFieldName = cleanseQuoting(pFieldNames[0]);
125
+ if (cleansedFieldName === '*')
119
126
  {
120
- return "`" + cleanseQuoting(pFieldNames[0]) + "`";
127
+ // do not put * as `*`
128
+ return '*';
121
129
  }
130
+ return "`" + cleanseQuoting(pFieldNames[0]) + "`";
122
131
  }
123
132
 
124
133
  /**
@@ -452,7 +461,7 @@ var FoxHoundDialectMySQL = function()
452
461
  }
453
462
  // Check if there is a schema. If so, we will use it to decide if these are parameterized or not.
454
463
  var tmpSchema = Array.isArray(pParameters.query.schema) ? pParameters.query.schema : [];
455
-
464
+
456
465
  var tmpCurrentColumn = 0;
457
466
  var tmpHasDeletedField = false;
458
467
  var tmpUpdate = '';
@@ -463,9 +472,9 @@ var FoxHoundDialectMySQL = function()
463
472
  {
464
473
  // There is a schema entry for it. Process it accordingly.
465
474
  tmpSchemaEntry = tmpSchema[i];
466
-
475
+
467
476
  var tmpUpdateSql = null;
468
-
477
+
469
478
  switch (tmpSchemaEntry.Type)
470
479
  {
471
480
  case 'Deleted':
@@ -491,28 +500,28 @@ var FoxHoundDialectMySQL = function()
491
500
  //DON'T allow update of other fields in this query
492
501
  continue;
493
502
  }
494
-
503
+
495
504
  if (tmpCurrentColumn > 0)
496
505
  {
497
506
  tmpUpdate += ',';
498
507
  }
499
-
508
+
500
509
  tmpUpdate += tmpUpdateSql;
501
-
510
+
502
511
  // We use a number to make sure parameters are unique.
503
512
  tmpCurrentColumn++;
504
513
  }
505
-
514
+
506
515
  // We need to tell the query not to generate improperly if there are no values set.
507
516
  if (!tmpHasDeletedField ||
508
517
  tmpUpdate === '')
509
518
  {
510
519
  return false;
511
520
  }
512
-
521
+
513
522
  return tmpUpdate;
514
523
  };
515
-
524
+
516
525
  /**
517
526
  * Generate the update-undelete SET clause
518
527
  *
@@ -824,7 +833,7 @@ var FoxHoundDialectMySQL = function()
824
833
  try
825
834
  {
826
835
  var tmpQueryTemplate = libUnderscore.template(pParameters.queryOverride);
827
- return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct});
836
+ return tmpQueryTemplate({FieldList:tmpFieldList, TableName:tmpTableName, Where:tmpWhere, Join:tmpJoin, OrderBy:tmpOrderBy, Limit:tmpLimit, Distinct: tmpOptDistinct, _Params: pParameters});
828
837
  }
829
838
  catch (pError)
830
839
  {
@@ -873,7 +882,7 @@ var FoxHoundDialectMySQL = function()
873
882
  var tmpTableName = generateTableName(pParameters);
874
883
  // TODO: Fix these
875
884
  let tmpDeleteTrackingState = pParameters.query.disableDeleteTracking;
876
- pParameters.query.disableDeleteTracking = false;
885
+ pParameters.query.disableDeleteTracking = true;
877
886
  var tmpWhere = generateWhere(pParameters);
878
887
  var tmpUpdateUndeleteSetters = generateUpdateUndeleteSetters(pParameters);
879
888
  pParameters.query.disableDeleteTracking = tmpDeleteTrackingState;
@@ -909,7 +918,7 @@ var FoxHoundDialectMySQL = function()
909
918
  try
910
919
  {
911
920
  var tmpQueryTemplate = libUnderscore.template(pParameters.queryOverride);
912
- return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct});
921
+ return tmpQueryTemplate({FieldList:[], TableName:tmpTableName, Where:tmpWhere, OrderBy:'', Limit:'', Distinct: tmpOptDistinct, _Params: pParameters});
913
922
  }
914
923
  catch (pError)
915
924
  {
@@ -232,6 +232,29 @@ suite
232
232
  }
233
233
  );
234
234
  test
235
+ (
236
+ 'Custom Read Query with Custom Parameters',
237
+ function()
238
+ {
239
+ var tmpQuery = libFoxHound.new(libFable)
240
+ .setDialect('ALASQL')
241
+ .setScope('Animal')
242
+ .setCap(10)
243
+ .setBegin(0)
244
+ .setDataElements(['Name', 'Age', 'Cost'])
245
+ .setSort([{Column:'Age',Direction:'Ascending'},{Column:'Cost',Direction:'Descending'}])
246
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
247
+ tmpQuery.parameters.CustomFields = '`Name`, `Age` * 5, `Cost`';
248
+ tmpQuery.parameters.queryOverride = 'SELECT <%= _Params.CustomFields %> FROM <%= TableName %> <%= Where %> <%= Limit %>;';
249
+ // Build the query
250
+ tmpQuery.buildReadQuery();
251
+ // This is the query generated by the ALASQL dialect
252
+ libFable.log.trace('Custom Select Query', tmpQuery.query);
253
+ Expect(tmpQuery.query.body)
254
+ .to.equal('SELECT `Name`, `Age` * 5, `Cost` FROM Animal WHERE `Age` = :Age_w0 LIMIT 10 FETCH 0;');
255
+ }
256
+ );
257
+ test
235
258
  (
236
259
  'Bad Custom Read Query',
237
260
  function()
@@ -290,6 +313,25 @@ suite
290
313
  }
291
314
  );
292
315
  test
316
+ (
317
+ 'Custom Count Query with Custom Parameters',
318
+ function()
319
+ {
320
+ var tmpQuery = libFoxHound.new(libFable)
321
+ .setDialect('ALASQL')
322
+ .setScope('Animal')
323
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
324
+ tmpQuery.parameters.CountAlias = 'RowCount';
325
+ tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS <%= _Params.CountAlias %> FROM <%= TableName %> <%= Where %>;';
326
+ // Build the query
327
+ tmpQuery.buildCountQuery();
328
+ // This is the query generated by the ALASQL dialect
329
+ libFable.log.trace('Custom Count Query', tmpQuery.query);
330
+ Expect(tmpQuery.query.body)
331
+ .to.equal('SELECT COUNT(*) AS RowCount FROM Animal WHERE `Age` = :Age_w0;');
332
+ }
333
+ );
334
+ test
293
335
  (
294
336
  'Count Query with Field Overrides',
295
337
  function()
@@ -675,7 +717,7 @@ suite
675
717
  // This is the query generated by the ALASQL dialect
676
718
  libFable.log.trace('Undelete Query', tmpQuery.query);
677
719
  Expect(tmpQuery.query.body)
678
- .to.equal('UPDATE Animal SET `UpdateDate` = NOW(), `UpdatingIDUser` = :UpdatingIDUser_1, `Deleted` = 0 WHERE `IDAnimal` = :IDAnimal_w0 AND `Deleted` = :Deleted_w1;');
720
+ .to.equal('UPDATE Animal SET `UpdateDate` = NOW(), `UpdatingIDUser` = :UpdatingIDUser_1, `Deleted` = 0 WHERE `IDAnimal` = :IDAnimal_w0;');
679
721
  }
680
722
  );
681
723
  test
@@ -161,6 +161,28 @@ suite
161
161
  }
162
162
  );
163
163
  test
164
+ (
165
+ 'Complex Read Query with qualified and unqualified "SELECT *" cases',
166
+ function()
167
+ {
168
+ var tmpQuery = libFoxHound.new(libFable)
169
+ .setDialect('MySQL')
170
+ .setScope('Animal')
171
+ .setCap(10)
172
+ .setBegin(0)
173
+ .setDataElements(['*', 'Name', 'Age', 'Cost', 'Animal.*'])
174
+ .setSort([{Column:'Age',Direction:'Ascending'}])
175
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
176
+ tmpQuery.addSort('Cost');
177
+ // Build the query
178
+ tmpQuery.buildReadQuery();
179
+ // This is the query generated by the MySQL dialect
180
+ libFable.log.trace('Select Query', tmpQuery.query);
181
+ Expect(tmpQuery.query.body)
182
+ .to.equal('SELECT *, `Name`, `Age`, `Cost`, `Animal`.* FROM `Animal` WHERE Age = :Age_w0 ORDER BY Age, Cost LIMIT 0, 10;');
183
+ }
184
+ );
185
+ test
164
186
  (
165
187
  'Complex Read Query 2',
166
188
  function()
@@ -209,6 +231,29 @@ suite
209
231
  }
210
232
  );
211
233
  test
234
+ (
235
+ 'Custom Read Query with Custom Parameters',
236
+ function()
237
+ {
238
+ var tmpQuery = libFoxHound.new(libFable)
239
+ .setDialect('MySQL')
240
+ .setScope('Animal')
241
+ .setCap(10)
242
+ .setBegin(0)
243
+ .setDataElements(['Name', 'Age', 'Cost'])
244
+ .setSort([{Column:'Age',Direction:'Ascending'},{Column:'Cost',Direction:'Descending'}])
245
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
246
+ tmpQuery.parameters.CustomFields = 'Name, Age * 5, Cost';
247
+ tmpQuery.parameters.queryOverride = 'SELECT <%= _Params.CustomFields %> FROM <%= TableName %> <%= Where %> <%= Limit %>;';
248
+ // Build the query
249
+ tmpQuery.buildReadQuery();
250
+ // This is the query generated by the MySQL dialect
251
+ libFable.log.trace('Custom Select Query', tmpQuery.query);
252
+ Expect(tmpQuery.query.body)
253
+ .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` WHERE Age = :Age_w0 LIMIT 0, 10;');
254
+ }
255
+ );
256
+ test
212
257
  (
213
258
  'Bad Custom Read Query',
214
259
  function()
@@ -267,6 +312,25 @@ suite
267
312
  }
268
313
  );
269
314
  test
315
+ (
316
+ 'Custom Count Query with Custom Parameters',
317
+ function()
318
+ {
319
+ var tmpQuery = libFoxHound.new(libFable)
320
+ .setDialect('MySQL')
321
+ .setScope('Animal')
322
+ .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
323
+ tmpQuery.parameters.CountAlias = 'RowCount';
324
+ tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS <%= _Params.CountAlias %> FROM <%= TableName %> <%= Where %>;';
325
+ // Build the query
326
+ tmpQuery.buildCountQuery();
327
+ // This is the query generated by the MySQL dialect
328
+ libFable.log.trace('Custom Count Query', tmpQuery.query);
329
+ Expect(tmpQuery.query.body)
330
+ .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` WHERE Age = :Age_w0;');
331
+ }
332
+ );
333
+ test
270
334
  (
271
335
  'Update Query',
272
336
  function()
@@ -789,7 +853,7 @@ suite
789
853
  // This is the query generated by the MySQL dialect
790
854
  libFable.log.trace('Undelete Query', tmpQuery.query);
791
855
  Expect(tmpQuery.query.body)
792
- .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
856
+ .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_1, Deleted = 0 WHERE IDAnimal = :IDAnimal_w0;');
793
857
  }
794
858
  );
795
859
  test