@bdkinc/knex-ibmi 0.5.11 → 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) {