@bdkinc/knex-ibmi 0.5.10 → 0.5.12

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.mts CHANGED
@@ -201,13 +201,18 @@ interface DB2ConnectionParams {
201
201
  XATXNTIMEOUT?: number;
202
202
  }
203
203
  interface DB2ConnectionConfig {
204
- database: string;
204
+ database?: string;
205
205
  host: string;
206
- port: 8471 | 9471 | number;
206
+ port?: number;
207
207
  user: string;
208
208
  password: string;
209
209
  driver: "IBM i Access ODBC Driver" | string;
210
210
  connectionStringParams?: DB2ConnectionParams;
211
+ sessionInit?: {
212
+ currentSchema?: string;
213
+ currentPath?: string;
214
+ statements?: string[];
215
+ };
211
216
  }
212
217
  interface DB2Config extends Knex.Config {
213
218
  client: any;
package/dist/index.d.ts CHANGED
@@ -201,13 +201,18 @@ interface DB2ConnectionParams {
201
201
  XATXNTIMEOUT?: number;
202
202
  }
203
203
  interface DB2ConnectionConfig {
204
- database: string;
204
+ database?: string;
205
205
  host: string;
206
- port: 8471 | 9471 | number;
206
+ port?: number;
207
207
  user: string;
208
208
  password: string;
209
209
  driver: "IBM i Access ODBC Driver" | string;
210
210
  connectionStringParams?: DB2ConnectionParams;
211
+ sessionInit?: {
212
+ currentSchema?: string;
213
+ currentPath?: string;
214
+ statements?: string[];
215
+ };
211
216
  }
212
217
  interface DB2Config extends Knex.Config {
213
218
  client: any;
package/dist/index.js CHANGED
@@ -926,6 +926,20 @@ var DB2Client = class extends import_knex.default.Client {
926
926
  const connection = await this.driver.connect(
927
927
  this._getConnectionString(connectionConfig)
928
928
  );
929
+ if (connectionConfig.sessionInit) {
930
+ const { currentSchema, currentPath, statements } = connectionConfig.sessionInit;
931
+ if (currentSchema) {
932
+ await connection.query(`SET CURRENT SCHEMA = ${currentSchema}`);
933
+ }
934
+ if (currentPath) {
935
+ await connection.query(`SET CURRENT PATH = ${currentPath}`);
936
+ }
937
+ if (statements && statements.length > 0) {
938
+ for (const stmt of statements) {
939
+ await connection.query(stmt);
940
+ }
941
+ }
942
+ }
929
943
  return connection;
930
944
  }
931
945
  // Used to explicitly close a connection, called internally by the pool manager
@@ -958,7 +972,8 @@ var DB2Client = class extends import_knex.default.Client {
958
972
  const value = connectionStringParams[key];
959
973
  return `${result}${key}=${value};`;
960
974
  }, "");
961
- return `DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};PORT=${connectionConfig.port || 8471};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};` + connectionStringExtension;
975
+ const databasePart = connectionConfig.database ? `DATABASE=${connectionConfig.database};` : "";
976
+ return `DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};PORT=${connectionConfig.port || 8471};` + databasePart + `UID=${connectionConfig.user};PWD=${connectionConfig.password};` + connectionStringExtension;
962
977
  }
963
978
  // Runs the query on the specified connection, providing the bindings
964
979
  async _query(connection, obj) {
@@ -1454,11 +1469,25 @@ var DB2Client = class extends import_knex.default.Client {
1454
1469
  validateResponse(obj) {
1455
1470
  if (!obj.response) {
1456
1471
  this.printDebug("response undefined " + this.safeStringify(obj));
1457
- return null;
1472
+ return this.processSqlMethod({
1473
+ ...obj,
1474
+ response: { rows: [], rowCount: 0 }
1475
+ });
1458
1476
  }
1459
1477
  if (!obj.response.rows) {
1460
- this.printError("rows undefined " + this.safeStringify(obj));
1461
- return null;
1478
+ const usesRowCountOnly = !obj.select && (obj.sqlMethod === "del" /* DELETE */ || obj.sqlMethod === "delete" /* DELETE_ALT */ || obj.sqlMethod === "update" /* UPDATE */ || obj.sqlMethod === "counter" /* COUNTER */);
1479
+ if (usesRowCountOnly) {
1480
+ return null;
1481
+ }
1482
+ this.printWarn("rows undefined " + this.safeStringify(obj));
1483
+ return this.processSqlMethod({
1484
+ ...obj,
1485
+ response: {
1486
+ ...obj.response,
1487
+ rows: [],
1488
+ rowCount: obj.response.rowCount ?? 0
1489
+ }
1490
+ });
1462
1491
  }
1463
1492
  return null;
1464
1493
  }
@@ -1548,7 +1577,8 @@ var DB2Client = class extends import_knex.default.Client {
1548
1577
  return errorMessage.includes("sql") || errorMessage.includes("syntax") || errorMessage.includes("table") || errorMessage.includes("column");
1549
1578
  }
1550
1579
  processSqlMethod(obj) {
1551
- const { rows, rowCount } = obj.response;
1580
+ const rows = obj.response?.rows ?? [];
1581
+ const rowCount = obj.response?.rowCount;
1552
1582
  switch (obj.sqlMethod) {
1553
1583
  case "select" /* SELECT */:
1554
1584
  return rows;