@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.mjs CHANGED
@@ -891,6 +891,20 @@ var DB2Client = class extends knex.Client {
891
891
  const connection = await this.driver.connect(
892
892
  this._getConnectionString(connectionConfig)
893
893
  );
894
+ if (connectionConfig.sessionInit) {
895
+ const { currentSchema, currentPath, statements } = connectionConfig.sessionInit;
896
+ if (currentSchema) {
897
+ await connection.query(`SET CURRENT SCHEMA = ${currentSchema}`);
898
+ }
899
+ if (currentPath) {
900
+ await connection.query(`SET CURRENT PATH = ${currentPath}`);
901
+ }
902
+ if (statements && statements.length > 0) {
903
+ for (const stmt of statements) {
904
+ await connection.query(stmt);
905
+ }
906
+ }
907
+ }
894
908
  return connection;
895
909
  }
896
910
  // Used to explicitly close a connection, called internally by the pool manager
@@ -923,7 +937,8 @@ var DB2Client = class extends knex.Client {
923
937
  const value = connectionStringParams[key];
924
938
  return `${result}${key}=${value};`;
925
939
  }, "");
926
- return `DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};PORT=${connectionConfig.port || 8471};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};` + connectionStringExtension;
940
+ const databasePart = connectionConfig.database ? `DATABASE=${connectionConfig.database};` : "";
941
+ return `DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};PORT=${connectionConfig.port || 8471};` + databasePart + `UID=${connectionConfig.user};PWD=${connectionConfig.password};` + connectionStringExtension;
927
942
  }
928
943
  // Runs the query on the specified connection, providing the bindings
929
944
  async _query(connection, obj) {
@@ -1419,11 +1434,25 @@ var DB2Client = class extends knex.Client {
1419
1434
  validateResponse(obj) {
1420
1435
  if (!obj.response) {
1421
1436
  this.printDebug("response undefined " + this.safeStringify(obj));
1422
- return null;
1437
+ return this.processSqlMethod({
1438
+ ...obj,
1439
+ response: { rows: [], rowCount: 0 }
1440
+ });
1423
1441
  }
1424
1442
  if (!obj.response.rows) {
1425
- this.printError("rows undefined " + this.safeStringify(obj));
1426
- return null;
1443
+ const usesRowCountOnly = !obj.select && (obj.sqlMethod === "del" /* DELETE */ || obj.sqlMethod === "delete" /* DELETE_ALT */ || obj.sqlMethod === "update" /* UPDATE */ || obj.sqlMethod === "counter" /* COUNTER */);
1444
+ if (usesRowCountOnly) {
1445
+ return null;
1446
+ }
1447
+ this.printWarn("rows undefined " + this.safeStringify(obj));
1448
+ return this.processSqlMethod({
1449
+ ...obj,
1450
+ response: {
1451
+ ...obj.response,
1452
+ rows: [],
1453
+ rowCount: obj.response.rowCount ?? 0
1454
+ }
1455
+ });
1427
1456
  }
1428
1457
  return null;
1429
1458
  }
@@ -1513,7 +1542,8 @@ var DB2Client = class extends knex.Client {
1513
1542
  return errorMessage.includes("sql") || errorMessage.includes("syntax") || errorMessage.includes("table") || errorMessage.includes("column");
1514
1543
  }
1515
1544
  processSqlMethod(obj) {
1516
- const { rows, rowCount } = obj.response;
1545
+ const rows = obj.response?.rows ?? [];
1546
+ const rowCount = obj.response?.rowCount;
1517
1547
  switch (obj.sqlMethod) {
1518
1548
  case "select" /* SELECT */:
1519
1549
  return rows;