/
query-generator.test.js
1494 lines (1465 loc) · 67.1 KB
/
query-generator.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../../support'),
dialect = Support.getTestDialect(),
_ = require('lodash'),
Op = require('sequelize/lib/operators'),
IndexHints = require('sequelize/lib/index-hints'),
QueryGenerator = require('sequelize/lib/dialects/snowflake/query-generator');
if (dialect === 'snowflake') {
describe('[SNOWFLAKE Specific] QueryGenerator', () => {
const suites = {
createDatabaseQuery: [
{
arguments: ['myDatabase'],
expectation: 'CREATE DATABASE IF NOT EXISTS "myDatabase";'
},
{
arguments: ['myDatabase', { charset: 'utf8mb4' }],
expectation: 'CREATE DATABASE IF NOT EXISTS "myDatabase" DEFAULT CHARACTER SET \'utf8mb4\';'
},
{
arguments: ['myDatabase', { collate: 'utf8mb4_unicode_ci' }],
expectation: 'CREATE DATABASE IF NOT EXISTS "myDatabase" DEFAULT COLLATE \'utf8mb4_unicode_ci\';'
},
{
arguments: ['myDatabase', { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci' }],
expectation: 'CREATE DATABASE IF NOT EXISTS "myDatabase" DEFAULT CHARACTER SET \'utf8mb4\' DEFAULT COLLATE \'utf8mb4_unicode_ci\';'
},
// Variants when quoteIdentifiers is false
{
arguments: ['myDatabase'],
expectation: 'CREATE DATABASE IF NOT EXISTS myDatabase;',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myDatabase', { charset: 'utf8mb4' }],
expectation: 'CREATE DATABASE IF NOT EXISTS myDatabase DEFAULT CHARACTER SET \'utf8mb4\';',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myDatabase', { collate: 'utf8mb4_unicode_ci' }],
expectation: 'CREATE DATABASE IF NOT EXISTS myDatabase DEFAULT COLLATE \'utf8mb4_unicode_ci\';',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myDatabase', { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci' }],
expectation: 'CREATE DATABASE IF NOT EXISTS myDatabase DEFAULT CHARACTER SET \'utf8mb4\' DEFAULT COLLATE \'utf8mb4_unicode_ci\';',
context: { options: { quoteIdentifiers: false } }
}
],
dropDatabaseQuery: [
{
arguments: ['myDatabase'],
expectation: 'DROP DATABASE IF EXISTS "myDatabase";'
},
// Variants when quoteIdentifiers is false
{
arguments: ['myDatabase'],
expectation: 'DROP DATABASE IF EXISTS myDatabase;',
context: { options: { quoteIdentifiers: false } }
}
],
arithmeticQuery: [
{
title: 'Should use the plus operator',
arguments: ['+', 'myTable', {}, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE "myTable" SET "foo"="foo"+ \'bar\''
},
{
title: 'Should use the plus operator with where clause',
arguments: ['+', 'myTable', { bar: 'biz' }, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE "myTable" SET "foo"="foo"+ \'bar\' WHERE "bar" = \'biz\''
},
{
title: 'Should use the minus operator',
arguments: ['-', 'myTable', {}, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE "myTable" SET "foo"="foo"- \'bar\''
},
{
title: 'Should use the minus operator with negative value',
arguments: ['-', 'myTable', {}, { foo: -1 }, {}, {}],
expectation: 'UPDATE "myTable" SET "foo"="foo"- -1'
},
{
title: 'Should use the minus operator with where clause',
arguments: ['-', 'myTable', { bar: 'biz' }, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE "myTable" SET "foo"="foo"- \'bar\' WHERE "bar" = \'biz\''
},
// Variants when quoteIdentifiers is false
{
title: 'Should use the plus operator',
arguments: ['+', 'myTable', {}, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE myTable SET foo=foo+ \'bar\'',
context: { options: { quoteIdentifiers: false } }
},
{
title: 'Should use the plus operator with where clause',
arguments: ['+', 'myTable', { bar: 'biz' }, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE myTable SET foo=foo+ \'bar\' WHERE bar = \'biz\'',
context: { options: { quoteIdentifiers: false } }
},
{
title: 'Should use the minus operator',
arguments: ['-', 'myTable', {}, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE myTable SET foo=foo- \'bar\'',
context: { options: { quoteIdentifiers: false } }
},
{
title: 'Should use the minus operator with negative value',
arguments: ['-', 'myTable', {}, { foo: -1 }, {}, {}],
expectation: 'UPDATE myTable SET foo=foo- -1',
context: { options: { quoteIdentifiers: false } }
},
{
title: 'Should use the minus operator with where clause',
arguments: ['-', 'myTable', { bar: 'biz' }, { foo: 'bar' }, {}, {}],
expectation: 'UPDATE myTable SET foo=foo- \'bar\' WHERE bar = \'biz\'',
context: { options: { quoteIdentifiers: false } }
}
],
attributesToSQL: [
{
arguments: [{ id: 'INTEGER' }],
expectation: { id: 'INTEGER' }
},
{
arguments: [{ id: 'INTEGER', foo: 'VARCHAR(255)' }],
expectation: { id: 'INTEGER', foo: 'VARCHAR(255)' }
},
{
arguments: [{ id: { type: 'INTEGER' } }],
expectation: { id: 'INTEGER' }
},
{
arguments: [{ id: { type: 'INTEGER', allowNull: false } }],
expectation: { id: 'INTEGER NOT NULL' }
},
{
arguments: [{ id: { type: 'INTEGER', allowNull: true } }],
expectation: { id: 'INTEGER' }
},
{
arguments: [{ id: { type: 'INTEGER', primaryKey: true, autoIncrement: true } }],
expectation: { id: 'INTEGER AUTOINCREMENT PRIMARY KEY' }
},
{
arguments: [{ id: { type: 'INTEGER', defaultValue: 0 } }],
expectation: { id: 'INTEGER DEFAULT 0' }
},
{
title: 'Add column level comment',
arguments: [{ id: { type: 'INTEGER', comment: 'Test' } }],
expectation: { id: 'INTEGER COMMENT \'Test\'' }
},
{
arguments: [{ id: { type: 'INTEGER', unique: true } }],
expectation: { id: 'INTEGER UNIQUE' }
},
{
arguments: [{ id: { type: 'INTEGER', after: 'Bar' } }],
expectation: { id: 'INTEGER AFTER "Bar"' }
},
// No Default Values allowed for certain types
{
title: 'No Default value for SNOWFLAKE BLOB allowed',
arguments: [{ id: { type: 'BLOB', defaultValue: [] } }],
expectation: { id: 'BLOB' }
},
{
title: 'No Default value for SNOWFLAKE TEXT allowed',
arguments: [{ id: { type: 'TEXT', defaultValue: [] } }],
expectation: { id: 'TEXT' }
},
{
title: 'No Default value for SNOWFLAKE GEOMETRY allowed',
arguments: [{ id: { type: 'GEOMETRY', defaultValue: [] } }],
expectation: { id: 'GEOMETRY' }
},
{
title: 'No Default value for SNOWFLAKE JSON allowed',
arguments: [{ id: { type: 'JSON', defaultValue: [] } }],
expectation: { id: 'JSON' }
},
// New references style
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' } } }],
expectation: { id: 'INTEGER REFERENCES "Bar" ("id")' }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar', key: 'pk' } } }],
expectation: { id: 'INTEGER REFERENCES "Bar" ("pk")' }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE' } }],
expectation: { id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE' }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT' } }],
expectation: { id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT' }
},
{
arguments: [{ id: { type: 'INTEGER', allowNull: false, autoIncrement: true, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT' } }],
expectation: { id: 'INTEGER NOT NULL AUTOINCREMENT DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT' }
},
// Variants when quoteIdentifiers is false
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' } } }],
expectation: { id: 'INTEGER REFERENCES Bar (id)' },
context: { options: { quoteIdentifiers: false } }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar', key: 'pk' } } }],
expectation: { id: 'INTEGER REFERENCES Bar (pk)' },
context: { options: { quoteIdentifiers: false } }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE' } }],
expectation: { id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE' },
context: { options: { quoteIdentifiers: false } }
},
{
arguments: [{ id: { type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT' } }],
expectation: { id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT' },
context: { options: { quoteIdentifiers: false } }
},
{
arguments: [{ id: { type: 'INTEGER', allowNull: false, autoIncrement: true, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT' } }],
expectation: { id: 'INTEGER NOT NULL AUTOINCREMENT DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT' },
context: { options: { quoteIdentifiers: false } }
}
],
createTableQuery: [
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255));'
},
{
arguments: ['myTable', { data: 'BLOB' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("data" BLOB);'
},
{
arguments: ['myTable', { data: 'LONGBLOB' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("data" LONGBLOB);'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255));'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { charset: 'utf8', collate: 'utf8_unicode_ci' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255)) DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { charset: 'latin1' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255)) DEFAULT CHARSET=latin1;'
},
{
arguments: ['myTable', { title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)' }, { charset: 'latin1' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" ENUM("A", "B", "C"), "name" VARCHAR(255)) DEFAULT CHARSET=latin1;'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { rowFormat: 'default' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255)) ROW_FORMAT=default;'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255), "id" INTEGER , PRIMARY KEY ("id"));'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES "otherTable" ("id") ON DELETE CASCADE ON UPDATE NO ACTION' }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255), "otherId" INTEGER, FOREIGN KEY ("otherId") REFERENCES "otherTable" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);'
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { uniqueKeys: [{ fields: ['title', 'name'], customIndex: true }] }],
expectation: 'CREATE TABLE IF NOT EXISTS "myTable" ("title" VARCHAR(255), "name" VARCHAR(255), UNIQUE "uniq_myTable_title_name" ("title", "name"));'
},
// Variants when quoteIdentifiers is false
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255));',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { data: 'BLOB' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (data BLOB);',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { data: 'LONGBLOB' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (data LONGBLOB);',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255));',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { charset: 'utf8', collate: 'utf8_unicode_ci' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255)) DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { charset: 'latin1' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255)) DEFAULT CHARSET=latin1;',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)' }, { charset: 'latin1' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title ENUM("A", "B", "C"), name VARCHAR(255)) DEFAULT CHARSET=latin1;',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { rowFormat: 'default' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255)) ROW_FORMAT=default;',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), id INTEGER , PRIMARY KEY (id));',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION' }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), otherId INTEGER, FOREIGN KEY (otherId) REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION);',
context: { options: { quoteIdentifiers: false } }
},
{
arguments: ['myTable', { title: 'VARCHAR(255)', name: 'VARCHAR(255)' }, { uniqueKeys: [{ fields: ['title', 'name'], customIndex: true }] }],
expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), UNIQUE uniq_myTable_title_name (title, name));',
context: { options: { quoteIdentifiers: false } }
}
],
dropTableQuery: [
{
arguments: ['myTable'],
expectation: 'DROP TABLE IF EXISTS "myTable";'
},
// Variants when quoteIdentifiers is false
{
arguments: ['myTable'],
expectation: 'DROP TABLE IF EXISTS myTable;',
context: { options: { quoteIdentifiers: false } }
}
],
tableExistsQuery: [
{
arguments: ['myTable'],
expectation: 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = \'BASE TABLE\' AND TABLE_SCHEMA = CURRENT_SCHEMA() AND TABLE_NAME = \'myTable\';',
},
{
arguments: [{ tableName: 'myTable', schema: 'mySchema' }],
expectation: 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = \'BASE TABLE\' AND TABLE_SCHEMA = \'mySchema\' AND TABLE_NAME = \'myTable\';',
},
],
selectQuery: [
{
arguments: ['myTable'],
expectation: 'SELECT * FROM "myTable";',
context: QueryGenerator
}, {
arguments: ['myTable', { attributes: ['id', 'name'] }],
expectation: 'SELECT "id", "name" FROM "myTable";',
context: QueryGenerator
}, {
arguments: ['myTable', { where: { id: 2 } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."id" = 2;',
context: QueryGenerator
}, {
arguments: ['myTable', { where: { name: 'foo' } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."name" = \'foo\';',
context: QueryGenerator
}, {
arguments: ['myTable', { where: { name: "foo';DROP TABLE myTable;" } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."name" = \'foo\'\';DROP TABLE myTable;\';',
context: QueryGenerator
}, {
arguments: ['myTable', { where: 2 }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."id" = 2;',
context: QueryGenerator
}, {
arguments: ['foo', { attributes: [['count(*)', 'count']] }],
expectation: 'SELECT count(*) AS "count" FROM "foo";',
context: QueryGenerator
}, {
arguments: ['myTable', { order: ['id'] }],
expectation: 'SELECT * FROM "myTable" ORDER BY "id";',
context: QueryGenerator
}, {
arguments: ['myTable', { order: ['id', 'DESC'] }],
expectation: 'SELECT * FROM "myTable" ORDER BY "id", "DESC";',
context: QueryGenerator
}, {
arguments: ['myTable', { order: ['myTable.id'] }],
expectation: 'SELECT * FROM "myTable" ORDER BY "myTable"."id";',
context: QueryGenerator
}, {
arguments: ['myTable', { order: [['myTable.id', 'DESC']] }],
expectation: 'SELECT * FROM "myTable" ORDER BY "myTable"."id" DESC;',
context: QueryGenerator
}, {
arguments: ['myTable', { order: [['id', 'DESC']] }, function(sequelize) {return sequelize.define('myTable', {});}],
expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC;',
context: QueryGenerator,
needsSequelize: true
}, {
arguments: ['myTable', { order: [['id', 'DESC'], ['name']] }, function(sequelize) {return sequelize.define('myTable', {});}],
expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC, "myTable"."name";',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'functions can take functions as arguments',
arguments: ['myTable', function(sequelize) {
return {
order: [[sequelize.fn('f1', sequelize.fn('f2', sequelize.col('id'))), 'DESC']]
};
}],
expectation: 'SELECT * FROM "myTable" ORDER BY f1(f2("id")) DESC;',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'functions can take all types as arguments',
arguments: ['myTable', function(sequelize) {
return {
order: [
[sequelize.fn('f1', sequelize.col('myTable.id')), 'DESC'],
[sequelize.fn('f2', 12, 'lalala', new Date(Date.UTC(2011, 2, 27, 10, 1, 55))), 'ASC']
]
};
}],
expectation: 'SELECT * FROM "myTable" ORDER BY f1("myTable"."id") DESC, f2(12, \'lalala\', \'2011-03-27 10:01:55\') ASC;',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'sequelize.where with .fn as attribute and default comparator',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'jan'),
{ type: 1 }
)
};
}],
expectation: 'SELECT * FROM "myTable" WHERE (LOWER("user"."name") = \'jan\' AND "myTable"."type" = 1);',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'sequelize.where with .fn as attribute and LIKE comparator',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'LIKE', '%t%'),
{ type: 1 }
)
};
}],
expectation: 'SELECT * FROM "myTable" WHERE (LOWER("user"."name") LIKE \'%t%\' AND "myTable"."type" = 1);',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'single string argument should be quoted',
arguments: ['myTable', { group: 'name' }],
expectation: 'SELECT * FROM "myTable" GROUP BY "name";',
context: QueryGenerator
}, {
arguments: ['myTable', { group: ['name'] }],
expectation: 'SELECT * FROM "myTable" GROUP BY "name";',
context: QueryGenerator
}, {
title: 'functions work for group by',
arguments: ['myTable', function(sequelize) {
return {
group: [sequelize.fn('YEAR', sequelize.col('createdAt'))]
};
}],
expectation: 'SELECT * FROM "myTable" GROUP BY YEAR("createdAt");',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'It is possible to mix sequelize.fn and string arguments to group by',
arguments: ['myTable', function(sequelize) {
return {
group: [sequelize.fn('YEAR', sequelize.col('createdAt')), 'title']
};
}],
expectation: 'SELECT * FROM "myTable" GROUP BY YEAR("createdAt"), "title";',
context: QueryGenerator,
needsSequelize: true
}, {
arguments: ['myTable', { group: 'name', order: [['id', 'DESC']] }],
expectation: 'SELECT * FROM "myTable" GROUP BY "name" ORDER BY "id" DESC;',
context: QueryGenerator
}, {
title: 'HAVING clause works with where-like hash',
arguments: ['myTable', function(sequelize) {
return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
group: ['creationYear', 'title'],
having: { creationYear: { [Op.gt]: 2002 } }
};
}],
expectation: 'SELECT *, YEAR("createdAt") AS "creationYear" FROM "myTable" GROUP BY "creationYear", "title" HAVING "creationYear" > 2002;',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'Combination of sequelize.fn, sequelize.col and { in: ... }',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
{ archived: null },
sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { [Op.in]: ['Lost', 'Found'] })
)
};
}],
expectation: 'SELECT * FROM "myTable" WHERE ("myTable"."archived" IS NULL AND COALESCE("place_type_codename", "announcement_type_codename") IN (\'Lost\', \'Found\'));',
context: QueryGenerator,
needsSequelize: true
}, {
arguments: ['myTable', { limit: 10 }],
expectation: 'SELECT * FROM "myTable" LIMIT 10;',
context: QueryGenerator
}, {
arguments: ['myTable', { limit: 10, offset: 2 }],
expectation: 'SELECT * FROM "myTable" LIMIT 10 OFFSET 2;',
context: QueryGenerator
}, {
title: 'uses default limit if only offset is specified',
arguments: ['myTable', { offset: 2 }],
expectation: 'SELECT * FROM "myTable" LIMIT NULL OFFSET 2;',
context: QueryGenerator
}, {
title: 'uses limit 0',
arguments: ['myTable', { limit: 0 }],
expectation: 'SELECT * FROM "myTable" LIMIT 0;',
context: QueryGenerator
}, {
title: 'uses offset 0',
arguments: ['myTable', { offset: 0 }],
expectation: 'SELECT * FROM "myTable";',
context: QueryGenerator
}, {
title: 'multiple where arguments',
arguments: ['myTable', { where: { boat: 'canoe', weather: 'cold' } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."boat" = \'canoe\' AND "myTable"."weather" = \'cold\';',
context: QueryGenerator
}, {
title: 'no where arguments (object)',
arguments: ['myTable', { where: {} }],
expectation: 'SELECT * FROM "myTable";',
context: QueryGenerator
}, {
title: 'no where arguments (string)',
arguments: ['myTable', { where: [''] }],
expectation: 'SELECT * FROM "myTable" WHERE 1=1;',
context: QueryGenerator
}, {
title: 'no where arguments (null)',
arguments: ['myTable', { where: null }],
expectation: 'SELECT * FROM "myTable";',
context: QueryGenerator
}, {
title: 'buffer as where argument',
arguments: ['myTable', { where: { field: Buffer.from('Sequelize') } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" = X\'53657175656c697a65\';',
context: QueryGenerator
}, {
title: 'use != if ne !== null',
arguments: ['myTable', { where: { field: { [Op.ne]: 0 } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" != 0;',
context: QueryGenerator
}, {
title: 'use IS NOT if ne === null',
arguments: ['myTable', { where: { field: { [Op.ne]: null } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" IS NOT NULL;',
context: QueryGenerator
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', { where: { field: { [Op.not]: true } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" IS NOT true;',
context: QueryGenerator
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', { where: { field: { [Op.not]: 3 } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" != 3;',
context: QueryGenerator
}, {
title: 'Regular Expression in where clause',
arguments: ['myTable', { where: { field: { [Op.regexp]: '^[h|a|t]' } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" REGEXP \'^[h|a|t]\';',
context: QueryGenerator
}, {
title: 'Regular Expression negation in where clause',
arguments: ['myTable', { where: { field: { [Op.notRegexp]: '^[h|a|t]' } } }],
expectation: 'SELECT * FROM "myTable" WHERE "myTable"."field" NOT REGEXP \'^[h|a|t]\';',
context: QueryGenerator
}, {
title: 'Empty having',
arguments: ['myTable', function() {
return {
having: {}
};
}],
expectation: 'SELECT * FROM "myTable";',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'Having in subquery',
arguments: ['myTable', function() {
return {
subQuery: true,
tableAs: 'test',
having: { creationYear: { [Op.gt]: 2002 } }
};
}],
expectation: 'SELECT "test".* FROM (SELECT * FROM "myTable" AS "test" HAVING "creationYear" > 2002) AS "test";',
context: QueryGenerator,
needsSequelize: true
}, {
title: 'Contains fields with "." characters.',
arguments: ['myTable', {
attributes: ['foo.bar.baz'],
model: {
rawAttributes: {
'foo.bar.baz': {}
}
}
}],
expectation: 'SELECT "foo.bar.baz" FROM "myTable";',
context: QueryGenerator
},
// Variants when quoteIdentifiers is false
{
arguments: ['myTable'],
expectation: 'SELECT * FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { attributes: ['id', 'name'] }],
expectation: 'SELECT id, name FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { where: { id: 2 } }],
expectation: 'SELECT * FROM myTable WHERE myTable.id = 2;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { where: { name: 'foo' } }],
expectation: 'SELECT * FROM myTable WHERE myTable.name = \'foo\';',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { where: { name: "foo';DROP TABLE myTable;" } }],
expectation: 'SELECT * FROM myTable WHERE myTable.name = \'foo\'\';DROP TABLE myTable;\';',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { where: 2 }],
expectation: 'SELECT * FROM myTable WHERE myTable.id = 2;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['foo', { attributes: [['count(*)', 'count']] }],
expectation: 'SELECT count(*) AS count FROM foo;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { order: ['id'] }],
expectation: 'SELECT * FROM myTable ORDER BY id;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { order: ['id', 'DESC'] }],
expectation: 'SELECT * FROM myTable ORDER BY id, DESC;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { order: ['myTable.id'] }],
expectation: 'SELECT * FROM myTable ORDER BY myTable.id;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { order: [['myTable.id', 'DESC']] }],
expectation: 'SELECT * FROM myTable ORDER BY myTable.id DESC;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { order: [['id', 'DESC']] }, function(sequelize) {return sequelize.define('myTable', {});}],
expectation: 'SELECT * FROM myTable AS myTable ORDER BY myTable.id DESC;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
arguments: ['myTable', { order: [['id', 'DESC'], ['name']] }, function(sequelize) {return sequelize.define('myTable', {});}],
expectation: 'SELECT * FROM myTable AS myTable ORDER BY myTable.id DESC, myTable.name;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'functions can take functions as arguments',
arguments: ['myTable', function(sequelize) {
return {
order: [[sequelize.fn('f1', sequelize.fn('f2', sequelize.col('id'))), 'DESC']]
};
}],
expectation: 'SELECT * FROM myTable ORDER BY f1(f2(id)) DESC;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'functions can take all types as arguments',
arguments: ['myTable', function(sequelize) {
return {
order: [
[sequelize.fn('f1', sequelize.col('myTable.id')), 'DESC'],
[sequelize.fn('f2', 12, 'lalala', new Date(Date.UTC(2011, 2, 27, 10, 1, 55))), 'ASC']
]
};
}],
expectation: 'SELECT * FROM myTable ORDER BY f1(myTable.id) DESC, f2(12, \'lalala\', \'2011-03-27 10:01:55\') ASC;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'sequelize.where with .fn as attribute and default comparator',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'jan'),
{ type: 1 }
)
};
}],
expectation: 'SELECT * FROM myTable WHERE (LOWER(user.name) = \'jan\' AND myTable.type = 1);',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'sequelize.where with .fn as attribute and LIKE comparator',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'LIKE', '%t%'),
{ type: 1 }
)
};
}],
expectation: 'SELECT * FROM myTable WHERE (LOWER(user.name) LIKE \'%t%\' AND myTable.type = 1);',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'single string argument should be quoted',
arguments: ['myTable', { group: 'name' }],
expectation: 'SELECT * FROM myTable GROUP BY name;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { group: ['name'] }],
expectation: 'SELECT * FROM myTable GROUP BY name;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'functions work for group by',
arguments: ['myTable', function(sequelize) {
return {
group: [sequelize.fn('YEAR', sequelize.col('createdAt'))]
};
}],
expectation: 'SELECT * FROM myTable GROUP BY YEAR(createdAt);',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'It is possible to mix sequelize.fn and string arguments to group by',
arguments: ['myTable', function(sequelize) {
return {
group: [sequelize.fn('YEAR', sequelize.col('createdAt')), 'title']
};
}],
expectation: 'SELECT * FROM myTable GROUP BY YEAR(createdAt), title;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
arguments: ['myTable', { group: 'name', order: [['id', 'DESC']] }],
expectation: 'SELECT * FROM myTable GROUP BY name ORDER BY id DESC;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'HAVING clause works with where-like hash',
arguments: ['myTable', function(sequelize) {
return {
attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],
group: ['creationYear', 'title'],
having: { creationYear: { [Op.gt]: 2002 } }
};
}],
expectation: 'SELECT *, YEAR(createdAt) AS creationYear FROM myTable GROUP BY creationYear, title HAVING creationYear > 2002;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'Combination of sequelize.fn, sequelize.col and { in: ... }',
arguments: ['myTable', function(sequelize) {
return {
where: sequelize.and(
{ archived: null },
sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { [Op.in]: ['Lost', 'Found'] })
)
};
}],
expectation: 'SELECT * FROM myTable WHERE (myTable.archived IS NULL AND COALESCE(place_type_codename, announcement_type_codename) IN (\'Lost\', \'Found\'));',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
arguments: ['myTable', { limit: 10 }],
expectation: 'SELECT * FROM myTable LIMIT 10;',
context: { options: { quoteIdentifiers: false } }
}, {
arguments: ['myTable', { limit: 10, offset: 2 }],
expectation: 'SELECT * FROM myTable LIMIT 10 OFFSET 2;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'uses default limit if only offset is specified',
arguments: ['myTable', { offset: 2 }],
expectation: 'SELECT * FROM myTable LIMIT NULL OFFSET 2;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'uses limit 0',
arguments: ['myTable', { limit: 0 }],
expectation: 'SELECT * FROM myTable LIMIT 0;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'uses offset 0',
arguments: ['myTable', { offset: 0 }],
expectation: 'SELECT * FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'multiple where arguments',
arguments: ['myTable', { where: { boat: 'canoe', weather: 'cold' } }],
expectation: 'SELECT * FROM myTable WHERE myTable.boat = \'canoe\' AND myTable.weather = \'cold\';',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'no where arguments (object)',
arguments: ['myTable', { where: {} }],
expectation: 'SELECT * FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'no where arguments (string)',
arguments: ['myTable', { where: [''] }],
expectation: 'SELECT * FROM myTable WHERE 1=1;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'no where arguments (null)',
arguments: ['myTable', { where: null }],
expectation: 'SELECT * FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'buffer as where argument',
arguments: ['myTable', { where: { field: Buffer.from('Sequelize') } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field = X\'53657175656c697a65\';',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'use != if ne !== null',
arguments: ['myTable', { where: { field: { [Op.ne]: 0 } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 0;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'use IS NOT if ne === null',
arguments: ['myTable', { where: { field: { [Op.ne]: null } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'use IS NOT if not === BOOLEAN',
arguments: ['myTable', { where: { field: { [Op.not]: true } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'use != if not !== BOOLEAN',
arguments: ['myTable', { where: { field: { [Op.not]: 3 } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'Regular Expression in where clause',
arguments: ['myTable', { where: { field: { [Op.regexp]: '^[h|a|t]' } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field REGEXP \'^[h|a|t]\';',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'Regular Expression negation in where clause',
arguments: ['myTable', { where: { field: { [Op.notRegexp]: '^[h|a|t]' } } }],
expectation: 'SELECT * FROM myTable WHERE myTable.field NOT REGEXP \'^[h|a|t]\';',
context: { options: { quoteIdentifiers: false } }
}, {
title: 'Empty having',
arguments: ['myTable', function() {
return {
having: {}
};
}],
expectation: 'SELECT * FROM myTable;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'Having in subquery',
arguments: ['myTable', function() {
return {
subQuery: true,
tableAs: 'test',
having: { creationYear: { [Op.gt]: 2002 } }
};
}],
expectation: 'SELECT test.* FROM (SELECT * FROM myTable AS test HAVING creationYear > 2002) AS test;',
context: { options: { quoteIdentifiers: false } },
needsSequelize: true
}, {
title: 'Contains fields with "." characters.',
arguments: ['myTable', {
attributes: ['foo.bar.baz'],
model: {
rawAttributes: {
'foo.bar.baz': {}
}
}
}],
expectation: 'SELECT "foo.bar.baz" FROM myTable;',
context: { options: { quoteIdentifiers: false } }
}
],
insertQuery: [
{
arguments: ['myTable', { name: 'foo' }],
expectation: {
query: 'INSERT INTO "myTable" ("name") VALUES ($1);',
bind: ['foo']
}
}, {
arguments: ['myTable', { name: "foo';DROP TABLE myTable;" }],
expectation: {
query: 'INSERT INTO "myTable" ("name") VALUES ($1);',
bind: ["foo';DROP TABLE myTable;"]
}
}, {
arguments: ['myTable', { name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55)) }],
expectation: {
query: 'INSERT INTO "myTable" ("name","birthday") VALUES ($1,$2);',
bind: ['foo', new Date(Date.UTC(2011, 2, 27, 10, 1, 55))]
}
}, {
arguments: ['myTable', { name: 'foo', foo: 1 }],
expectation: {
query: 'INSERT INTO "myTable" ("name","foo") VALUES ($1,$2);',
bind: ['foo', 1]
}
}, {
arguments: ['myTable', { data: Buffer.from('Sequelize') }],
expectation: {
query: 'INSERT INTO "myTable" ("data") VALUES ($1);',
bind: [Buffer.from('Sequelize')]
}
}, {
arguments: ['myTable', { name: 'foo', foo: 1, nullValue: null }],
expectation: {
query: 'INSERT INTO "myTable" ("name","foo","nullValue") VALUES ($1,$2,$3);',
bind: ['foo', 1, null]
}
}, {
arguments: ['myTable', { name: 'foo', foo: 1, nullValue: null }],
expectation: {
query: 'INSERT INTO "myTable" ("name","foo","nullValue") VALUES ($1,$2,$3);',
bind: ['foo', 1, null]
},
context: { options: { omitNull: false } }
}, {
arguments: ['myTable', { name: 'foo', foo: 1, nullValue: null }],
expectation: {
query: 'INSERT INTO "myTable" ("name","foo") VALUES ($1,$2);',
bind: ['foo', 1]
},
context: { options: { omitNull: true } }
}, {
arguments: ['myTable', { name: 'foo', foo: 1, nullValue: undefined }],
expectation: {
query: 'INSERT INTO "myTable" ("name","foo") VALUES ($1,$2);',
bind: ['foo', 1]
},
context: { options: { omitNull: true } }
}, {
arguments: ['myTable', { foo: false }],
expectation: {
query: 'INSERT INTO "myTable" ("foo") VALUES ($1);',
bind: [false]
}
}, {
arguments: ['myTable', { foo: true }],
expectation: {
query: 'INSERT INTO "myTable" ("foo") VALUES ($1);',
bind: [true]
}
}, {
arguments: ['myTable', function(sequelize) {
return {
foo: sequelize.fn('NOW')
};
}],
expectation: {
query: 'INSERT INTO "myTable" ("foo") VALUES (NOW());',
bind: []
},