@openfn/language-mssql 2.6.6 → 2.6.10
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 +62 -71
- 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,25 +230,31 @@ 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
|
*/
|
|
236
237
|
|
|
237
238
|
|
|
238
|
-
function flattenRows(rows) {
|
|
239
|
+
function flattenRows(state, rows) {
|
|
239
240
|
var obj = [];
|
|
240
241
|
rows.forEach(function (row) {
|
|
241
242
|
return obj.push({
|
|
242
243
|
column_name: row[0].value
|
|
243
244
|
});
|
|
244
245
|
});
|
|
245
|
-
|
|
246
|
+
var data = {
|
|
246
247
|
rowCount: rows.length,
|
|
247
248
|
rows: obj
|
|
248
249
|
};
|
|
250
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
251
|
+
response: {
|
|
252
|
+
body: data
|
|
253
|
+
}
|
|
254
|
+
});
|
|
249
255
|
}
|
|
250
256
|
|
|
251
|
-
function queryHandler(state, query, options) {
|
|
257
|
+
function queryHandler(state, query, callback, options) {
|
|
252
258
|
var connection = state.connection;
|
|
253
259
|
return new Promise(function (resolve, reject) {
|
|
254
260
|
if (options) {
|
|
@@ -259,7 +265,7 @@ function queryHandler(state, query, options) {
|
|
|
259
265
|
|
|
260
266
|
if (options.execute === false) {
|
|
261
267
|
console.log('Not executing query; options.execute === false');
|
|
262
|
-
resolve(
|
|
268
|
+
resolve(state);
|
|
263
269
|
return state;
|
|
264
270
|
}
|
|
265
271
|
}
|
|
@@ -270,16 +276,10 @@ function queryHandler(state, query, options) {
|
|
|
270
276
|
throw err;
|
|
271
277
|
} else {
|
|
272
278
|
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
273
|
-
resolve(
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
if (!options || options.execute) connection.execSql(request);
|
|
277
|
-
}).then(function (data) {
|
|
278
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
279
|
-
response: {
|
|
280
|
-
body: data
|
|
279
|
+
resolve(callback(state, rows));
|
|
281
280
|
}
|
|
282
281
|
});
|
|
282
|
+
connection.execSql(request);
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
@@ -305,7 +305,7 @@ function sql(params) {
|
|
|
305
305
|
options = _expandReferences.options;
|
|
306
306
|
|
|
307
307
|
console.log("Preparing to execute sql statement: ".concat(query));
|
|
308
|
-
return queryHandler(state, query, options);
|
|
308
|
+
return queryHandler(state, query, flattenRows, options);
|
|
309
309
|
} catch (e) {
|
|
310
310
|
connection.close();
|
|
311
311
|
throw e;
|
|
@@ -445,16 +445,7 @@ function insert(table, record, options) {
|
|
|
445
445
|
return new Promise(function (resolve, reject) {
|
|
446
446
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
447
447
|
console.log("Executing insert via: ".concat(queryToLog));
|
|
448
|
-
|
|
449
|
-
if (err) {
|
|
450
|
-
console.error(err.message);
|
|
451
|
-
throw err;
|
|
452
|
-
} else {
|
|
453
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
454
|
-
resolve(addRowsToRefs(state, rows));
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
connection.execSql(request);
|
|
448
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
458
449
|
});
|
|
459
450
|
} catch (e) {
|
|
460
451
|
connection.close();
|
|
@@ -467,7 +458,7 @@ function insert(table, record, options) {
|
|
|
467
458
|
* @public
|
|
468
459
|
* @example
|
|
469
460
|
* execute(
|
|
470
|
-
* insertMany(table, records, { setNull: false, logValues: false })
|
|
461
|
+
* insertMany(table, records, { setNull: false, writeSql: true, logValues: false })
|
|
471
462
|
* )(state)
|
|
472
463
|
* @constructor
|
|
473
464
|
* @param {string} table - The target table
|
|
@@ -493,16 +484,7 @@ function insertMany(table, records, options) {
|
|
|
493
484
|
return new Promise(function (resolve, reject) {
|
|
494
485
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
495
486
|
console.log("Executing insertMany via: ".concat(queryToLog));
|
|
496
|
-
|
|
497
|
-
if (err) {
|
|
498
|
-
console.error(err.message);
|
|
499
|
-
throw err;
|
|
500
|
-
} else {
|
|
501
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
502
|
-
resolve(addRowsToRefs(state, rows));
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
connection.execSql(request);
|
|
487
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
506
488
|
});
|
|
507
489
|
} catch (e) {
|
|
508
490
|
connection.close();
|
|
@@ -517,6 +499,9 @@ function insertMany(table, records, options) {
|
|
|
517
499
|
* execute(
|
|
518
500
|
* upsert(table, uuid, record, { setNull: "'undefined'", logValues: false})
|
|
519
501
|
* )(state)
|
|
502
|
+
* execute(
|
|
503
|
+
* upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false})
|
|
504
|
+
* )(state)
|
|
520
505
|
* @constructor
|
|
521
506
|
* @param {string} table - The target table
|
|
522
507
|
* @param {string} uuid - The uuid column to determine a matching/existing record
|
|
@@ -543,21 +528,22 @@ function upsert(table, uuid, record, options) {
|
|
|
543
528
|
var insertValues = columns.map(function (key) {
|
|
544
529
|
return "[Source].".concat(key);
|
|
545
530
|
}).join(', ');
|
|
546
|
-
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));
|
|
547
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--];");
|
|
548
543
|
return new Promise(function (resolve, reject) {
|
|
549
544
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
550
545
|
console.log("Executing upsert via: ".concat(queryToLog));
|
|
551
|
-
|
|
552
|
-
if (err) {
|
|
553
|
-
console.error(err.message);
|
|
554
|
-
throw err;
|
|
555
|
-
} else {
|
|
556
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
557
|
-
resolve(addRowsToRefs(state, rows));
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
connection.execSql(request);
|
|
546
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
561
547
|
});
|
|
562
548
|
} catch (e) {
|
|
563
549
|
connection.close();
|
|
@@ -572,7 +558,7 @@ function upsert(table, uuid, record, options) {
|
|
|
572
558
|
* upsertIf(
|
|
573
559
|
* dataValue('name'),
|
|
574
560
|
* 'users', // the DB table
|
|
575
|
-
* '
|
|
561
|
+
* 'uuid', // a DB column with a unique constraint
|
|
576
562
|
* { name: 'Elodie', id: 7 },
|
|
577
563
|
* { writeSql:true, execute: true, logValues: false }
|
|
578
564
|
* )
|
|
@@ -611,20 +597,21 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
611
597
|
var insertValues = columns.map(function (key) {
|
|
612
598
|
return "[Source].".concat(key);
|
|
613
599
|
}).join(', ');
|
|
614
|
-
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));
|
|
615
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--];");
|
|
616
612
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
617
613
|
console.log("Executing upsertIf via: ".concat(queryToLog));
|
|
618
|
-
|
|
619
|
-
if (err) {
|
|
620
|
-
console.error(err.message);
|
|
621
|
-
throw err;
|
|
622
|
-
} else {
|
|
623
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
624
|
-
resolve(addRowsToRefs(state, rows));
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
connection.execSql(request);
|
|
614
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
628
615
|
});
|
|
629
616
|
} catch (e) {
|
|
630
617
|
connection.close();
|
|
@@ -639,6 +626,9 @@ function upsertIf(logical, table, uuid, record, options) {
|
|
|
639
626
|
* upsertMany(
|
|
640
627
|
* 'users', 'email', records, { logValues: false }
|
|
641
628
|
* )
|
|
629
|
+
* upsertMany(
|
|
630
|
+
* 'users', ['email', 'phone'], records, { logValues: false }
|
|
631
|
+
* )
|
|
642
632
|
* @constructor
|
|
643
633
|
* @param {string} table - The target table
|
|
644
634
|
* @param {string} uuid - The uuid column to determine a matching/existing record
|
|
@@ -672,20 +662,21 @@ function upsertMany(table, uuid, records, options) {
|
|
|
672
662
|
var updateValues = columns.map(function (key) {
|
|
673
663
|
return "[Target].".concat(key, "=[Source].").concat(key);
|
|
674
664
|
}).join(', ');
|
|
675
|
-
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));
|
|
676
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--];");
|
|
677
677
|
var queryToLog = options && options.logValues ? query : safeQuery;
|
|
678
678
|
console.log("Executing upsertMany via: ".concat(queryToLog));
|
|
679
|
-
|
|
680
|
-
if (err) {
|
|
681
|
-
console.error(err.message);
|
|
682
|
-
throw err;
|
|
683
|
-
} else {
|
|
684
|
-
console.log("Finished: ".concat(rowCount, " row(s)."));
|
|
685
|
-
resolve(addRowsToRefs(state, rows));
|
|
686
|
-
}
|
|
687
|
-
});
|
|
688
|
-
connection.execSql(request);
|
|
679
|
+
resolve(queryHandler(state, query, addRowsToRefs, options));
|
|
689
680
|
});
|
|
690
681
|
} catch (e) {
|
|
691
682
|
connection.close();
|
|
@@ -713,7 +704,7 @@ function describeTable(tableName, options) {
|
|
|
713
704
|
try {
|
|
714
705
|
var query = "SELECT column_name\n FROM information_schema.columns \n WHERE table_name = '".concat(name, "'\n ORDER BY ordinal_position");
|
|
715
706
|
console.log('Preparing to describe table via:', query);
|
|
716
|
-
return queryHandler(state, query, options);
|
|
707
|
+
return queryHandler(state, query, flattenRows, options);
|
|
717
708
|
} catch (e) {
|
|
718
709
|
connection.close();
|
|
719
710
|
throw e;
|
|
@@ -758,7 +749,7 @@ function insertTable(tableName, columns, options) {
|
|
|
758
749
|
}).join(', ');
|
|
759
750
|
var query = "CREATE TABLE ".concat(tableName, " (\n ").concat(structureData, "\n );");
|
|
760
751
|
console.log('Preparing to create table via:', query);
|
|
761
|
-
resolve(queryHandler(state, query, options));
|
|
752
|
+
resolve(queryHandler(state, query, flattenRows, options));
|
|
762
753
|
});
|
|
763
754
|
} catch (e) {
|
|
764
755
|
connection.close();
|
|
@@ -804,7 +795,7 @@ function modifyTable(tableName, columns, options) {
|
|
|
804
795
|
}).join(', ');
|
|
805
796
|
var query = "ALTER TABLE ".concat(tableName, " ADD ").concat(structureData, ";");
|
|
806
797
|
console.log('Preparing to modify table via:', query);
|
|
807
|
-
resolve(queryHandler(state, query, options));
|
|
798
|
+
resolve(queryHandler(state, query, flattenRows, options));
|
|
808
799
|
});
|
|
809
800
|
} catch (e) {
|
|
810
801
|
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
|
},
|