-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathsql.test.js
More file actions
726 lines (654 loc) · 22.9 KB
/
sql.test.js
File metadata and controls
726 lines (654 loc) · 22.9 KB
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
// Copyright IBM Corp. 2015,2019. All Rights Reserved.
// Node module: loopback-connector
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const expect = require('chai').expect;
const SQLConnector = require('../lib/sql');
const ParameterizedSQL = SQLConnector.ParameterizedSQL;
const testConnector = require('./connectors/test-sql-connector');
const juggler = require('loopback-datasource-juggler');
const ds = new juggler.DataSource({
connector: testConnector,
debug: true,
});
/* eslint-disable one-var */
let connector;
let Customer;
let Order;
/* eslint-enable one-var */
describe('sql connector', function() {
before(function() {
connector = ds.connector;
connector._tables = {};
connector._models = {};
Customer = ds.createModel('customer',
{
name: {
id: true,
type: String,
testdb: {
column: 'NAME',
dataType: 'VARCHAR',
dataLength: 32,
},
}, middleName: {
type: String,
name: 'middle_name',
postgresql: {
column: 'MIDDLENAME',
},
}, lastName: {
type: String,
name: 'last_name',
testdb: {
column: 'LASTNAME',
},
}, vip: {
type: Boolean,
testdb: {
column: 'VIP',
},
}, primaryAddress: {
type: String,
name: 'primary_address',
}, token: {
type: String,
name: 'token',
readOnly: true,
testdb: {
column: 'TOKEN',
},
},
address: String,
},
{testdb: {table: 'CUSTOMER'}});
Order = ds.createModel('order',
{
id: {
id: true,
generated: true,
type: Number,
testdb: {
column: 'orderId',
dataType: 'INTEGER',
},
}, des: {
type: String,
name: 'des',
testdb: {
column: 'description',
},
},
},
{testdb: {table: 'ORDER'}});
});
// tests for column names mapping are moved to name-mapping.test.js
it('should map table name', function() {
const table = connector.table('customer');
expect(table).to.eql('CUSTOMER');
});
it('should find column metadata', function() {
const column = connector.columnMetadata('customer', 'name');
expect(column).to.eql({
column: 'NAME',
dataType: 'VARCHAR',
dataLength: 32,
});
});
it('should map property name', function() {
const prop = connector.propertyName('customer', 'NAME');
expect(prop).to.eql('name');
});
it('should find escaped id column name', function() {
const idCol = connector.idColumnEscaped('customer');
expect(idCol).to.eql('`NAME`');
});
it('should find escaped table name', function() {
const table = connector.tableEscaped('customer');
expect(table).to.eql('`CUSTOMER`');
});
it('should find escaped column name', function() {
const column = connector.columnEscaped('customer', 'vip');
expect(column).to.eql('`VIP`');
});
it('should convert to escaped id column value', function() {
const column = connector.idColumnValue('customer', 'John');
expect(column).to.eql('John');
});
it('builds where', function() {
const where = connector.buildWhere('customer', {name: 'John'});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME`=?',
params: ['John'],
});
});
it('builds where with null', function() {
const where = connector.buildWhere('customer', {name: null});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` IS NULL',
params: [],
});
});
it('builds where with inq', function() {
const where = connector.buildWhere('customer', {name: {inq: ['John', 'Mary']}});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` IN (?,?)',
params: ['John', 'Mary'],
});
});
it('builds where with or', function() {
const where = connector.buildWhere('customer',
{or: [{name: 'John'}, {name: 'Mary'}]});
expect(where.toJSON()).to.eql({
sql: 'WHERE ((`NAME`=?) OR (`NAME`=?))',
params: ['John', 'Mary'],
});
});
it('builds where with and', function() {
const where = connector.buildWhere('customer',
{and: [{name: 'John'}, {vip: true}]});
expect(where.toJSON()).to.eql({
sql: 'WHERE ((`NAME`=?) AND (`VIP`=?))',
params: ['John', true],
});
});
it('builds where with a regexp string that does not have flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: '^J',
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: ['^J'],
});
});
it('builds where with a regexp string that has flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: '^J/i',
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: ['^J/i'],
});
});
it('builds where with a regexp literal that does not have flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: /^J/,
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/],
});
});
it('builds where with a regexp literal that has flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: /^J/i,
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/i],
});
});
it('builds where with a regexp object that does not have flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: new RegExp(/^J/),
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [/^J/],
});
});
it('builds where with a regexp object that has flags', function() {
const where = connector.buildWhere('customer', {
name: {
regexp: new RegExp(/^J/i),
},
});
expect(where.toJSON()).to.eql({
sql: 'WHERE `NAME` REGEXP ?',
params: [new RegExp(/^J/i)],
});
});
it('builds where with nesting and/or', function() {
const where = connector.buildWhere('customer',
{and: [{name: 'John'}, {or: [{vip: true}, {address: null}]}]});
expect(where.toJSON()).to.eql({
sql: 'WHERE ((`NAME`=?) AND (((`VIP`=?) OR (`ADDRESS` IS NULL))))',
params: ['John', true],
});
});
it('builds where and ignores invalid clauses in or', function() {
const where = connector.buildWhere('customer', {
name: 'icecream',
or: [{notAColumnName: ''}, {notAColumnNameEither: ''}],
});
expect(where.sql).to.not.match(/ AND $/);
});
it('builds order by with one field', function() {
const orderBy = connector.buildOrderBy('customer', 'name');
expect(orderBy).to.eql('ORDER BY `NAME`');
});
it('builds order by with two fields', function() {
const orderBy = connector.buildOrderBy('customer', ['name', 'vip']);
expect(orderBy).to.eql('ORDER BY `NAME`,`VIP`');
});
it('builds order by with two fields and dirs', function() {
const orderBy = connector.buildOrderBy('customer', ['name ASC', 'vip DESC']);
expect(orderBy).to.eql('ORDER BY `NAME` ASC,`VIP` DESC');
});
it('builds fields for columns', function() {
const fields = connector.buildFields('customer',
{name: 'John', vip: true, unknown: 'Random'});
expect(fields.names).to.eql(['`NAME`', '`VIP`']);
expect(fields.columnValues[0].toJSON()).to.eql(
{sql: '?', params: ['John']},
);
expect(fields.columnValues[1].toJSON()).to.eql(
{sql: '?', params: [true]},
);
});
it('builds fields for UPDATE without readOnlys', function() {
const fields = connector.buildFieldsForReplace('customer', {
middleName: '',
lastName: 'Libert',
vip: true,
token: null,
address: '1031 NW 7th Ave, Fort Lauderdale, Florida, United States',
primaryAddress: '1031 NW 7th Ave, Fort Lauderdale, Florida, United States',
});
expect(fields.toJSON()).to.eql({
sql: 'SET `middle_name`=?,`LASTNAME`=?,`VIP`=?,`primary_address`=?,`ADDRESS`=?',
params: [
'',
'Libert',
true,
'1031 NW 7th Ave, Fort Lauderdale, Florida, United States',
'1031 NW 7th Ave, Fort Lauderdale, Florida, United States',
],
});
});
it('builds fields for UPDATE without ids', function() {
const fields = connector.buildFieldsForUpdate('customer',
{name: 'John', vip: true});
expect(fields.toJSON()).to.eql({
sql: 'SET `VIP`=?',
params: [true],
});
});
it('builds fields for UPDATE with ids', function() {
const fields = connector.buildFieldsForUpdate('customer',
{name: 'John', vip: true}, false);
expect(fields.toJSON()).to.eql({
sql: 'SET `NAME`=?,`VIP`=?',
params: ['John', true],
});
});
it('builds column names for SELECT', function() {
const cols = connector.buildColumnNames('customer');
expect(cols).to.eql('`NAME`,`middle_name`,`LASTNAME`,`VIP`,' +
'`primary_address`,`TOKEN`,`ADDRESS`');
});
it('builds column names with true fields filter for SELECT', function() {
const cols = connector.buildColumnNames('customer', {fields: {name: true}});
expect(cols).to.eql('`NAME`');
});
it('builds column names with false fields filter for SELECT', function() {
const cols = connector.buildColumnNames('customer', {
fields: {
name: false,
primaryAddress: false,
lastName: false,
token: false,
middleName: false,
},
});
expect(cols).to.eql('`VIP`,`ADDRESS`');
});
it('builds column names with array fields filter for SELECT', function() {
const cols = connector.buildColumnNames('customer', {fields: ['name']});
expect(cols).to.eql('`NAME`');
});
it('builds DELETE', function() {
const sql = connector.buildDelete('customer', {name: 'John'});
expect(sql.toJSON()).to.eql({
sql: 'DELETE FROM `CUSTOMER` WHERE `NAME`=$1',
params: ['John'],
});
});
it('builds UPDATE', function() {
const sql = connector.buildUpdate('customer', {name: 'John'}, {vip: false});
expect(sql.toJSON()).to.eql({
sql: 'UPDATE `CUSTOMER` SET `VIP`=$1 WHERE `NAME`=$2',
params: [false, 'John'],
});
});
it('builds SELECT', function() {
const sql = connector.buildSelect('customer', {
order: 'name',
limit: 5,
where: {or: [{name: 'Top Cat'}, {address: 'Trash can'}], vip: true},
});
expect(sql.toJSON()).to.eql({
sql:
'SELECT `NAME`,`middle_name`,`LASTNAME`,`VIP`,`primary_address`,' +
'`TOKEN`,`ADDRESS` FROM `CUSTOMER` WHERE ((`NAME`=$1) OR (`ADDRESS`=$2)) ' +
'AND `VIP`=$3 ORDER BY `NAME` LIMIT 5',
params: ['Top Cat', 'Trash can', true],
});
});
it('builds SELECT with where', function() {
const sql = connector.buildSelect('customer',
{order: 'name', limit: 5, where: {name: 'John'}});
expect(sql.toJSON()).to.eql({
sql: 'SELECT `NAME`,`middle_name`,`LASTNAME`,`VIP`,`primary_address`,`TOKEN`,' +
'`ADDRESS` FROM `CUSTOMER`' +
' WHERE `NAME`=$1 ORDER BY `NAME` LIMIT 5',
params: ['John'],
});
});
it('builds INSERT', function() {
const sql = connector.buildInsert('customer', {name: 'John', vip: true});
expect(sql.toJSON()).to.eql({
sql: 'INSERT INTO `CUSTOMER`(`NAME`,`VIP`) VALUES($1,$2)',
params: ['John', true],
});
});
it('normalizes a SQL statement from string', function() {
const sql = 'SELECT * FROM `CUSTOMER`';
const stmt = new ParameterizedSQL(sql);
expect(stmt.toJSON()).to.eql({sql: sql, params: []});
});
it('normalizes a SQL statement from object without params', function() {
const sql = {sql: 'SELECT * FROM `CUSTOMER`'};
const stmt = new ParameterizedSQL(sql);
expect(stmt.toJSON()).to.eql({sql: sql.sql, params: []});
});
it('normalizes a SQL statement from object with params', function() {
const sql =
{sql: 'SELECT * FROM `CUSTOMER` WHERE `NAME`=?', params: ['John']};
const stmt = new ParameterizedSQL(sql);
expect(stmt.toJSON()).to.eql({sql: sql.sql, params: ['John']});
});
it('should throw if the statement is not a string or object', function() {
expect(function() {
/* jshint unused:false */
const stmt = new ParameterizedSQL(true);
}).to.throw('sql must be a string');
});
it('concats SQL statements', function() {
let stmt1 = {sql: 'SELECT * from `CUSTOMER`'};
const where = {sql: 'WHERE `NAME`=?', params: ['John']};
stmt1 = ParameterizedSQL.append(stmt1, where);
expect(stmt1.toJSON()).to.eql(
{sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John']},
);
});
it('concats string SQL statements', function() {
let stmt1 = 'SELECT * from `CUSTOMER`';
const where = {sql: 'WHERE `NAME`=?', params: ['John']};
stmt1 = ParameterizedSQL.append(stmt1, where);
expect(stmt1.toJSON()).to.eql(
{sql: 'SELECT * from `CUSTOMER` WHERE `NAME`=?', params: ['John']},
);
});
it('should throw if params does not match placeholders', function() {
expect(function() {
let stmt1 = 'SELECT * from `CUSTOMER`';
const where = {sql: 'WHERE `NAME`=?', params: ['John', 'Mary']};
stmt1 = ParameterizedSQL.append(stmt1, where);
}).to.throw('must match the number of params');
});
it('should allow execute(sql, callback)', function(done) {
connector.execute('SELECT * FROM `CUSTOMER`', done);
});
it('should allow execute(sql, params, callback)', function(done) {
connector.execute('SELECT * FROM `CUSTOMER` WHERE `NAME`=$1',
['xyz'], done);
});
it('should allow execute(sql, params, options, callback)', function(done) {
connector.execute('SELECT * FROM `CUSTOMER` WHERE `NAME`=$1',
['xyz'], {transaction: true}, done);
});
it('should throw if params is not an array for execute()', function() {
expect(function() {
connector.execute('SELECT * FROM `CUSTOMER`', 'xyz', function() {
});
}).to.throw('params must be an array');
});
it('should throw if options is not an object for execute()', function() {
expect(function() {
connector.execute('SELECT * FROM `CUSTOMER`', [], 'xyz', function() {
});
}).to.throw('options must be an object');
});
it('should throw if callback is not a function for execute()', function() {
expect(function() {
connector.execute('SELECT * FROM `CUSTOMER`', [], {}, 'xyz');
}).to.throw('callback must be a function');
});
it('should invoke hooks', function(done) {
const events = [];
connector.observe('before execute', function(ctx, next) {
expect(ctx.req.sql).be.a('string');
expect(ctx.req.params).be.a('array');
events.push('before execute');
next();
});
connector.observe('after execute', function(ctx, next) {
expect(ctx.res).be.an('array');
events.push('after execute');
next();
});
Customer.find(function(err, results) {
expect(events).to.eql(['before execute', 'after execute']);
done(err, results);
});
});
it('should throw if the event listener limit is reached', function() {
ds.connected = false;
function runExecute() {
return connector.execute('SELECT * FROM `CUSTOMER`', function(err) {
throw err;
});
}
for (let i = 0; i < 16; i++) {
runExecute();
}
expect(function() { runExecute(); }).to.throw(
'Event listener limit reached. ' +
'Increase maxOfflineRequests value in datasources.json.',
);
ds.connected = true;
ds.removeAllListeners(['connected']);
});
it('should not throw if the event listener limit is not reached', function() {
ds.connected = false;
function runExecute() {
return connector.execute('SELECT * FROM `CUSTOMER`', function(err) {
throw err;
});
}
for (let i = 0; i < 15; i++) {
runExecute();
}
expect(function() { runExecute(); }).to.not.throw();
ds.connected = true;
});
it('should return null for INSERT multiple rows if multiInsertSupported is false',
function() {
connector.multiInsertSupported = false;
const sql = connector.buildInsertAll('customer', [
{name: 'Adam', middleName: 'abc', vip: true},
{name: 'Test', middleName: null, vip: false},
]);
// eslint-disable-next-line no-unused-expressions
expect(sql).to.be.null;
});
it('should return null for INSERT multiple rows if multiInsertSupported not set',
function() {
const sql = connector.buildInsertAll('customer', [
{name: 'Adam', middleName: 'abc', vip: true},
{name: 'Test', middleName: null, vip: false},
]);
// eslint-disable-next-line no-unused-expressions
expect(sql).to.be.null;
});
context('when multiInsertSupported is true', function() {
beforeEach(function() {
connector.multiInsertSupported = true;
});
it('should build INSERT for multiple rows', function() {
connector.multiInsertSupported = true;
const sql = connector.buildInsertAll('customer', [
{name: 'Adam', middleName: 'abc', vip: true},
{name: 'Test', middleName: null, vip: false},
]);
expect(sql.toJSON()).to.eql({
sql:
'INSERT INTO `CUSTOMER`(`NAME`,`middle_name`,`VIP`) VALUES ($1,$2,$3), ($4,$5,$6)',
params: ['Adam', 'abc', true, 'Test', null, false],
});
});
it('should build INSERT for array w/ undefined properties in first row', function() {
connector.multiInsertSupported = true;
const sql = connector.buildInsertAll('customer', [
{name: 'Adam', middleName: 'abc'},
{name: 'Test', middleName: null, vip: false},
]);
expect(sql.toJSON()).to.eql({
sql:
'INSERT INTO `CUSTOMER`(`NAME`,`middle_name`,`VIP`) VALUES ($1,$2,$3), ($4,$5,$6)',
params: ['Adam', 'abc', null, 'Test', null, false],
});
});
context('getInsertedDataArray', function() {
context('when id column is auto-generated', function() {
it('should return back data with id column', function() {
connector.multiInsertSupported = true;
const insertedArr = connector.getInsertedDataArray('order', [1, 2], [
{des: 'Description 1'},
{des: 'Description 2'},
]);
expect(insertedArr).to.eql([
{id: 1, des: 'Description 1'},
{id: 2, des: 'Description 2'},
]);
});
});
context('when id column is not auto-generated', function() {
it('should return back same data', function() {
connector.multiInsertSupported = true;
const insertedArr = connector.getInsertedDataArray('customer', [], [
{name: 'Adam', middleName: 'abc', vip: true},
{name: 'Test', middleName: null, vip: false},
]);
expect(insertedArr).to.eql([
{name: 'Adam', middleName: 'abc', vip: true},
{name: 'Test', middleName: null, vip: false},
]);
});
});
});
});
describe('toColumnValue with column name parameter', function() {
it('should pass escaped column name as fourth parameter', function() {
let capturedColumnName;
const originalToColumnValue = connector.toColumnValue;
// Override toColumnValue to capture the fourth parameter
connector.toColumnValue = function(prop, val, escaping, columnName) {
capturedColumnName = columnName;
return originalToColumnValue.call(this, prop, val, escaping);
};
try {
const fields = connector.buildFields('customer', {
name: 'John',
vip: true,
});
// Verify that the escaped column name was passed
expect(capturedColumnName).to.be.oneOf(['`NAME`', '`VIP`']);
} finally {
// Restore original method
connector.toColumnValue = originalToColumnValue;
}
});
it('should enable partial JSON updates with column-specific logic', function() {
const originalToColumnValue = connector.toColumnValue;
// Mock connector that handles JSON columns differently
connector.toColumnValue = function(prop, val, escaping, columnName) {
// Example: Enable partial JSON update for specific columns
if (columnName === '`ADDRESS`' && typeof val === 'object' && val !== null) {
// For JSON columns, connector can use database-specific JSON update syntax
// e.g., PostgreSQL: column = column || '{"new": "data"}'::jsonb
// This demonstrates how the column name enables column-specific handling
return {
sql: 'jsonb_set(' + columnName + ', ?, ?)',
params: ['{path}', JSON.stringify(val)],
};
}
return originalToColumnValue.call(this, prop, val, escaping);
};
try {
const fields = connector.buildFields('customer', {
address: {city: 'Miami', zip: '33101'},
});
// Verify that column-specific logic was applied
expect(fields.columnValues).to.have.lengthOf(1);
expect(fields.columnValues[0].toJSON()).to.deep.include({
sql: 'jsonb_set(`ADDRESS`, ?, ?)',
});
} finally {
connector.toColumnValue = originalToColumnValue;
}
});
it('should work with buildFieldsForUpdate', function() {
const capturedColumnNames = [];
const originalToColumnValue = connector.toColumnValue;
connector.toColumnValue = function(prop, val, escaping, columnName) {
if (columnName) {
capturedColumnNames.push(columnName);
}
return originalToColumnValue.call(this, prop, val, escaping);
};
try {
connector.buildFieldsForUpdate('customer', {
lastName: 'Doe',
vip: true,
});
// Verify column names were passed for UPDATE operations
expect(capturedColumnNames).to.include.members(['`LASTNAME`', '`VIP`']);
} finally {
connector.toColumnValue = originalToColumnValue;
}
});
it('should work with buildFieldsFromArray for bulk inserts', function() {
const capturedColumnNames = [];
const originalToColumnValue = connector.toColumnValue;
connector.toColumnValue = function(prop, val, escaping, columnName) {
if (columnName && !capturedColumnNames.includes(columnName)) {
capturedColumnNames.push(columnName);
}
return originalToColumnValue.call(this, prop, val, escaping);
};
try {
connector.buildFieldsFromArray('customer', [
{name: 'John', vip: true},
{name: 'Jane', vip: false},
]);
// Verify column names were passed for all rows
expect(capturedColumnNames).to.include.members(['`NAME`', '`VIP`']);
} finally {
connector.toColumnValue = originalToColumnValue;
}
});
});
});