@bdkinc/knex-ibmi 0.2.3 → 0.2.4

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/dist/index.d.ts CHANGED
@@ -40,7 +40,6 @@ declare class IBMiQueryCompiler extends QueryCompiler {
40
40
  update(): {
41
41
  sql: string;
42
42
  returning: any;
43
- selectReturning: string;
44
43
  };
45
44
  _returning(method: string, value: any, withTrigger: undefined): string | undefined;
46
45
  columnizeWithPrefix(prefix: string, target: any): string;
@@ -94,12 +93,10 @@ interface DB2ConnectionConfig {
94
93
  driver: "IBM i Access ODBC Driver" | string;
95
94
  connectionStringParams?: DB2ConnectionParams;
96
95
  }
97
- interface DB2Config {
96
+ interface DB2Config extends Knex.Config {
98
97
  client: any;
99
98
  connection: DB2ConnectionConfig;
100
99
  pool?: DB2PoolConfig;
101
- version?: string;
102
- useNullAsDefault?: boolean;
103
100
  }
104
101
  declare const DB2Dialect: typeof DB2Client;
105
102
 
package/dist/index.js CHANGED
@@ -271,17 +271,15 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
271
271
  const order = this.order();
272
272
  const limit = this.limit();
273
273
  const { returning } = this.single;
274
- const values = Object.values(this.single.update).map((a) => `${a}`).join(", ");
275
- const moreWheres = this.grouped.where && this.grouped.where.length > 0 ? this.grouped.where.map((w) => {
276
- if (this.single.update.hasOwnProperty(w.column)) return;
277
- if (!w.value) return;
278
- return `"${w.column}" ${w.not ? "!" : ""}${w.operator} ${w.value}`;
279
- }) : [];
280
- let selectReturning = returning ? `select ${returning.map((a) => `"${a}"`).join(", ")} from ${this.tableName} where ${Object.entries(this.single.update).map(([key, value]) => `"${key}" = '${value}'`).join(" and ")}${moreWheres.length > 0 && " and "}${moreWheres.join(
281
- " and "
282
- )}` : "";
283
- const sql = withSQL + `update ${this.single.only ? "only " : ""}${this.tableName} set ` + updates.join(", ") + (where ? ` ${where}` : "") + (order ? ` ${order}` : "") + (limit ? ` ${limit}` : "");
284
- return { sql, returning, selectReturning };
274
+ let sql = "";
275
+ if (returning) {
276
+ sql += `select ${this.formatter.columnize(this.single.returning)} from FINAL TABLE(`;
277
+ }
278
+ sql += withSQL + `update ${this.single.only ? "only " : ""}${this.tableName} set ` + updates.join(", ") + (where ? ` ${where}` : "") + (order ? ` ${order}` : "") + (limit ? ` ${limit}` : "");
279
+ if (returning) {
280
+ sql += `)`;
281
+ }
282
+ return { sql, returning };
285
283
  }
286
284
  _returning(method, value, withTrigger) {
287
285
  switch (method) {
@@ -348,11 +346,10 @@ var DB2Client = class extends import_knex.knex.Client {
348
346
  }
349
347
  }
350
348
  printError(message) {
351
- if (import_node_process.default.env.DEBUG === "true") {
352
- if (this.logger.error) {
353
- this.logger.error("knex-ibmi: " + message);
354
- }
349
+ if (this.logger.error) {
350
+ this.logger.error("knex-ibmi: " + message);
355
351
  }
352
+ throw new Error(message);
356
353
  }
357
354
  printWarn(message) {
358
355
  if (import_node_process.default.env.DEBUG === "true") {
@@ -448,8 +445,7 @@ var DB2Client = class extends import_knex.knex.Client {
448
445
  obj.response = { rows: result, rowCount: result.count };
449
446
  }
450
447
  } catch (err) {
451
- this.printError(err);
452
- throw new Error(err);
448
+ this.printError(JSON.stringify(err));
453
449
  }
454
450
  }
455
451
  this.printDebug(obj);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bdkinc/knex-ibmi",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Knex dialect for IBMi",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",