@openfn/language-mssql 2.6.7 → 2.6.11
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/README.md +92 -19
- package/ast.json +4 -4
- package/lib/Adaptor.js +48 -51
- package/node_modules/@azure/ms-rest-azure-env/package.json +2 -2
- package/node_modules/@azure/ms-rest-js/node_modules/form-data/package.json +2 -2
- package/node_modules/@azure/ms-rest-js/package.json +2 -2
- package/node_modules/@azure/ms-rest-nodeauth/package.json +2 -2
- package/node_modules/@js-joda/core/package.json +2 -2
- package/node_modules/@openfn/language-common/node_modules/axios/package.json +2 -2
- package/node_modules/@openfn/language-common/node_modules/follow-redirects/package.json +2 -2
- package/node_modules/@openfn/language-common/node_modules/jsonpath-plus/package.json +2 -2
- package/node_modules/@openfn/language-common/node_modules/lodash/package.json +2 -2
- package/node_modules/@openfn/language-common/package.json +2 -2
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/tunnel/package.json +2 -2
- package/node_modules/adal-node/node_modules/@types/node/package.json +2 -2
- package/node_modules/adal-node/package.json +2 -2
- package/node_modules/ajv/package.json +2 -2
- package/node_modules/asn1/package.json +2 -2
- package/node_modules/assert-plus/package.json +2 -2
- package/node_modules/async/package.json +2 -2
- package/node_modules/asynckit/package.json +2 -2
- package/node_modules/aws-sign2/package.json +2 -2
- package/node_modules/aws4/package.json +2 -2
- package/node_modules/axios/package.json +2 -2
- package/node_modules/bcrypt-pbkdf/package.json +2 -2
- package/node_modules/bl/node_modules/readable-stream/package.json +2 -2
- package/node_modules/bl/node_modules/string_decoder/package.json +2 -2
- package/node_modules/bl/package.json +2 -2
- package/node_modules/buffer-equal-constant-time/package.json +2 -2
- package/node_modules/caseless/package.json +2 -2
- package/node_modules/combined-stream/package.json +2 -2
- package/node_modules/core-util-is/package.json +2 -2
- package/node_modules/dashdash/package.json +2 -2
- package/node_modules/date-utils/package.json +2 -2
- package/node_modules/delayed-stream/package.json +2 -2
- package/node_modules/depd/package.json +2 -2
- package/node_modules/ecc-jsbn/package.json +2 -2
- package/node_modules/ecdsa-sig-formatter/package.json +2 -2
- package/node_modules/extsprintf/package.json +2 -2
- package/node_modules/fast-deep-equal/package.json +2 -2
- package/node_modules/fast-json-stable-stringify/package.json +2 -2
- package/node_modules/follow-redirects/node_modules/debug/package.json +2 -2
- package/node_modules/follow-redirects/package.json +2 -2
- package/node_modules/forever-agent/package.json +2 -2
- package/node_modules/getpass/package.json +2 -2
- package/node_modules/har-schema/package.json +2 -2
- package/node_modules/har-validator/package.json +2 -2
- package/node_modules/http-signature/package.json +2 -2
- package/node_modules/iconv-lite/package.json +2 -2
- package/node_modules/inherits/package.json +2 -2
- package/node_modules/is-typedarray/package.json +2 -2
- package/node_modules/isstream/package.json +2 -2
- package/node_modules/jsbi/package.json +2 -2
- package/node_modules/jsbn/package.json +2 -2
- package/node_modules/json-schema/package.json +2 -2
- package/node_modules/json-schema-traverse/package.json +2 -2
- package/node_modules/json-stringify-safe/package.json +2 -2
- package/node_modules/jsprim/package.json +2 -2
- package/node_modules/jwa/package.json +2 -2
- package/node_modules/jws/package.json +2 -2
- package/node_modules/mime-db/package.json +2 -2
- package/node_modules/mime-types/package.json +2 -2
- package/node_modules/ms/package.json +2 -2
- package/node_modules/native-duplexpair/package.json +2 -2
- package/node_modules/oauth-sign/package.json +2 -2
- package/node_modules/performance-now/package.json +2 -2
- package/node_modules/psl/package.json +2 -2
- package/node_modules/punycode/package.json +2 -2
- package/node_modules/request/node_modules/extend/package.json +2 -2
- package/node_modules/request/node_modules/form-data/package.json +2 -2
- package/node_modules/request/node_modules/qs/package.json +2 -2
- package/node_modules/request/package.json +2 -2
- package/node_modules/safe-buffer/package.json +2 -2
- package/node_modules/safer-buffer/package.json +2 -2
- package/node_modules/sax/package.json +2 -2
- package/node_modules/sprintf-js/package.json +2 -2
- package/node_modules/sshpk/package.json +5 -5
- package/node_modules/tedious/node_modules/readable-stream/package.json +2 -2
- package/node_modules/tedious/node_modules/string_decoder/package.json +2 -2
- package/node_modules/tedious/package.json +2 -2
- package/node_modules/tough-cookie/node_modules/punycode/package.json +2 -2
- package/node_modules/tough-cookie/package.json +2 -2
- package/node_modules/tslib/package.json +2 -2
- package/node_modules/tunnel/package.json +2 -2
- package/node_modules/tunnel-agent/package.json +2 -2
- package/node_modules/tweetnacl/package.json +2 -2
- package/node_modules/underscore/package.json +2 -2
- package/node_modules/uri-js/package.json +2 -2
- package/node_modules/util-deprecate/package.json +2 -2
- package/node_modules/uuid/package.json +2 -2
- package/node_modules/verror/package.json +2 -2
- package/node_modules/xml2js/package.json +2 -2
- package/node_modules/xmlbuilder/package.json +2 -2
- package/node_modules/xmldom/package.json +2 -2
- package/node_modules/xpath.js/package.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ sql({
|
|
|
45
45
|
This helper function allows to build a specific query where `sql` would not be best suited. It returns a single value and not a promise. An example of usage would be in building a mapping object with a value from a lookup table.
|
|
46
46
|
|
|
47
47
|
```js
|
|
48
|
-
|
|
48
|
+
fn(async state => {
|
|
49
49
|
const user = {
|
|
50
50
|
id: 1,
|
|
51
51
|
name: 'Mamadou',
|
|
@@ -77,6 +77,7 @@ insert(
|
|
|
77
77
|
// to NULL. It can be a single string or an array of strings.
|
|
78
78
|
// It DEFAULTS to "'undefined'", and can be turned off w/ `false`.
|
|
79
79
|
setNull: "'undefined'",
|
|
80
|
+
logValues: true,
|
|
80
81
|
}
|
|
81
82
|
);
|
|
82
83
|
```
|
|
@@ -95,7 +96,7 @@ upsert(
|
|
|
95
96
|
Address: 'Now I can tell!',
|
|
96
97
|
},
|
|
97
98
|
// Do NOT replace any instances of 'undefined' in the final SQL statement.
|
|
98
|
-
{ setNull: false }
|
|
99
|
+
{ setNull: false, logValues: true }
|
|
99
100
|
);
|
|
100
101
|
```
|
|
101
102
|
|
|
@@ -113,7 +114,12 @@ upsertIf(
|
|
|
113
114
|
id: 7,
|
|
114
115
|
},
|
|
115
116
|
// Replace any occurence of '' and 'undefined' to NULL
|
|
116
|
-
{
|
|
117
|
+
{
|
|
118
|
+
setNull: ["''", "'undefined'"],
|
|
119
|
+
writeSql: true,
|
|
120
|
+
execute: false,
|
|
121
|
+
logValues: true,
|
|
122
|
+
}
|
|
117
123
|
);
|
|
118
124
|
```
|
|
119
125
|
|
|
@@ -125,14 +131,17 @@ Pass `logQuery` option to `true` to display the query.
|
|
|
125
131
|
```js
|
|
126
132
|
// Note that insertMany takes a function which returns an array—this helps
|
|
127
133
|
// enforce that each item in the array has the same keys.
|
|
128
|
-
insertMany(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
insertMany(
|
|
135
|
+
'SomeDB.dbo.Supplier',
|
|
136
|
+
state =>
|
|
137
|
+
state.data.supplierArray.map(s => {
|
|
138
|
+
return {
|
|
139
|
+
SupplierNumber: s.id,
|
|
140
|
+
Name: s.name,
|
|
141
|
+
Address: s.address,
|
|
142
|
+
};
|
|
143
|
+
}),
|
|
144
|
+
{ writeSql: true, logValues: true }
|
|
136
145
|
);
|
|
137
146
|
```
|
|
138
147
|
|
|
@@ -143,14 +152,78 @@ This function inserts or updates many records all at once depending on their exi
|
|
|
143
152
|
```js
|
|
144
153
|
// Note that insertMany takes a function which returns an array—this helps
|
|
145
154
|
// enforce that each item in the array has the same keys.
|
|
146
|
-
upsertMany(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
upsertMany(
|
|
156
|
+
'SomeDB.dbo.Supplier',
|
|
157
|
+
'SupplierNumber',
|
|
158
|
+
state =>
|
|
159
|
+
state.data.supplierArray.map(s => {
|
|
160
|
+
return {
|
|
161
|
+
SupplierNumber: s.id,
|
|
162
|
+
Name: s.name,
|
|
163
|
+
Address: s.address,
|
|
164
|
+
};
|
|
165
|
+
}),
|
|
166
|
+
{ writeSql: true, execute: false, logValues: true }
|
|
167
|
+
);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
In case we need to check on multiple columns before upserting, we can have an array of `uuids`.
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
upsertMany(
|
|
174
|
+
'SomeDB.dbo.Supplier',
|
|
175
|
+
['SupplierNumber', 'SupplierCode'],
|
|
176
|
+
state =>
|
|
177
|
+
state.data.supplierArray.map(s => {
|
|
178
|
+
return {
|
|
179
|
+
SupplierNumber: s.id,
|
|
180
|
+
Name: s.name,
|
|
181
|
+
Address: s.address,
|
|
182
|
+
SupplierCode: s.code,
|
|
183
|
+
};
|
|
184
|
+
}),
|
|
185
|
+
{ writeSql: true, execute: false, logValues: true }
|
|
186
|
+
);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Describe a table from mssql
|
|
190
|
+
|
|
191
|
+
This function is used to fetch the list of columns of a given table in the database.
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
describeTable('users', { writeSql: false, execute: true });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Create a table in the database
|
|
198
|
+
|
|
199
|
+
This function allows to create a table in a database from a given array of columns. The key `identity` can be use for a column to auto-generate a value.
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
insertTable('users', state =>
|
|
203
|
+
state.data.map(column => ({
|
|
204
|
+
name: column.name,
|
|
205
|
+
type: column.type,
|
|
206
|
+
required: true, // optional
|
|
207
|
+
unique: false, // optional - set to true for unique constraint
|
|
208
|
+
}))
|
|
209
|
+
);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Alter a table in the database
|
|
213
|
+
|
|
214
|
+
This function allows to add new columns to a table. Beware of the fact that you cannot add new columns with names that already exist in the table.
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
modifyTable(
|
|
218
|
+
'users',
|
|
219
|
+
state =>
|
|
220
|
+
state.data.map(newColumn => ({
|
|
221
|
+
name: newColumn.name,
|
|
222
|
+
type: newColumn.type,
|
|
223
|
+
required: true, // optional
|
|
224
|
+
unique: false, // optional - set to true for unique constraint
|
|
225
|
+
})),
|
|
226
|
+
{ writeSql: false, execute: true }
|
|
154
227
|
);
|
|
155
228
|
```
|
|
156
229
|
|
package/ast.json
CHANGED
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
"title": "example",
|
|
172
|
-
"description": "execute(\n insertMany(table, records, { setNull: false, logValues: false })\n)(state)"
|
|
172
|
+
"description": "execute(\n insertMany(table, records, { setNull: false, writeSql: true, logValues: false })\n)(state)"
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
175
|
"title": "constructor",
|
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
},
|
|
235
235
|
{
|
|
236
236
|
"title": "example",
|
|
237
|
-
"description": "execute(\n upsert(table, uuid, record, { setNull: \"'undefined'\", logValues: false})\n)(state)"
|
|
237
|
+
"description": "execute(\n upsert(table, uuid, record, { setNull: \"'undefined'\", logValues: false})\n)(state)\nexecute(\n upsert(table, [uuid1, uuid2], record, { setNull: \"'undefined'\", logValues: false})\n)(state)"
|
|
238
238
|
},
|
|
239
239
|
{
|
|
240
240
|
"title": "constructor",
|
|
@@ -309,7 +309,7 @@
|
|
|
309
309
|
},
|
|
310
310
|
{
|
|
311
311
|
"title": "example",
|
|
312
|
-
"description": "upsertIf(\n dataValue('name'),\n 'users', // the DB table\n '
|
|
312
|
+
"description": "upsertIf(\n dataValue('name'),\n 'users', // the DB table\n 'uuid', // a DB column with a unique constraint\n { name: 'Elodie', id: 7 },\n { writeSql:true, execute: true, logValues: false }\n)"
|
|
313
313
|
},
|
|
314
314
|
{
|
|
315
315
|
"title": "constructor",
|
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
},
|
|
393
393
|
{
|
|
394
394
|
"title": "example",
|
|
395
|
-
"description": "upsertMany(\n 'users', 'email', records, { logValues: false }\n)"
|
|
395
|
+
"description": "upsertMany(\n 'users', 'email', records, { logValues: false }\n)\nupsertMany(\n 'users', ['email', 'phone'], records, { logValues: false }\n)"
|
|
396
396
|
},
|
|
397
397
|
{
|
|
398
398
|
"title": "constructor",
|
package/lib/Adaptor.js
CHANGED
|
@@ -230,6 +230,7 @@ function addRowsToRefs(state, rows) {
|
|
|
230
230
|
/**
|
|
231
231
|
* Returns a flatten object of the rows (array of arrays) with rowCount.
|
|
232
232
|
* @function
|
|
233
|
+
* @param {State} state
|
|
233
234
|
* @param {array} rows - the array of rows returned from the sql query
|
|
234
235
|
* @returns {State}
|
|
235
236
|
*/
|
|
@@ -264,7 +265,7 @@ function queryHandler(state, query, callback, options) {
|
|
|
264
265
|
|
|
265
266
|
if (options.execute === false) {
|
|
266
267
|
console.log('Not executing query; options.execute === false');
|
|
267
|
-
resolve(
|
|
268
|
+
resolve(state);
|
|
268
269
|
return state;
|
|
269
270
|
}
|
|
270
271
|
}
|
|
@@ -278,11 +279,8 @@ function queryHandler(state, query, callback, options) {
|
|
|
278
279
|
resolve(callback(state, rows));
|
|
279
280
|
}
|
|
280
281
|
});
|
|
281
|
-
|
|
282
|
+
connection.execSql(request);
|
|
282
283
|
});
|
|
283
|
-
/* .then(data => {
|
|
284
|
-
return { ...state, response: { body: data } };
|
|
285
|
-
}); */
|
|
286
284
|
}
|
|
287
285
|
/**
|
|
288
286
|
* Execute an SQL statement
|
|
@@ -447,16 +445,7 @@ function insert(table, record, options) {
|
|
|
447
445
|
return new Promise(function (resolve, reject) {
|
|
448
446
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
449
447
|
console.log("Executing insert via: ".concat(queryToLog));
|
|
450
|
-
|
|
451
|
-
if (err) {
|
|
452
|
-
console.error(err.message);
|
|
453
|
-
throw err;
|
|
454
|
-
} else {
|
|
455
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
456
|
-
resolve(addRowsToRefs(state, rows));
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
connection.execSql(request);
|
|
448
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
460
449
|
});
|
|
461
450
|
} catch (e) {
|
|
462
451
|
connection.close();
|
|
@@ -469,7 +458,7 @@ function insert(table, record, options) {
|
|
|
469
458
|
* @public
|
|
470
459
|
* @example
|
|
471
460
|
* execute(
|
|
472
|
-
* insertMany(table, records, { setNull: false, logValues: false })
|
|
461
|
+
* insertMany(table, records, { setNull: false, writeSql: true, logValues: false })
|
|
473
462
|
* )(state)
|
|
474
463
|
* @constructor
|
|
475
464
|
* @param {string} table - The target table
|
|
@@ -495,16 +484,7 @@ function insertMany(table, records, options) {
|
|
|
495
484
|
return new Promise(function (resolve, reject) {
|
|
496
485
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
497
486
|
console.log("Executing insertMany via: ".concat(queryToLog));
|
|
498
|
-
|
|
499
|
-
if (err) {
|
|
500
|
-
console.error(err.message);
|
|
501
|
-
throw err;
|
|
502
|
-
} else {
|
|
503
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
504
|
-
resolve(addRowsToRefs(state, rows));
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
connection.execSql(request);
|
|
487
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
508
488
|
});
|
|
509
489
|
} catch (e) {
|
|
510
490
|
connection.close();
|
|
@@ -519,6 +499,9 @@ function insertMany(table, records, options) {
|
|
|
519
499
|
* execute(
|
|
520
500
|
* upsert(table, uuid, record, { setNull: "'undefined'", logValues: false})
|
|
521
501
|
* )(state)
|
|
502
|
+
* execute(
|
|
503
|
+
* upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false})
|
|
504
|
+
* )(state)
|
|
522
505
|
* @constructor
|
|
523
506
|
* @param {string} table - The target table
|
|
524
507
|
* @param {string} uuid - The uuid column to determine a matching/existing record
|
|
@@ -545,21 +528,22 @@ function upsert(table, uuid, record, options) {
|
|
|
545
528
|
var insertValues = columns.map(function (key) {
|
|
546
529
|
return "[Source].".concat(key);
|
|
547
530
|
}).join(', ');
|
|
548
|
-
var
|
|
531
|
+
var constraint = [];
|
|
532
|
+
|
|
533
|
+
if (Array.isArray(uuid)) {
|
|
534
|
+
uuid.forEach(function (key) {
|
|
535
|
+
constraint.push("[Target].".concat(key, " = [Source].").concat(key));
|
|
536
|
+
});
|
|
537
|
+
} else {
|
|
538
|
+
constraint.push("[Target].".concat(uuid, " = [Source].").concat(uuid));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
var query = handleValues("MERGE ".concat(table, " AS [Target]\n USING (SELECT ").concat(selectValues, ") AS [Source] \n ON ").concat(constraint.join(' AND '), "\n WHEN MATCHED THEN\n UPDATE SET ").concat(updateValues, " \n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES (").concat(insertValues, ");"), handleOptions(options));
|
|
549
542
|
var safeQuery = "MERGE ".concat(table, " AS [Target]\n USING (SELECT [--REDACTED--]) \n ON [Target].[--VALUE--] = [Source].[--VALUE--]\n WHEN MATCHED THEN\n UPDATE SET [--REDACTED--] \n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES [--REDACTED--];");
|
|
550
543
|
return new Promise(function (resolve, reject) {
|
|
551
544
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
552
545
|
console.log("Executing upsert via: ".concat(queryToLog));
|
|
553
|
-
|
|
554
|
-
if (err) {
|
|
555
|
-
console.error(err.message);
|
|
556
|
-
throw err;
|
|
557
|
-
} else {
|
|
558
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
559
|
-
resolve(addRowsToRefs(state, rows));
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
connection.execSql(request);
|
|
546
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
563
547
|
});
|
|
564
548
|
} catch (e) {
|
|
565
549
|
connection.close();
|
|
@@ -574,7 +558,7 @@ function upsert(table, uuid, record, options) {
|
|
|
574
558
|
* upsertIf(
|
|
575
559
|
* dataValue('name'),
|
|
576
560
|
* 'users', // the DB table
|
|
577
|
-
* '
|
|
561
|
+
* 'uuid', // a DB column with a unique constraint
|
|
578
562
|
* { name: 'Elodie', id: 7 },
|
|
579
563
|
* { writeSql:true, execute: true, logValues: false }
|
|
580
564
|
* )
|
|
@@ -613,20 +597,21 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
613
597
|
var insertValues = columns.map(function (key) {
|
|
614
598
|
return "[Source].".concat(key);
|
|
615
599
|
}).join(', ');
|
|
616
|
-
var
|
|
600
|
+
var constraint = [];
|
|
601
|
+
|
|
602
|
+
if (Array.isArray(uuid)) {
|
|
603
|
+
uuid.forEach(function (key) {
|
|
604
|
+
constraint.push("[Target].".concat(key, " = [Source].").concat(key));
|
|
605
|
+
});
|
|
606
|
+
} else {
|
|
607
|
+
constraint.push("[Target].".concat(uuid, " = [Source].").concat(uuid));
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
var query = handleValues("MERGE ".concat(table, " AS [Target]\n USING (SELECT ").concat(selectValues, ") AS [Source] \n ON ").concat(constraint.join(' AND '), "\n WHEN MATCHED THEN\n UPDATE SET ").concat(updateValues, " \n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES (").concat(insertValues, ");"), handleOptions(options));
|
|
617
611
|
var safeQuery = "MERGE ".concat(table, " AS [Target]\n USING (SELECT [--REDACTED--]) \n ON [Target].[--VALUE--] = [Source].[--VALUE--]\n WHEN MATCHED THEN\n UPDATE SET [--REDACTED--] \n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES [--REDACTED--];");
|
|
618
612
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
619
613
|
console.log("Executing upsertIf via: ".concat(queryToLog));
|
|
620
|
-
|
|
621
|
-
if (err) {
|
|
622
|
-
console.error(err.message);
|
|
623
|
-
throw err;
|
|
624
|
-
} else {
|
|
625
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
626
|
-
resolve(addRowsToRefs(state, rows));
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
connection.execSql(request);
|
|
614
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
630
615
|
});
|
|
631
616
|
} catch (e) {
|
|
632
617
|
connection.close();
|
|
@@ -641,6 +626,9 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
641
626
|
* upsertMany(
|
|
642
627
|
* 'users', 'email', records, { logValues: false }
|
|
643
628
|
* )
|
|
629
|
+
* upsertMany(
|
|
630
|
+
* 'users', ['email', 'phone'], records, { logValues: false }
|
|
631
|
+
* )
|
|
644
632
|
* @constructor
|
|
645
633
|
* @param {string} table - The target table
|
|
646
634
|
* @param {string} uuid - The uuid column to determine a matching/existing record
|
|
@@ -674,12 +662,21 @@ function upsertMany(table, uuid, records, options) {
|
|
|
674
662
|
var updateValues = columns.map(function (key) {
|
|
675
663
|
return "[Target].".concat(key, "=[Source].").concat(key);
|
|
676
664
|
}).join(', ');
|
|
677
|
-
var
|
|
665
|
+
var constraint = [];
|
|
666
|
+
|
|
667
|
+
if (Array.isArray(uuid)) {
|
|
668
|
+
uuid.forEach(function (key) {
|
|
669
|
+
constraint.push("[Target].".concat(key, " = [Source].").concat(key));
|
|
670
|
+
});
|
|
671
|
+
} else {
|
|
672
|
+
constraint.push("[Target].".concat(uuid, " = [Source].").concat(uuid));
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
var query = handleValues("MERGE ".concat(table, " AS [Target]\n USING (VALUES ").concat(valueSets.join(', '), ") AS [Source] (").concat(insertColumns, ")\n ON ").concat(constraint.join(' AND '), "\n WHEN MATCHED THEN\n UPDATE SET ").concat(updateValues, "\n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES (").concat(insertValues, ");"), handleOptions(options));
|
|
678
676
|
var safeQuery = "MERGE ".concat(table, " AS [Target]\n USING (VALUES [--REDACTED--]) AS [SOURCE] (").concat(insertColumns, ")\n ON [Target].[--VALUE--] = [Source].[--VALUE--]\n WHEN MATCHED THEN\n UPDATE SET [--REDACTED--] \n WHEN NOT MATCHED THEN\n INSERT (").concat(insertColumns, ") VALUES [--REDACTED--];");
|
|
679
677
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
680
678
|
console.log("Executing upsertMany via: ".concat(queryToLog));
|
|
681
679
|
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
682
|
-
connection.execSql(request);
|
|
683
680
|
});
|
|
684
681
|
} catch (e) {
|
|
685
682
|
connection.close();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@azure/ms-rest-azure-env@1.1.2",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@azure/ms-rest-azure-env@1.1.2",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-1.1.2.tgz",
|
|
29
29
|
"_spec": "1.1.2",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"author": {
|
|
32
32
|
"name": "Microsoft Corporation",
|
|
33
33
|
"email": "azsdkteam@microsoft.com",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"form-data@2.5.1",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "form-data@2.5.1",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"_resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
|
|
28
28
|
"_spec": "2.5.1",
|
|
29
|
-
"_where": "/
|
|
29
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Felix Geisendörfer",
|
|
32
32
|
"email": "felix@debuggable.com",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@azure/ms-rest-js@1.8.14",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@azure/ms-rest-js@1.8.14",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"_resolved": "https://registry.npmjs.org/@azure/ms-rest-js/-/ms-rest-js-1.8.14.tgz",
|
|
33
33
|
"_spec": "1.8.14",
|
|
34
|
-
"_where": "/
|
|
34
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
35
35
|
"author": {
|
|
36
36
|
"name": "Microsoft Corporation",
|
|
37
37
|
"email": "azsdkteam@microsoft.com",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@azure/ms-rest-nodeauth@2.0.2",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@azure/ms-rest-nodeauth@2.0.2",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@azure/ms-rest-nodeauth/-/ms-rest-nodeauth-2.0.2.tgz",
|
|
29
29
|
"_spec": "2.0.2",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"author": {
|
|
32
32
|
"name": "Microsoft Corporation",
|
|
33
33
|
"email": "azsdkteam@microsoft.com",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@js-joda/core@1.12.0",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@js-joda/core@1.12.0",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@js-joda/core/-/core-1.12.0.tgz",
|
|
29
29
|
"_spec": "1.12.0",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"author": {
|
|
32
32
|
"name": "pithu"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"axios@0.21.1",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "axios@0.21.1",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"_resolved": false,
|
|
27
27
|
"_spec": "0.21.1",
|
|
28
|
-
"_where": "/
|
|
28
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
29
29
|
"author": {
|
|
30
30
|
"name": "Matt Zabriskie"
|
|
31
31
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"follow-redirects@1.13.1",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "follow-redirects@1.13.1",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"_resolved": false,
|
|
27
27
|
"_spec": "1.13.1",
|
|
28
|
-
"_where": "/
|
|
28
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
29
29
|
"author": {
|
|
30
30
|
"name": "Ruben Verborgh",
|
|
31
31
|
"email": "ruben@verborgh.org",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"jsonpath-plus@4.0.0",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "jsonpath-plus@4.0.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"_resolved": false,
|
|
27
27
|
"_spec": "4.0.0",
|
|
28
|
-
"_where": "/
|
|
28
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
29
29
|
"author": {
|
|
30
30
|
"name": "Stefan Goessner"
|
|
31
31
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"lodash@4.17.21",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "lodash@4.17.21",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"_resolved": false,
|
|
27
27
|
"_spec": "4.17.21",
|
|
28
|
-
"_where": "/
|
|
28
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
29
29
|
"author": {
|
|
30
30
|
"name": "John-David Dalton",
|
|
31
31
|
"email": "john.david.dalton@gmail.com"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@openfn/language-common@1.4.1",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@openfn/language-common@1.4.1",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@openfn/language-common/-/language-common-1.4.1.tgz",
|
|
29
29
|
"_spec": "1.4.1",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"author": {
|
|
32
32
|
"name": "Open Function Group"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@types/node@13.5.0",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@types/node@13.5.0",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@types/node/-/node-13.5.0.tgz",
|
|
29
29
|
"_spec": "13.5.0",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@types/tunnel@0.0.0",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@types/tunnel@0.0.0",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@types/tunnel/-/tunnel-0.0.0.tgz",
|
|
29
29
|
"_spec": "0.0.0",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"@types/node@8.10.59",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "@types/node@8.10.59",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"_resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz",
|
|
29
29
|
"_spec": "8.10.59",
|
|
30
|
-
"_where": "/
|
|
30
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"adal-node@0.1.28",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "adal-node@0.1.28",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"_resolved": "https://registry.npmjs.org/adal-node/-/adal-node-0.1.28.tgz",
|
|
28
28
|
"_spec": "0.1.28",
|
|
29
|
-
"_where": "/
|
|
29
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Microsoft Open Technologies Inc",
|
|
32
32
|
"email": "msopentech@microsoft.com",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"_args": [
|
|
3
3
|
[
|
|
4
4
|
"ajv@6.11.0",
|
|
5
|
-
"/
|
|
5
|
+
"/Users/taylor/devtools/adaptors/language-mssql"
|
|
6
6
|
]
|
|
7
7
|
],
|
|
8
8
|
"_from": "ajv@6.11.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"_resolved": "https://registry.npmjs.org/ajv/-/ajv-6.11.0.tgz",
|
|
28
28
|
"_spec": "6.11.0",
|
|
29
|
-
"_where": "/
|
|
29
|
+
"_where": "/Users/taylor/devtools/adaptors/language-mssql",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Evgeny Poberezkin"
|
|
32
32
|
},
|