@bdkinc/knex-ibmi 0.0.33 → 0.0.35
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 +2 -30
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -24
- package/package.json +1 -1
- package/src/index.ts +7 -7
package/README.md
CHANGED
|
@@ -110,7 +110,6 @@ or as Typescript
|
|
|
110
110
|
import { knex } from "knex";
|
|
111
111
|
import { Db2Dialect, DB2Config } from "@bdkinc/knex-ibmi";
|
|
112
112
|
|
|
113
|
-
|
|
114
113
|
const config: DB2Config = {
|
|
115
114
|
client: Db2Dialect,
|
|
116
115
|
connection: {
|
|
@@ -129,7 +128,7 @@ const config: DB2Config = {
|
|
|
129
128
|
min: 2,
|
|
130
129
|
max: 10,
|
|
131
130
|
},
|
|
132
|
-
}
|
|
131
|
+
};
|
|
133
132
|
|
|
134
133
|
const db = knex(config);
|
|
135
134
|
|
|
@@ -145,10 +144,6 @@ try {
|
|
|
145
144
|
|
|
146
145
|
## Pooling
|
|
147
146
|
|
|
148
|
-
There are 2 different pooling configurations, Tarn pooling and the Node-ODBC pooling.
|
|
149
|
-
Where the pool property is positioned dictates which pooling is used. To use node-odbc pooling the pool object needs to
|
|
150
|
-
be a property inside the connection object. Examples below
|
|
151
|
-
|
|
152
147
|
Tarn Pooling Configuration
|
|
153
148
|
|
|
154
149
|
```javascript
|
|
@@ -169,30 +164,7 @@ const db = knex({
|
|
|
169
164
|
pool: {
|
|
170
165
|
min: 2,
|
|
171
166
|
max: 10,
|
|
172
|
-
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Node-ODBC Pooling Configuration
|
|
177
|
-
|
|
178
|
-
```javascript
|
|
179
|
-
const db = knex({
|
|
180
|
-
client: Db2Dialect,
|
|
181
|
-
connection: {
|
|
182
|
-
host: "localhost",
|
|
183
|
-
database: "knextest",
|
|
184
|
-
port: 50000,
|
|
185
|
-
user: "<user>",
|
|
186
|
-
password: "<password>",
|
|
187
|
-
driver: "IBM i Access ODBC Driver",
|
|
188
|
-
connectionStringParams: {
|
|
189
|
-
ALLOWPROCCALLS: 1,
|
|
190
|
-
CMT: 0,
|
|
191
|
-
},
|
|
192
|
-
pool: {
|
|
193
|
-
min: 2,
|
|
194
|
-
max: 10,
|
|
195
|
-
},
|
|
167
|
+
acquireConnectionTimeout: 6000,
|
|
196
168
|
},
|
|
197
169
|
});
|
|
198
170
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -57,8 +57,9 @@ declare class DB2Client extends knex.Client {
|
|
|
57
57
|
processResponse(obj: any, runner: any): any;
|
|
58
58
|
}
|
|
59
59
|
interface DB2PoolConfig {
|
|
60
|
-
min
|
|
61
|
-
max
|
|
60
|
+
min?: number;
|
|
61
|
+
max?: number;
|
|
62
|
+
acquireConnectionTimeout?: number;
|
|
62
63
|
}
|
|
63
64
|
interface DB2ConnectionParams {
|
|
64
65
|
CMT?: number;
|
|
@@ -83,7 +84,6 @@ interface DB2ConnectionConfig {
|
|
|
83
84
|
password: string;
|
|
84
85
|
driver: "IBM i Access ODBC Driver" | string;
|
|
85
86
|
connectionStringParams?: DB2ConnectionParams;
|
|
86
|
-
pool?: DB2PoolConfig;
|
|
87
87
|
}
|
|
88
88
|
interface DB2Config {
|
|
89
89
|
client: any;
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
37
37
|
var process = __toESM(require("process"));
|
|
38
38
|
var import_knex = require("knex");
|
|
39
39
|
var odbc = __toESM(require("odbc"));
|
|
40
|
-
var
|
|
40
|
+
var console = __toESM(require("console"));
|
|
41
41
|
|
|
42
42
|
// src/schema/ibmi-compiler.ts
|
|
43
43
|
var import_compiler = __toESM(require("knex/lib/schema/compiler"));
|
|
@@ -182,7 +182,6 @@ var import_isObject2 = __toESM(require("lodash/isObject"));
|
|
|
182
182
|
var import_wrappingFormatter = require("knex/lib/formatter/wrappingFormatter");
|
|
183
183
|
var import_date_fns = require("date-fns");
|
|
184
184
|
var import_isEmpty = __toESM(require("lodash/isEmpty"));
|
|
185
|
-
var console = __toESM(require("console"));
|
|
186
185
|
var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
187
186
|
insert() {
|
|
188
187
|
const insertValues = this.single.insert || [];
|
|
@@ -294,18 +293,6 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
|
294
293
|
const limit = this.limit();
|
|
295
294
|
const { returning } = this.single;
|
|
296
295
|
const values = Object.values(this.single.update).map((a) => `${a}`).join(", ");
|
|
297
|
-
console.log({
|
|
298
|
-
returning,
|
|
299
|
-
// @ts-ignore
|
|
300
|
-
where,
|
|
301
|
-
// @ts-ignore
|
|
302
|
-
updates,
|
|
303
|
-
// @ts-ignore
|
|
304
|
-
single: this.single.update,
|
|
305
|
-
// @ts-ignore
|
|
306
|
-
grouped: this.grouped.where,
|
|
307
|
-
values
|
|
308
|
-
});
|
|
309
296
|
const moreWheres = (
|
|
310
297
|
// @ts-ignore
|
|
311
298
|
this.grouped.where && this.grouped.where.length > 0 ? (
|
|
@@ -401,18 +388,18 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
401
388
|
async acquireRawConnection() {
|
|
402
389
|
this.printDebug("acquiring raw connection");
|
|
403
390
|
const connectionConfig = this.config.connection;
|
|
404
|
-
|
|
405
|
-
if (this.config?.
|
|
391
|
+
console.log("knex-ibmi: ", this._getConnectionString(connectionConfig));
|
|
392
|
+
if (this.config?.pool) {
|
|
406
393
|
const poolConfig = {
|
|
407
394
|
connectionString: this._getConnectionString(connectionConfig),
|
|
408
395
|
connectionTimeout: (
|
|
409
396
|
// @ts-ignore
|
|
410
|
-
this.config?.
|
|
397
|
+
this.config?.acquireConnectionTimeout || 6e4
|
|
411
398
|
),
|
|
412
399
|
// @ts-ignore
|
|
413
|
-
initialSize: this.config?.
|
|
400
|
+
initialSize: this.config?.pool?.min || 2,
|
|
414
401
|
// @ts-ignore
|
|
415
|
-
maxSize: this.config?.
|
|
402
|
+
maxSize: this.config?.pool?.max || 10,
|
|
416
403
|
reuseConnection: true
|
|
417
404
|
};
|
|
418
405
|
const pool = await this.driver.pool(poolConfig);
|
|
@@ -425,7 +412,7 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
425
412
|
// Used to explicitly close a connection, called internally by the pool manager
|
|
426
413
|
// when a connection times out or the pool is shutdown.
|
|
427
414
|
async destroyRawConnection(connection) {
|
|
428
|
-
|
|
415
|
+
console.log("knex-ibmi: ", "destroy connection");
|
|
429
416
|
return await connection.close();
|
|
430
417
|
}
|
|
431
418
|
_getConnectionString(connectionConfig) {
|
|
@@ -452,7 +439,7 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
452
439
|
}
|
|
453
440
|
} else {
|
|
454
441
|
await connection.beginTransaction();
|
|
455
|
-
|
|
442
|
+
console.log("knex-ibmi: ", "transaction begun");
|
|
456
443
|
try {
|
|
457
444
|
const statement = await connection.createStatement();
|
|
458
445
|
await statement.prepare(obj.sql);
|
|
@@ -484,15 +471,15 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
484
471
|
obj.response = { rows: result, rowCount: result.count };
|
|
485
472
|
}
|
|
486
473
|
} catch (err) {
|
|
487
|
-
|
|
474
|
+
console.error(err);
|
|
488
475
|
await connection.rollback();
|
|
489
476
|
throw new Error(err);
|
|
490
477
|
} finally {
|
|
491
|
-
|
|
478
|
+
console.log("knex-ibmi: ", "transaction committed");
|
|
492
479
|
await connection.commit();
|
|
493
480
|
}
|
|
494
481
|
}
|
|
495
|
-
|
|
482
|
+
console.log(
|
|
496
483
|
"knex-ibmi: ",
|
|
497
484
|
obj.sql,
|
|
498
485
|
obj.bindings ? JSON.stringify(obj.bindings) : ""
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -63,16 +63,16 @@ class DB2Client extends knex.Client {
|
|
|
63
63
|
console.log("knex-ibmi: ", this._getConnectionString(connectionConfig));
|
|
64
64
|
|
|
65
65
|
// @ts-ignore
|
|
66
|
-
if (this.config?.
|
|
66
|
+
if (this.config?.pool) {
|
|
67
67
|
const poolConfig = {
|
|
68
68
|
connectionString: this._getConnectionString(connectionConfig),
|
|
69
69
|
connectionTimeout:
|
|
70
70
|
// @ts-ignore
|
|
71
|
-
this.config?.
|
|
71
|
+
this.config?.acquireConnectionTimeout || 60000,
|
|
72
72
|
// @ts-ignore
|
|
73
|
-
initialSize: this.config?.
|
|
73
|
+
initialSize: this.config?.pool?.min || 2,
|
|
74
74
|
// @ts-ignore
|
|
75
|
-
maxSize: this.config?.
|
|
75
|
+
maxSize: this.config?.pool?.max || 10,
|
|
76
76
|
reuseConnection: true,
|
|
77
77
|
};
|
|
78
78
|
const pool = await this.driver.pool(poolConfig);
|
|
@@ -244,8 +244,9 @@ class DB2Client extends knex.Client {
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
interface DB2PoolConfig {
|
|
247
|
-
min
|
|
248
|
-
max
|
|
247
|
+
min?: number;
|
|
248
|
+
max?: number;
|
|
249
|
+
acquireConnectionTimeout?: number;
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
interface DB2ConnectionParams {
|
|
@@ -272,7 +273,6 @@ interface DB2ConnectionConfig {
|
|
|
272
273
|
password: string;
|
|
273
274
|
driver: "IBM i Access ODBC Driver" | string;
|
|
274
275
|
connectionStringParams?: DB2ConnectionParams;
|
|
275
|
-
pool?: DB2PoolConfig;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
export interface DB2Config {
|