@bdkinc/knex-ibmi 0.0.14 → 0.0.16
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.js +37 -24
- package/dist/index.mjs +37 -24
- package/package.json +1 -1
- package/src/execution/ibmi-transaction.ts +5 -7
- package/src/index.ts +39 -20
package/dist/index.js
CHANGED
|
@@ -161,19 +161,17 @@ var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
|
161
161
|
// src/execution/ibmi-transaction.ts
|
|
162
162
|
var import_transaction = __toESM(require("knex/lib/execution/transaction"));
|
|
163
163
|
var IBMiTransaction = class extends import_transaction.default {
|
|
164
|
-
async begin(
|
|
165
|
-
const connection = await conn.connect();
|
|
164
|
+
async begin(connection) {
|
|
166
165
|
await connection.beginTransaction();
|
|
167
166
|
return connection;
|
|
168
167
|
}
|
|
169
|
-
async rollback(
|
|
170
|
-
const connection = await conn.connect();
|
|
168
|
+
async rollback(connection) {
|
|
171
169
|
await connection.rollback();
|
|
172
170
|
return connection;
|
|
173
171
|
}
|
|
174
|
-
async commit(
|
|
175
|
-
await
|
|
176
|
-
return
|
|
172
|
+
async commit(connection) {
|
|
173
|
+
await connection.commit();
|
|
174
|
+
return connection;
|
|
177
175
|
}
|
|
178
176
|
};
|
|
179
177
|
var ibmi_transaction_default = IBMiTransaction;
|
|
@@ -361,7 +359,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
361
359
|
this.printDebug("acquiring raw connection");
|
|
362
360
|
const connectionConfig = this.config.connection;
|
|
363
361
|
console.log(this._getConnectionString(connectionConfig));
|
|
364
|
-
console.log({ config: this.config, pool: this.pool });
|
|
365
362
|
if (this.config?.connection?.pool) {
|
|
366
363
|
const poolConfig = {
|
|
367
364
|
connectionString: this._getConnectionString(connectionConfig),
|
|
@@ -416,7 +413,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
416
413
|
try {
|
|
417
414
|
const statement = await connection.createStatement();
|
|
418
415
|
await statement.prepare(obj.sql);
|
|
419
|
-
console.log({ obj });
|
|
420
416
|
if (obj.bindings) {
|
|
421
417
|
await statement.bind(obj.bindings);
|
|
422
418
|
}
|
|
@@ -429,33 +425,50 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
429
425
|
rowCount: result.length
|
|
430
426
|
};
|
|
431
427
|
} else if (method === "update") {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
428
|
+
if (obj.sql.includes("knex_migrations_lock")) {
|
|
429
|
+
console.log("migrations_lock");
|
|
430
|
+
const rows = await connection.query(
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
`select * from "knex_migrations_lock"`
|
|
433
|
+
);
|
|
434
|
+
console.log({ rows });
|
|
435
|
+
console.log(rows.map((row) => row.index));
|
|
436
|
+
obj.response = {
|
|
437
|
+
rows: rows.length,
|
|
438
|
+
rowCount: rows.length
|
|
439
|
+
};
|
|
440
|
+
} else {
|
|
441
|
+
let returningSelect = obj.sql.replace("update", "select * from ");
|
|
442
|
+
returningSelect = returningSelect.replace("where", "and");
|
|
443
|
+
returningSelect = returningSelect.replace("set", "where");
|
|
444
|
+
returningSelect = returningSelect.replace(this.tableName, "where");
|
|
445
|
+
const selectStatement = await connection.createStatement();
|
|
446
|
+
await selectStatement.prepare(returningSelect);
|
|
447
|
+
console.log({ returningSelect });
|
|
448
|
+
if (obj.bindings) {
|
|
449
|
+
await selectStatement.bind(obj.bindings);
|
|
450
|
+
}
|
|
451
|
+
const selected = await selectStatement.execute();
|
|
452
|
+
obj.response = {
|
|
453
|
+
rows: selected.map(
|
|
454
|
+
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
455
|
+
),
|
|
456
|
+
rowCount: selected.length
|
|
457
|
+
};
|
|
440
458
|
}
|
|
441
|
-
const selected = await selectStatement.execute();
|
|
442
|
-
obj.response = {
|
|
443
|
-
rows: selected.map(
|
|
444
|
-
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
445
|
-
),
|
|
446
|
-
rowCount: selected.length
|
|
447
|
-
};
|
|
448
459
|
} else {
|
|
449
460
|
obj.response = { rows: result, rowCount: result.length };
|
|
450
461
|
}
|
|
451
462
|
} catch (err) {
|
|
452
463
|
console.error(err);
|
|
464
|
+
await connection.rollback();
|
|
453
465
|
throw new Error(err);
|
|
454
466
|
} finally {
|
|
455
467
|
console.log("transaction committed");
|
|
456
468
|
await connection.commit();
|
|
457
469
|
}
|
|
458
470
|
}
|
|
471
|
+
console.log({ obj });
|
|
459
472
|
return obj;
|
|
460
473
|
}
|
|
461
474
|
_selectAfterUpdate() {
|
package/dist/index.mjs
CHANGED
|
@@ -126,19 +126,17 @@ var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
|
126
126
|
// src/execution/ibmi-transaction.ts
|
|
127
127
|
import Transaction from "knex/lib/execution/transaction";
|
|
128
128
|
var IBMiTransaction = class extends Transaction {
|
|
129
|
-
async begin(
|
|
130
|
-
const connection = await conn.connect();
|
|
129
|
+
async begin(connection) {
|
|
131
130
|
await connection.beginTransaction();
|
|
132
131
|
return connection;
|
|
133
132
|
}
|
|
134
|
-
async rollback(
|
|
135
|
-
const connection = await conn.connect();
|
|
133
|
+
async rollback(connection) {
|
|
136
134
|
await connection.rollback();
|
|
137
135
|
return connection;
|
|
138
136
|
}
|
|
139
|
-
async commit(
|
|
140
|
-
await
|
|
141
|
-
return
|
|
137
|
+
async commit(connection) {
|
|
138
|
+
await connection.commit();
|
|
139
|
+
return connection;
|
|
142
140
|
}
|
|
143
141
|
};
|
|
144
142
|
var ibmi_transaction_default = IBMiTransaction;
|
|
@@ -326,7 +324,6 @@ var DB2Client = class extends knex.Client {
|
|
|
326
324
|
this.printDebug("acquiring raw connection");
|
|
327
325
|
const connectionConfig = this.config.connection;
|
|
328
326
|
console.log(this._getConnectionString(connectionConfig));
|
|
329
|
-
console.log({ config: this.config, pool: this.pool });
|
|
330
327
|
if (this.config?.connection?.pool) {
|
|
331
328
|
const poolConfig = {
|
|
332
329
|
connectionString: this._getConnectionString(connectionConfig),
|
|
@@ -381,7 +378,6 @@ var DB2Client = class extends knex.Client {
|
|
|
381
378
|
try {
|
|
382
379
|
const statement = await connection.createStatement();
|
|
383
380
|
await statement.prepare(obj.sql);
|
|
384
|
-
console.log({ obj });
|
|
385
381
|
if (obj.bindings) {
|
|
386
382
|
await statement.bind(obj.bindings);
|
|
387
383
|
}
|
|
@@ -394,33 +390,50 @@ var DB2Client = class extends knex.Client {
|
|
|
394
390
|
rowCount: result.length
|
|
395
391
|
};
|
|
396
392
|
} else if (method === "update") {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
393
|
+
if (obj.sql.includes("knex_migrations_lock")) {
|
|
394
|
+
console.log("migrations_lock");
|
|
395
|
+
const rows = await connection.query(
|
|
396
|
+
// @ts-ignore
|
|
397
|
+
`select * from "knex_migrations_lock"`
|
|
398
|
+
);
|
|
399
|
+
console.log({ rows });
|
|
400
|
+
console.log(rows.map((row) => row.index));
|
|
401
|
+
obj.response = {
|
|
402
|
+
rows: rows.length,
|
|
403
|
+
rowCount: rows.length
|
|
404
|
+
};
|
|
405
|
+
} else {
|
|
406
|
+
let returningSelect = obj.sql.replace("update", "select * from ");
|
|
407
|
+
returningSelect = returningSelect.replace("where", "and");
|
|
408
|
+
returningSelect = returningSelect.replace("set", "where");
|
|
409
|
+
returningSelect = returningSelect.replace(this.tableName, "where");
|
|
410
|
+
const selectStatement = await connection.createStatement();
|
|
411
|
+
await selectStatement.prepare(returningSelect);
|
|
412
|
+
console.log({ returningSelect });
|
|
413
|
+
if (obj.bindings) {
|
|
414
|
+
await selectStatement.bind(obj.bindings);
|
|
415
|
+
}
|
|
416
|
+
const selected = await selectStatement.execute();
|
|
417
|
+
obj.response = {
|
|
418
|
+
rows: selected.map(
|
|
419
|
+
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
420
|
+
),
|
|
421
|
+
rowCount: selected.length
|
|
422
|
+
};
|
|
405
423
|
}
|
|
406
|
-
const selected = await selectStatement.execute();
|
|
407
|
-
obj.response = {
|
|
408
|
-
rows: selected.map(
|
|
409
|
-
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
410
|
-
),
|
|
411
|
-
rowCount: selected.length
|
|
412
|
-
};
|
|
413
424
|
} else {
|
|
414
425
|
obj.response = { rows: result, rowCount: result.length };
|
|
415
426
|
}
|
|
416
427
|
} catch (err) {
|
|
417
428
|
console.error(err);
|
|
429
|
+
await connection.rollback();
|
|
418
430
|
throw new Error(err);
|
|
419
431
|
} finally {
|
|
420
432
|
console.log("transaction committed");
|
|
421
433
|
await connection.commit();
|
|
422
434
|
}
|
|
423
435
|
}
|
|
436
|
+
console.log({ obj });
|
|
424
437
|
return obj;
|
|
425
438
|
}
|
|
426
439
|
_selectAfterUpdate() {
|
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import Transaction from "knex/lib/execution/transaction";
|
|
2
2
|
|
|
3
3
|
class IBMiTransaction extends Transaction {
|
|
4
|
-
async begin(
|
|
5
|
-
const connection = await conn.connect();
|
|
4
|
+
async begin(connection) {
|
|
6
5
|
await connection.beginTransaction();
|
|
7
6
|
return connection;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
|
-
async rollback(
|
|
11
|
-
const connection = await conn.connect();
|
|
9
|
+
async rollback(connection) {
|
|
12
10
|
await connection.rollback();
|
|
13
11
|
return connection;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
async commit(
|
|
17
|
-
await
|
|
18
|
-
return
|
|
14
|
+
async commit(connection) {
|
|
15
|
+
await connection.commit();
|
|
16
|
+
return connection;
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
|
package/src/index.ts
CHANGED
|
@@ -62,14 +62,12 @@ class DB2Client extends knex.Client {
|
|
|
62
62
|
const connectionConfig = this.config.connection;
|
|
63
63
|
console.log(this._getConnectionString(connectionConfig));
|
|
64
64
|
|
|
65
|
-
console.log({ config: this.config, pool: this.pool });
|
|
66
|
-
|
|
67
65
|
// @ts-ignore
|
|
68
66
|
if (this.config?.connection?.pool) {
|
|
69
67
|
const poolConfig = {
|
|
70
68
|
connectionString: this._getConnectionString(connectionConfig),
|
|
71
69
|
connectionTimeout:
|
|
72
|
-
|
|
70
|
+
// @ts-ignore
|
|
73
71
|
this.config?.connection?.acquireConnectionTimeout || 60000,
|
|
74
72
|
// @ts-ignore
|
|
75
73
|
initialSize: this.config?.connection?.pool?.min || 2,
|
|
@@ -135,7 +133,6 @@ class DB2Client extends knex.Client {
|
|
|
135
133
|
try {
|
|
136
134
|
const statement = await connection.createStatement();
|
|
137
135
|
await statement.prepare(obj.sql);
|
|
138
|
-
console.log({ obj });
|
|
139
136
|
if (obj.bindings) {
|
|
140
137
|
await statement.bind(obj.bindings);
|
|
141
138
|
}
|
|
@@ -152,35 +149,56 @@ class DB2Client extends knex.Client {
|
|
|
152
149
|
),
|
|
153
150
|
rowCount: result.length,
|
|
154
151
|
};
|
|
152
|
+
// @ts-ignore
|
|
155
153
|
} else if (method === "update") {
|
|
156
154
|
// if is in update we need to run a separate select query
|
|
157
155
|
// this also feels hacky and should be cleaned up
|
|
158
156
|
// it would be a lot easier if the table-reference function
|
|
159
157
|
// worked the same for updates as it does inserts
|
|
160
158
|
// on DB2 LUW it does work so if they ever add it we need to fix
|
|
161
|
-
let returningSelect = obj.sql.replace("update", "select * from ");
|
|
162
|
-
returningSelect = returningSelect.replace("where", "and");
|
|
163
|
-
returningSelect = returningSelect.replace("set", "where");
|
|
164
159
|
// @ts-ignore
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
await
|
|
160
|
+
if (obj.sql.includes("knex_migrations_lock")) {
|
|
161
|
+
// even more hacky for migrations
|
|
162
|
+
console.log("migrations_lock");
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
const rows = await connection.query(
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
`select * from \"knex_migrations_lock\"`,
|
|
167
|
+
);
|
|
168
|
+
console.log({ rows });
|
|
169
|
+
console.log(rows.map((row) => row.index));
|
|
170
|
+
obj.response = {
|
|
171
|
+
rows: rows.length,
|
|
172
|
+
rowCount: rows.length,
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
let returningSelect = obj.sql.replace("update", "select * from ");
|
|
176
|
+
returningSelect = returningSelect.replace("where", "and");
|
|
177
|
+
returningSelect = returningSelect.replace("set", "where");
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
returningSelect = returningSelect.replace(this.tableName, "where");
|
|
180
|
+
const selectStatement = await connection.createStatement();
|
|
181
|
+
await selectStatement.prepare(returningSelect);
|
|
182
|
+
console.log({ returningSelect });
|
|
183
|
+
if (obj.bindings) {
|
|
184
|
+
await selectStatement.bind(obj.bindings);
|
|
185
|
+
}
|
|
186
|
+
const selected = await selectStatement.execute();
|
|
187
|
+
obj.response = {
|
|
188
|
+
rows: selected.map((row) =>
|
|
189
|
+
selected.columns.length > 0
|
|
190
|
+
? row[selected.columns[0].name]
|
|
191
|
+
: row,
|
|
192
|
+
),
|
|
193
|
+
rowCount: selected.length,
|
|
194
|
+
};
|
|
170
195
|
}
|
|
171
|
-
const selected = await selectStatement.execute();
|
|
172
|
-
obj.response = {
|
|
173
|
-
rows: selected.map((row) =>
|
|
174
|
-
selected.columns.length > 0 ? row[selected.columns[0].name] : row,
|
|
175
|
-
),
|
|
176
|
-
rowCount: selected.length,
|
|
177
|
-
};
|
|
178
196
|
} else {
|
|
179
197
|
obj.response = { rows: result, rowCount: result.length };
|
|
180
198
|
}
|
|
181
199
|
} catch (err: any) {
|
|
182
200
|
console.error(err);
|
|
183
|
-
|
|
201
|
+
await connection.rollback();
|
|
184
202
|
throw new Error(err);
|
|
185
203
|
} finally {
|
|
186
204
|
console.log("transaction committed");
|
|
@@ -188,6 +206,7 @@ class DB2Client extends knex.Client {
|
|
|
188
206
|
}
|
|
189
207
|
}
|
|
190
208
|
|
|
209
|
+
console.log({ obj });
|
|
191
210
|
return obj;
|
|
192
211
|
}
|
|
193
212
|
|