@bdkinc/knex-ibmi 0.0.7 → 0.0.8

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 CHANGED
@@ -17,8 +17,8 @@ This is an external dialect for [knex](https://github.com/tgriesser/knex). This
17
17
  Currently, this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:
18
18
 
19
19
  - No streaming support
20
+ - Updates return the value of the first column in that row. Make sure your identifier is the first column in the table. The returning option does not work on updates.
20
21
  - Possibly other missing functionality
21
- - Uses a pool for all connections
22
22
  - Journaling must be handled separately. After a migration is ran journaling can be configured on the newly created tables. I recommend using the schema utility in the i access client solutions software.
23
23
 
24
24
  ## Installing
package/dist/index.js CHANGED
@@ -392,8 +392,9 @@ var DB2Client = class extends import_knex.default.Client {
392
392
  obj.response = { rows, rowCount: rows.length };
393
393
  }
394
394
  } else {
395
+ const connection = await pool.connect();
396
+ await connection.beginTransaction();
395
397
  try {
396
- const connection = await pool.connect();
397
398
  const statement = await connection.createStatement();
398
399
  await statement.prepare(obj.sql);
399
400
  console.log({ obj });
@@ -409,7 +410,6 @@ var DB2Client = class extends import_knex.default.Client {
409
410
  rowCount: result.length
410
411
  };
411
412
  } else if (method === "update") {
412
- console.log(this.queryCompiler);
413
413
  let returningSelect = obj.sql.replace("update", "select * from ");
414
414
  returningSelect = returningSelect.replace("where", "and");
415
415
  returningSelect = returningSelect.replace("set", "where");
@@ -420,14 +420,18 @@ var DB2Client = class extends import_knex.default.Client {
420
420
  await selectStatement.bind(obj.bindings);
421
421
  }
422
422
  const selected = await selectStatement.execute();
423
- console.log(selected.columns);
424
- obj.response = { rows: selected, rowCount: selected.length };
423
+ obj.response = { rows: selected.map(
424
+ (row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
425
+ ), rowCount: selected.length };
425
426
  } else {
426
427
  obj.response = { rows: result, rowCount: result.length };
427
428
  }
428
429
  } catch (err) {
429
430
  console.error(err);
431
+ await connection.rollback();
430
432
  throw new Error(err);
433
+ } finally {
434
+ await connection.commit();
431
435
  }
432
436
  }
433
437
  return obj;
package/dist/index.mjs CHANGED
@@ -357,8 +357,9 @@ var DB2Client = class extends knex.Client {
357
357
  obj.response = { rows, rowCount: rows.length };
358
358
  }
359
359
  } else {
360
+ const connection = await pool.connect();
361
+ await connection.beginTransaction();
360
362
  try {
361
- const connection = await pool.connect();
362
363
  const statement = await connection.createStatement();
363
364
  await statement.prepare(obj.sql);
364
365
  console.log({ obj });
@@ -374,7 +375,6 @@ var DB2Client = class extends knex.Client {
374
375
  rowCount: result.length
375
376
  };
376
377
  } else if (method === "update") {
377
- console.log(this.queryCompiler);
378
378
  let returningSelect = obj.sql.replace("update", "select * from ");
379
379
  returningSelect = returningSelect.replace("where", "and");
380
380
  returningSelect = returningSelect.replace("set", "where");
@@ -385,14 +385,18 @@ var DB2Client = class extends knex.Client {
385
385
  await selectStatement.bind(obj.bindings);
386
386
  }
387
387
  const selected = await selectStatement.execute();
388
- console.log(selected.columns);
389
- obj.response = { rows: selected, rowCount: selected.length };
388
+ obj.response = { rows: selected.map(
389
+ (row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
390
+ ), rowCount: selected.length };
390
391
  } else {
391
392
  obj.response = { rows: result, rowCount: result.length };
392
393
  }
393
394
  } catch (err) {
394
395
  console.error(err);
396
+ await connection.rollback();
395
397
  throw new Error(err);
398
+ } finally {
399
+ await connection.commit();
396
400
  }
397
401
  }
398
402
  return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bdkinc/knex-ibmi",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Knex dialect for IBMi",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.ts CHANGED
@@ -110,8 +110,9 @@ class DB2Client extends knex.Client {
110
110
  obj.response = { rows, rowCount: rows.length };
111
111
  }
112
112
  } else {
113
+ const connection = await pool.connect();
114
+ await connection.beginTransaction();
113
115
  try {
114
- const connection = await pool.connect();
115
116
  const statement = await connection.createStatement();
116
117
  await statement.prepare(obj.sql);
117
118
  console.log({ obj });
@@ -137,7 +138,6 @@ class DB2Client extends knex.Client {
137
138
  // it would be a lot easier if the table-reference function
138
139
  // worked the same for updates as it does inserts
139
140
  // on DB2 LUW it does work so if they ever add it we need to fix
140
- console.log(this.queryCompiler)
141
141
  let returningSelect = obj.sql.replace("update", "select * from ");
142
142
  returningSelect = returningSelect.replace("where", "and");
143
143
  returningSelect = returningSelect.replace("set", "where");
@@ -148,15 +148,20 @@ class DB2Client extends knex.Client {
148
148
  await selectStatement.bind(obj.bindings);
149
149
  }
150
150
  const selected = await selectStatement.execute();
151
- console.log(selected.columns)
152
- obj.response = {rows: selected, rowCount: selected.length}
151
+ obj.response = {rows: selected.map((row) =>
152
+ selected.columns.length > 0 ? row[selected.columns[0].name] : row,
153
+ ), rowCount: selected.length}
153
154
  } else {
154
155
  obj.response = { rows: result, rowCount: result.length };
155
156
  }
156
157
  } catch (err: any) {
157
158
  console.error(err);
159
+ await connection.rollback()
158
160
  throw new Error(err);
161
+ } finally {
162
+ await connection.commit()
159
163
  }
164
+
160
165
  }
161
166
 
162
167
  return obj;