@bdkinc/knex-ibmi 0.0.15 → 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 +32 -17
- package/dist/index.mjs +32 -17
- package/package.json +1 -1
- package/src/index.ts +39 -20
package/dist/index.js
CHANGED
|
@@ -359,7 +359,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
359
359
|
this.printDebug("acquiring raw connection");
|
|
360
360
|
const connectionConfig = this.config.connection;
|
|
361
361
|
console.log(this._getConnectionString(connectionConfig));
|
|
362
|
-
console.log({ config: this.config, pool: this.pool });
|
|
363
362
|
if (this.config?.connection?.pool) {
|
|
364
363
|
const poolConfig = {
|
|
365
364
|
connectionString: this._getConnectionString(connectionConfig),
|
|
@@ -414,7 +413,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
414
413
|
try {
|
|
415
414
|
const statement = await connection.createStatement();
|
|
416
415
|
await statement.prepare(obj.sql);
|
|
417
|
-
console.log({ obj });
|
|
418
416
|
if (obj.bindings) {
|
|
419
417
|
await statement.bind(obj.bindings);
|
|
420
418
|
}
|
|
@@ -427,33 +425,50 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
427
425
|
rowCount: result.length
|
|
428
426
|
};
|
|
429
427
|
} else if (method === "update") {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
+
};
|
|
438
458
|
}
|
|
439
|
-
const selected = await selectStatement.execute();
|
|
440
|
-
obj.response = {
|
|
441
|
-
rows: selected.map(
|
|
442
|
-
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
443
|
-
),
|
|
444
|
-
rowCount: selected.length
|
|
445
|
-
};
|
|
446
459
|
} else {
|
|
447
460
|
obj.response = { rows: result, rowCount: result.length };
|
|
448
461
|
}
|
|
449
462
|
} catch (err) {
|
|
450
463
|
console.error(err);
|
|
464
|
+
await connection.rollback();
|
|
451
465
|
throw new Error(err);
|
|
452
466
|
} finally {
|
|
453
467
|
console.log("transaction committed");
|
|
454
468
|
await connection.commit();
|
|
455
469
|
}
|
|
456
470
|
}
|
|
471
|
+
console.log({ obj });
|
|
457
472
|
return obj;
|
|
458
473
|
}
|
|
459
474
|
_selectAfterUpdate() {
|
package/dist/index.mjs
CHANGED
|
@@ -324,7 +324,6 @@ var DB2Client = class extends knex.Client {
|
|
|
324
324
|
this.printDebug("acquiring raw connection");
|
|
325
325
|
const connectionConfig = this.config.connection;
|
|
326
326
|
console.log(this._getConnectionString(connectionConfig));
|
|
327
|
-
console.log({ config: this.config, pool: this.pool });
|
|
328
327
|
if (this.config?.connection?.pool) {
|
|
329
328
|
const poolConfig = {
|
|
330
329
|
connectionString: this._getConnectionString(connectionConfig),
|
|
@@ -379,7 +378,6 @@ var DB2Client = class extends knex.Client {
|
|
|
379
378
|
try {
|
|
380
379
|
const statement = await connection.createStatement();
|
|
381
380
|
await statement.prepare(obj.sql);
|
|
382
|
-
console.log({ obj });
|
|
383
381
|
if (obj.bindings) {
|
|
384
382
|
await statement.bind(obj.bindings);
|
|
385
383
|
}
|
|
@@ -392,33 +390,50 @@ var DB2Client = class extends knex.Client {
|
|
|
392
390
|
rowCount: result.length
|
|
393
391
|
};
|
|
394
392
|
} else if (method === "update") {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
+
};
|
|
403
423
|
}
|
|
404
|
-
const selected = await selectStatement.execute();
|
|
405
|
-
obj.response = {
|
|
406
|
-
rows: selected.map(
|
|
407
|
-
(row) => selected.columns.length > 0 ? row[selected.columns[0].name] : row
|
|
408
|
-
),
|
|
409
|
-
rowCount: selected.length
|
|
410
|
-
};
|
|
411
424
|
} else {
|
|
412
425
|
obj.response = { rows: result, rowCount: result.length };
|
|
413
426
|
}
|
|
414
427
|
} catch (err) {
|
|
415
428
|
console.error(err);
|
|
429
|
+
await connection.rollback();
|
|
416
430
|
throw new Error(err);
|
|
417
431
|
} finally {
|
|
418
432
|
console.log("transaction committed");
|
|
419
433
|
await connection.commit();
|
|
420
434
|
}
|
|
421
435
|
}
|
|
436
|
+
console.log({ obj });
|
|
422
437
|
return obj;
|
|
423
438
|
}
|
|
424
439
|
_selectAfterUpdate() {
|
package/package.json
CHANGED
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
|
|