@openfn/language-mssql 2.6.11 → 3.0.0

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.
Files changed (3) hide show
  1. package/ast.json +4 -4
  2. package/lib/Adaptor.js +20 -16
  3. package/package.json +1 -1
package/ast.json CHANGED
@@ -15,7 +15,7 @@
15
15
  },
16
16
  {
17
17
  "title": "example",
18
- "description": "execute(\n sql(sqlQuery)\n)(state)"
18
+ "description": "sql({ query, options })"
19
19
  },
20
20
  {
21
21
  "title": "constructor",
@@ -105,7 +105,7 @@
105
105
  },
106
106
  {
107
107
  "title": "example",
108
- "description": "execute(\n insert(table, record, {setNull: [\"'undefined'\", \"''\"], logValues: false})\n)(state)"
108
+ "description": "insert(table, record, {setNull: [\"'undefined'\", \"''\"], logValues: false})"
109
109
  },
110
110
  {
111
111
  "title": "constructor",
@@ -169,7 +169,7 @@
169
169
  },
170
170
  {
171
171
  "title": "example",
172
- "description": "execute(\n insertMany(table, records, { setNull: false, writeSql: true, logValues: false })\n)(state)"
172
+ "description": "insertMany(table, records, { setNull: false, writeSql: true, logValues: false })"
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)\nexecute(\n upsert(table, [uuid1, uuid2], record, { setNull: \"'undefined'\", logValues: false})\n)(state)"
237
+ "description": "upsert(table, uuid, record, { setNull: \"'undefined'\", logValues: false})\nupsert(table, [uuid1, uuid2], record, { setNull: \"'undefined'\", logValues: false})"
238
238
  },
239
239
  {
240
240
  "title": "constructor",
package/lib/Adaptor.js CHANGED
@@ -254,6 +254,20 @@ function flattenRows(state, rows) {
254
254
  });
255
255
  }
256
256
 
257
+ function composeNextState(state, rows) {
258
+ var obj = {};
259
+ rows.forEach(function (row) {
260
+ row.forEach(function (col) {
261
+ obj[col.metadata.colName] = col.value;
262
+ });
263
+ });
264
+ return _objectSpread(_objectSpread({}, state), {}, {
265
+ response: {
266
+ body: obj
267
+ }
268
+ });
269
+ }
270
+
257
271
  function queryHandler(state, query, callback, options) {
258
272
  var connection = state.connection;
259
273
  return new Promise(function (resolve, reject) {
@@ -286,9 +300,7 @@ function queryHandler(state, query, callback, options) {
286
300
  * Execute an SQL statement
287
301
  * @public
288
302
  * @example
289
- * execute(
290
- * sql(sqlQuery)
291
- * )(state)
303
+ * sql({ query, options })
292
304
  * @constructor
293
305
  * @param {object} params - Payload data for the message
294
306
  * @returns {Operation}
@@ -305,7 +317,7 @@ function sql(params) {
305
317
  options = _expandReferences.options;
306
318
 
307
319
  console.log("Preparing to execute sql statement: ".concat(query));
308
- return queryHandler(state, query, flattenRows, options);
320
+ return queryHandler(state, query, composeNextState, options);
309
321
  } catch (e) {
310
322
  connection.close();
311
323
  throw e;
@@ -419,9 +431,7 @@ function findValue(filter) {
419
431
  * Insert a record
420
432
  * @public
421
433
  * @example
422
- * execute(
423
- * insert(table, record, {setNull: ["'undefined'", "''"], logValues: false})
424
- * )(state)
434
+ * insert(table, record, {setNull: ["'undefined'", "''"], logValues: false})
425
435
  * @constructor
426
436
  * @param {string} table - The target table
427
437
  * @param {object} record - Payload data for the record as a JS object
@@ -457,9 +467,7 @@ function insert(table, record, options) {
457
467
  * Insert many records, using the keys of the first as the column template
458
468
  * @public
459
469
  * @example
460
- * execute(
461
- * insertMany(table, records, { setNull: false, writeSql: true, logValues: false })
462
- * )(state)
470
+ * insertMany(table, records, { setNull: false, writeSql: true, logValues: false })
463
471
  * @constructor
464
472
  * @param {string} table - The target table
465
473
  * @param {function} records - A function that takes state and returns an array of records
@@ -496,12 +504,8 @@ function insertMany(table, records, options) {
496
504
  * Insert or update a record using SQL MERGE
497
505
  * @public
498
506
  * @example
499
- * execute(
500
- * upsert(table, uuid, record, { setNull: "'undefined'", logValues: false})
501
- * )(state)
502
- * execute(
503
- * upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false})
504
- * )(state)
507
+ * upsert(table, uuid, record, { setNull: "'undefined'", logValues: false})
508
+ * upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false})
505
509
  * @constructor
506
510
  * @param {string} table - The target table
507
511
  * @param {string} uuid - The uuid column to determine a matching/existing record
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-mssql",
3
- "version": "2.6.11",
3
+ "version": "3.0.0",
4
4
  "description": "A Microsoft SQL language pack for OpenFn",
5
5
  "main": "lib/index.js",
6
6
  "homepage": "https://docs.openfn.org",