foxhound 2.0.24 → 2.0.26

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.24",
3
+ "version": "2.0.26",
4
4
  "description": "A Database Query generation library.",
5
5
  "main": "source/FoxHound.js",
6
6
  "scripts": {
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "homepage": "https://github.com/stevenvelozo/foxhound",
50
50
  "devDependencies": {
51
- "quackage": "^1.0.62"
51
+ "quackage": "^1.0.63"
52
52
  },
53
53
  "dependencies": {
54
54
  "fable": "^3.1.63",
@@ -352,12 +352,6 @@ var FoxHoundDialectALASQL = function(pFable)
352
352
  }
353
353
  }
354
354
 
355
- if (pParameters.query.disableAutoDateStamp &&
356
- tmpSchemaEntry.Type === 'UpdateDate')
357
- {
358
- // This is ignored if flag is set
359
- continue;
360
- }
361
355
  if (pParameters.query.disableAutoUserStamp &&
362
356
  tmpSchemaEntry.Type === 'UpdateIDUser')
363
357
  {
@@ -382,8 +376,16 @@ var FoxHoundDialectALASQL = function(pFable)
382
376
  switch (tmpSchemaEntry.Type)
383
377
  {
384
378
  case 'UpdateDate':
385
- // This is an autoidentity, so we don't parameterize it and just pass in NULL
386
- tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = NOW()';
379
+ if (pParameters.query.disableAutoDateStamp)
380
+ {
381
+ var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
382
+ tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = :'+tmpColumnParameter;
383
+ pParameters.query.parameters[tmpColumnParameter] = tmpRecords[0][tmpColumn];
384
+ }
385
+ else
386
+ {
387
+ tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = NOW()';
388
+ }
387
389
  break;
388
390
  case 'UpdateIDUser':
389
391
  // This is the user ID, which we hope is in the query.
@@ -489,11 +489,6 @@ var FoxHoundDialectDGraph = function(pFable)
489
489
  {
490
490
  var tmpSchemaEntry = findSchemaEntry(tmpColumn, tmpSchema);
491
491
 
492
- if (pParameters.query.disableAutoDateStamp &&
493
- tmpSchemaEntry.Type === 'UpdateDate')
494
- {
495
- continue;
496
- }
497
492
  if (pParameters.query.disableAutoUserStamp &&
498
493
  tmpSchemaEntry.Type === 'UpdateIDUser')
499
494
  {
@@ -513,7 +508,14 @@ var FoxHoundDialectDGraph = function(pFable)
513
508
  switch (tmpSchemaEntry.Type)
514
509
  {
515
510
  case 'UpdateDate':
516
- tmpUpdateDoc[tmpColumn] = '$$NOW';
511
+ if (pParameters.query.disableAutoDateStamp)
512
+ {
513
+ tmpUpdateDoc[tmpColumn] = tmpRecords[0][tmpColumn];
514
+ }
515
+ else
516
+ {
517
+ tmpUpdateDoc[tmpColumn] = '$$NOW';
518
+ }
517
519
  break;
518
520
  case 'UpdateIDUser':
519
521
  tmpUpdateDoc[tmpColumn] = pParameters.query.IDUser;
@@ -554,17 +554,19 @@ var FoxHoundDialectMSSQL = function(pFable)
554
554
  break;
555
555
  case 'JSON':
556
556
  var tmpJSONUpdateParam = tmpColumn+'_'+tmpCurrentColumn;
557
- tmpUpdate += ' '+tmpColumn+' = :'+tmpJSONUpdateParam;
557
+ tmpUpdate += ' ['+tmpColumn+'] = @'+tmpJSONUpdateParam;
558
558
  pParameters.query.parameters[tmpJSONUpdateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
559
559
  ? tmpRecords[0][tmpColumn]
560
560
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
561
+ generateMSSQLParameterTypeEntry(pParameters, tmpJSONUpdateParam, {Type:'String'});
561
562
  break;
562
563
  case 'JSONProxy':
563
564
  var tmpProxyUpdateParam = tmpSchemaEntry.StorageColumn+'_'+tmpCurrentColumn;
564
- tmpUpdate += ' '+tmpSchemaEntry.StorageColumn+' = :'+tmpProxyUpdateParam;
565
+ tmpUpdate += ' ['+tmpSchemaEntry.StorageColumn+'] = @'+tmpProxyUpdateParam;
565
566
  pParameters.query.parameters[tmpProxyUpdateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
566
567
  ? tmpRecords[0][tmpColumn]
567
568
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
569
+ generateMSSQLParameterTypeEntry(pParameters, tmpProxyUpdateParam, {Type:'String'});
568
570
  break;
569
571
  default:
570
572
  var tmpColumnDefaultParameter = tmpColumn+'_'+tmpCurrentColumn;
@@ -867,17 +869,19 @@ var FoxHoundDialectMSSQL = function(pFable)
867
869
  break;
868
870
  case 'JSON':
869
871
  var tmpJSONCreateParam = tmpColumn+'_'+tmpCurrentColumn;
870
- tmpCreateSet += ' :'+tmpJSONCreateParam;
872
+ tmpCreateSet += ' @'+tmpJSONCreateParam;
871
873
  pParameters.query.parameters[tmpJSONCreateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
872
874
  ? tmpRecords[0][tmpColumn]
873
875
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
876
+ generateMSSQLParameterTypeEntry(pParameters, tmpJSONCreateParam, {Type:'String'});
874
877
  break;
875
878
  case 'JSONProxy':
876
879
  var tmpProxyCreateParam = tmpColumn+'_'+tmpCurrentColumn;
877
- tmpCreateSet += ' :'+tmpProxyCreateParam;
880
+ tmpCreateSet += ' @'+tmpProxyCreateParam;
878
881
  pParameters.query.parameters[tmpProxyCreateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
879
882
  ? tmpRecords[0][tmpColumn]
880
883
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
884
+ generateMSSQLParameterTypeEntry(pParameters, tmpProxyCreateParam, {Type:'String'});
881
885
  break;
882
886
  default:
883
887
  buildDefaultDefinition();
@@ -955,14 +959,14 @@ var FoxHoundDialectMSSQL = function(pFable)
955
959
  {
956
960
  tmpCreateSet += ',';
957
961
  }
958
- tmpCreateSet += ' '+tmpColumn;
962
+ tmpCreateSet += ' ['+tmpColumn+']';
959
963
  break;
960
964
  case 'JSONProxy':
961
965
  if (tmpCreateSet != '')
962
966
  {
963
967
  tmpCreateSet += ',';
964
968
  }
965
- tmpCreateSet += ' '+tmpSchemaEntry.StorageColumn;
969
+ tmpCreateSet += ' ['+tmpSchemaEntry.StorageColumn+']';
966
970
  break;
967
971
  default:
968
972
  if (tmpCreateSet != '')
@@ -492,11 +492,6 @@ var FoxHoundDialectMongoDB = function(pFable)
492
492
  {
493
493
  var tmpSchemaEntry = findSchemaEntry(tmpColumn, tmpSchema);
494
494
 
495
- if (pParameters.query.disableAutoDateStamp &&
496
- tmpSchemaEntry.Type === 'UpdateDate')
497
- {
498
- continue;
499
- }
500
495
  if (pParameters.query.disableAutoUserStamp &&
501
496
  tmpSchemaEntry.Type === 'UpdateIDUser')
502
497
  {
@@ -516,7 +511,14 @@ var FoxHoundDialectMongoDB = function(pFable)
516
511
  switch (tmpSchemaEntry.Type)
517
512
  {
518
513
  case 'UpdateDate':
519
- tmpUpdateDoc[tmpColumn] = '$$NOW';
514
+ if (pParameters.query.disableAutoDateStamp)
515
+ {
516
+ tmpUpdateDoc[tmpColumn] = tmpRecords[0][tmpColumn];
517
+ }
518
+ else
519
+ {
520
+ tmpUpdateDoc[tmpColumn] = '$$NOW';
521
+ }
520
522
  break;
521
523
  case 'UpdateIDUser':
522
524
  tmpUpdateDoc[tmpColumn] = pParameters.query.IDUser;
@@ -434,12 +434,6 @@ var FoxHoundDialectMySQL = function(pFable)
434
434
  }
435
435
  }
436
436
 
437
- if (pParameters.query.disableAutoDateStamp &&
438
- tmpSchemaEntry.Type === 'UpdateDate')
439
- {
440
- // This is ignored if flag is set
441
- continue;
442
- }
443
437
  if (pParameters.query.disableAutoUserStamp &&
444
438
  tmpSchemaEntry.Type === 'UpdateIDUser')
445
439
  {
@@ -464,8 +458,17 @@ var FoxHoundDialectMySQL = function(pFable)
464
458
  switch (tmpSchemaEntry.Type)
465
459
  {
466
460
  case 'UpdateDate':
467
- // This is an autoidentity, so we don't parameterize it and just pass in NULL
468
- tmpUpdate += ' '+tmpColumn+' = ' + SQL_NOW;
461
+ if (pParameters.query.disableAutoDateStamp)
462
+ {
463
+ // Manual mode: use the record's value as-is
464
+ var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
465
+ tmpUpdate += ' '+tmpColumn+' = :'+tmpColumnParameter;
466
+ pParameters.query.parameters[tmpColumnParameter] = tmpRecords[0][tmpColumn];
467
+ }
468
+ else
469
+ {
470
+ tmpUpdate += ' '+tmpColumn+' = ' + SQL_NOW;
471
+ }
469
472
  break;
470
473
  case 'UpdateIDUser':
471
474
  // This is the user ID, which we hope is in the query.
@@ -398,11 +398,6 @@ var FoxHoundDialectPostgreSQL = function(pFable)
398
398
  }
399
399
  }
400
400
 
401
- if (pParameters.query.disableAutoDateStamp &&
402
- tmpSchemaEntry.Type === 'UpdateDate')
403
- {
404
- continue;
405
- }
406
401
  if (pParameters.query.disableAutoUserStamp &&
407
402
  tmpSchemaEntry.Type === 'UpdateIDUser')
408
403
  {
@@ -425,7 +420,16 @@ var FoxHoundDialectPostgreSQL = function(pFable)
425
420
  switch (tmpSchemaEntry.Type)
426
421
  {
427
422
  case 'UpdateDate':
428
- tmpUpdate += ' '+generateSafeFieldName(tmpColumn)+' = ' + SQL_NOW;
423
+ if (pParameters.query.disableAutoDateStamp)
424
+ {
425
+ var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
426
+ tmpUpdate += ' '+generateSafeFieldName(tmpColumn)+' = :'+tmpColumnParameter;
427
+ pParameters.query.parameters[tmpColumnParameter] = tmpRecords[0][tmpColumn];
428
+ }
429
+ else
430
+ {
431
+ tmpUpdate += ' '+generateSafeFieldName(tmpColumn)+' = ' + SQL_NOW;
432
+ }
429
433
  break;
430
434
  case 'UpdateIDUser':
431
435
  var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
@@ -434,14 +438,14 @@ var FoxHoundDialectPostgreSQL = function(pFable)
434
438
  break;
435
439
  case 'JSON':
436
440
  var tmpJSONUpdateParam = tmpColumn+'_'+tmpCurrentColumn;
437
- tmpUpdate += ' '+tmpColumn+' = :'+tmpJSONUpdateParam;
441
+ tmpUpdate += ' '+generateSafeFieldName(tmpColumn)+' = :'+tmpJSONUpdateParam;
438
442
  pParameters.query.parameters[tmpJSONUpdateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
439
443
  ? tmpRecords[0][tmpColumn]
440
444
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
441
445
  break;
442
446
  case 'JSONProxy':
443
447
  var tmpProxyUpdateParam = tmpSchemaEntry.StorageColumn+'_'+tmpCurrentColumn;
444
- tmpUpdate += ' '+tmpSchemaEntry.StorageColumn+' = :'+tmpProxyUpdateParam;
448
+ tmpUpdate += ' '+generateSafeFieldName(tmpSchemaEntry.StorageColumn)+' = :'+tmpProxyUpdateParam;
445
449
  pParameters.query.parameters[tmpProxyUpdateParam] = (typeof tmpRecords[0][tmpColumn] === 'string')
446
450
  ? tmpRecords[0][tmpColumn]
447
451
  : JSON.stringify(tmpRecords[0][tmpColumn] || {});
@@ -768,14 +772,14 @@ var FoxHoundDialectPostgreSQL = function(pFable)
768
772
  {
769
773
  tmpCreateSet += ',';
770
774
  }
771
- tmpCreateSet += ' '+tmpColumn;
775
+ tmpCreateSet += ' '+generateSafeFieldName(tmpColumn);
772
776
  break;
773
777
  case 'JSONProxy':
774
778
  if (tmpCreateSet != '')
775
779
  {
776
780
  tmpCreateSet += ',';
777
781
  }
778
- tmpCreateSet += ' '+tmpSchemaEntry.StorageColumn;
782
+ tmpCreateSet += ' '+generateSafeFieldName(tmpSchemaEntry.StorageColumn);
779
783
  break;
780
784
  default:
781
785
  if (tmpCreateSet != '')
@@ -380,12 +380,6 @@ var FoxHoundDialectSQLite = function(pFable)
380
380
  }
381
381
  }
382
382
 
383
- if (pParameters.query.disableAutoDateStamp &&
384
- tmpSchemaEntry.Type === 'UpdateDate')
385
- {
386
- // This is ignored if flag is set
387
- continue;
388
- }
389
383
  if (pParameters.query.disableAutoUserStamp &&
390
384
  tmpSchemaEntry.Type === 'UpdateIDUser')
391
385
  {
@@ -410,8 +404,17 @@ var FoxHoundDialectSQLite = function(pFable)
410
404
  switch (tmpSchemaEntry.Type)
411
405
  {
412
406
  case 'UpdateDate':
413
- // This is an autoidentity, so we don't parameterize it and just pass in NULL
414
- tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = NOW()';
407
+ if (pParameters.query.disableAutoDateStamp)
408
+ {
409
+ // Manual mode: use the record's value as-is
410
+ var tmpColumnParameter = tmpColumn+'_'+tmpCurrentColumn;
411
+ tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = :'+tmpColumnParameter;
412
+ pParameters.query.parameters[tmpColumnParameter] = tmpRecords[0][tmpColumn];
413
+ }
414
+ else
415
+ {
416
+ tmpUpdate += ' '+escapeColumn(tmpColumn, pParameters)+' = NOW()';
417
+ }
415
418
  break;
416
419
  case 'UpdateIDUser':
417
420
  // This is the user ID, which we hope is in the query.
@@ -461,11 +461,6 @@ var FoxHoundDialectSolr = function(pFable)
461
461
  {
462
462
  var tmpSchemaEntry = findSchemaEntry(tmpColumn, tmpSchema);
463
463
 
464
- if (pParameters.query.disableAutoDateStamp &&
465
- tmpSchemaEntry.Type === 'UpdateDate')
466
- {
467
- continue;
468
- }
469
464
  if (pParameters.query.disableAutoUserStamp &&
470
465
  tmpSchemaEntry.Type === 'UpdateIDUser')
471
466
  {
@@ -485,7 +480,14 @@ var FoxHoundDialectSolr = function(pFable)
485
480
  switch (tmpSchemaEntry.Type)
486
481
  {
487
482
  case 'UpdateDate':
488
- tmpUpdateDoc[tmpColumn] = { 'set': '$$NOW' };
483
+ if (pParameters.query.disableAutoDateStamp)
484
+ {
485
+ tmpUpdateDoc[tmpColumn] = { 'set': tmpRecords[0][tmpColumn] };
486
+ }
487
+ else
488
+ {
489
+ tmpUpdateDoc[tmpColumn] = { 'set': '$$NOW' };
490
+ }
489
491
  break;
490
492
  case 'UpdateIDUser':
491
493
  tmpUpdateDoc[tmpColumn] = { 'set': pParameters.query.IDUser };
@@ -792,8 +792,10 @@ suite
792
792
  tmpQuery.buildUpdateQuery();
793
793
  // This is the query generated by the ALASQL dialect
794
794
  _Fable.log.trace('Update Query', tmpQuery.query);
795
+ // When disableAutoDateStamp is true, UpdateDate is included with the
796
+ // record's value instead of being auto-stamped with NOW()
795
797
  Expect(tmpQuery.query.body)
796
- .to.equal('UPDATE Animal SET `GUIDAnimal` = :GUIDAnimal_0, `Name` = :Name_1, `Age` = :Age_2 WHERE `IDAnimal` = :IDAnimal_w0;');
798
+ .to.equal('UPDATE Animal SET `GUIDAnimal` = :GUIDAnimal_0, `UpdateDate` = :UpdateDate_1, `Name` = :Name_2, `Age` = :Age_3 WHERE `IDAnimal` = :IDAnimal_w0;');
797
799
  }
798
800
  );
799
801
  test
@@ -752,8 +752,10 @@ suite
752
752
  tmpQuery.buildUpdateQuery();
753
753
  // This is the query generated by the MySQL dialect
754
754
  _Fable.log.trace('Update Query', tmpQuery.query);
755
+ // When disableAutoDateStamp is true, UpdateDate is included with the
756
+ // record's value instead of being auto-stamped with NOW()
755
757
  Expect(tmpQuery.query.body)
756
- .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, Name = :Name_1, Age = :Age_2 WHERE IDAnimal = :IDAnimal_w0;');
758
+ .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, UpdateDate = :UpdateDate_1, Name = :Name_2, Age = :Age_3 WHERE IDAnimal = :IDAnimal_w0;');
757
759
  }
758
760
  );
759
761
  test
@@ -792,8 +792,10 @@ suite
792
792
  tmpQuery.buildUpdateQuery();
793
793
  // This is the query generated by the SQLite dialect
794
794
  _Fable.log.trace('Update Query', tmpQuery.query);
795
+ // When disableAutoDateStamp is true, UpdateDate is included with the
796
+ // record's value instead of being auto-stamped with NOW()
795
797
  Expect(tmpQuery.query.body)
796
- .to.equal('UPDATE Animal SET `GUIDAnimal` = :GUIDAnimal_0, `Name` = :Name_1, `Age` = :Age_2 WHERE `IDAnimal` = :IDAnimal_w0;');
798
+ .to.equal('UPDATE Animal SET `GUIDAnimal` = :GUIDAnimal_0, `UpdateDate` = :UpdateDate_1, `Name` = :Name_2, `Age` = :Age_3 WHERE `IDAnimal` = :IDAnimal_w0;');
797
799
  }
798
800
  );
799
801
  test