@bdkinc/knex-ibmi 0.5.2 → 0.5.4
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 +56 -7
- package/dist/index.d.ts +56 -7
- package/dist/index.js +58 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -44,6 +44,7 @@ declare enum SqlMethod {
|
|
|
44
44
|
}
|
|
45
45
|
declare class DB2Client extends knex.Client {
|
|
46
46
|
private statementCaches;
|
|
47
|
+
private normalizeBigintToString;
|
|
47
48
|
constructor(config: Knex.Config<DB2Config>);
|
|
48
49
|
private safeStringify;
|
|
49
50
|
_driver(): typeof odbc;
|
|
@@ -70,6 +71,9 @@ declare class DB2Client extends knex.Client {
|
|
|
70
71
|
private executeSelectQuery;
|
|
71
72
|
private executeStatementQuery;
|
|
72
73
|
private isNoDataError;
|
|
74
|
+
private shouldNormalizeBigintValues;
|
|
75
|
+
private maybeNormalizeBigint;
|
|
76
|
+
private normalizeBigintValue;
|
|
73
77
|
/**
|
|
74
78
|
* Format statement response from ODBC driver
|
|
75
79
|
* Handles special case for IDENTITY_VAL_LOCAL() function
|
|
@@ -109,8 +113,12 @@ interface DB2PoolConfig {
|
|
|
109
113
|
acquireConnectionTimeout?: number;
|
|
110
114
|
}
|
|
111
115
|
interface DB2ConnectionParams {
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
DSN?: string;
|
|
117
|
+
SIGNON?: 0 | 1 | 2 | 3 | 4;
|
|
118
|
+
SSL?: 0 | 1;
|
|
119
|
+
CMT?: 0 | 1 | 2 | 3 | 4;
|
|
120
|
+
CONNTYPE?: 0 | 1 | 2;
|
|
121
|
+
DATABASE?: string;
|
|
114
122
|
DBQ?: string;
|
|
115
123
|
MAXDECPREC?: 31 | 63;
|
|
116
124
|
MAXDECSCALE?: number;
|
|
@@ -126,17 +134,57 @@ interface DB2ConnectionParams {
|
|
|
126
134
|
TSP?: 0 | 1 | 2 | 3;
|
|
127
135
|
TSFT?: 0 | 1;
|
|
128
136
|
XMLCURIMPPARSE?: 0 | 1;
|
|
129
|
-
XMLDECLARATION?: 1 | 2 | 3 | 4;
|
|
130
|
-
ALLOWPROCCALLS?: 0 | 1;
|
|
131
|
-
XDYNAMIC?: 0 | 1;
|
|
137
|
+
XMLDECLARATION?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
132
138
|
DFTPKGLIB?: string;
|
|
133
|
-
PKG?:
|
|
139
|
+
PKG?: string;
|
|
140
|
+
XDYNAMIC?: 0 | 1;
|
|
134
141
|
BLOCKFETCH?: 0 | 1;
|
|
142
|
+
BLOCKSIZE?: number;
|
|
135
143
|
COMPRESSION?: 0 | 1;
|
|
136
144
|
CONCURRENCY?: 0 | 1;
|
|
137
145
|
CURSORSENSITIVITY?: 0 | 1 | 2;
|
|
138
|
-
EXTCOLINFO?:
|
|
146
|
+
EXTCOLINFO?: 0 | 1;
|
|
147
|
+
LAZYCLOSE?: 0 | 1;
|
|
148
|
+
MAXFIELDLEN?: number;
|
|
149
|
+
PREFETCH?: 0 | 1;
|
|
150
|
+
QRYSTGLMT?: number | "*NOMAX";
|
|
151
|
+
QUERYOPTIMIZEGOAL?: 0 | 1 | 2;
|
|
152
|
+
QUERYTIMEOUT?: 0 | 1;
|
|
153
|
+
LANGUAGEID?: "AFR" | "ARA" | "BEL" | "BGR" | "CAT" | "CHS" | "CHT" | "CSY" | "DAN" | "DES" | "DEU" | "ELL" | "ENA" | "ENB" | "ENG" | "ENP" | "ENU" | "ESP" | "EST" | "FAR" | "FIN" | "FRA" | "FRB" | "FRC" | "FRS" | "GAE" | "HEB" | "HRV" | "HUN" | "ISL" | "ITA" | "ITS" | "JPN" | "KOR" | "LAO" | "LVA" | "LTU" | "MKD" | "NLB" | "NLD" | "NON" | "NOR" | "PLK" | "PTB" | "PTG" | "RMS" | "ROM" | "RUS" | "SKY" | "SLO" | "SQI" | "SRB" | "SRL" | "SVE" | "THA" | "TRK" | "UKR" | "URD" | "VIE";
|
|
154
|
+
SORTTABLE?: string;
|
|
155
|
+
SORTTYPE?: 0 | 1 | 2 | 3;
|
|
156
|
+
SORTWEIGHT?: 0 | 1;
|
|
157
|
+
CATALOGOPTIONS?: number;
|
|
158
|
+
LIBVIEW?: 0 | 1 | 2;
|
|
159
|
+
REMARKS?: 0 | 1;
|
|
160
|
+
SEARCHPATTERN?: 0 | 1;
|
|
161
|
+
ALLOWUNSCHAR?: 0 | 1;
|
|
162
|
+
CCSID?: number;
|
|
163
|
+
GRAPHIC?: 0 | 1 | 2 | 3;
|
|
164
|
+
HEXPARSEROPT?: 0 | 1;
|
|
165
|
+
TRANSLATE?: 0 | 1;
|
|
166
|
+
TRIMCHAR?: 0 | 1;
|
|
167
|
+
UNICODESQL?: 0 | 1;
|
|
168
|
+
XLATEDLL?: string;
|
|
169
|
+
XLATEOPT?: number;
|
|
170
|
+
QAQQINILIB?: string;
|
|
171
|
+
SQDIAGCODE?: string;
|
|
172
|
+
TRACE?: number;
|
|
173
|
+
ALWAYSCALCLEN?: 0 | 1;
|
|
174
|
+
ALLOWPROCCALLS?: 0 | 1;
|
|
175
|
+
CONCURRENTACCESSRESOLUTION?: 0 | 1 | 2 | 3;
|
|
176
|
+
DB2SQLSTATES?: 0 | 1;
|
|
177
|
+
DATETIMETOCHAR?: number;
|
|
178
|
+
DBCSNoTruncError?: 0 | 1;
|
|
179
|
+
DEBUG?: number;
|
|
180
|
+
KEEPALIVE?: 0 | 1 | 2;
|
|
181
|
+
LOGINTIMEOUT?: number;
|
|
182
|
+
TIMEOUT?: number;
|
|
139
183
|
TRUEAUTOCOMMIT?: 0 | 1;
|
|
184
|
+
NEWPWD?: string;
|
|
185
|
+
XALCS?: 0 | 1;
|
|
186
|
+
XALOCKTIMEOUT?: number;
|
|
187
|
+
XATXNTIMEOUT?: number;
|
|
140
188
|
}
|
|
141
189
|
interface DB2ConnectionConfig {
|
|
142
190
|
database: string;
|
|
@@ -157,6 +205,7 @@ interface DB2Config extends Knex.Config {
|
|
|
157
205
|
preparedStatementCache?: boolean;
|
|
158
206
|
preparedStatementCacheSize?: number;
|
|
159
207
|
readUncommitted?: boolean;
|
|
208
|
+
normalizeBigintToString?: boolean;
|
|
160
209
|
};
|
|
161
210
|
}
|
|
162
211
|
declare const DB2Dialect: typeof DB2Client;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ declare enum SqlMethod {
|
|
|
44
44
|
}
|
|
45
45
|
declare class DB2Client extends knex.Client {
|
|
46
46
|
private statementCaches;
|
|
47
|
+
private normalizeBigintToString;
|
|
47
48
|
constructor(config: Knex.Config<DB2Config>);
|
|
48
49
|
private safeStringify;
|
|
49
50
|
_driver(): typeof odbc;
|
|
@@ -70,6 +71,9 @@ declare class DB2Client extends knex.Client {
|
|
|
70
71
|
private executeSelectQuery;
|
|
71
72
|
private executeStatementQuery;
|
|
72
73
|
private isNoDataError;
|
|
74
|
+
private shouldNormalizeBigintValues;
|
|
75
|
+
private maybeNormalizeBigint;
|
|
76
|
+
private normalizeBigintValue;
|
|
73
77
|
/**
|
|
74
78
|
* Format statement response from ODBC driver
|
|
75
79
|
* Handles special case for IDENTITY_VAL_LOCAL() function
|
|
@@ -109,8 +113,12 @@ interface DB2PoolConfig {
|
|
|
109
113
|
acquireConnectionTimeout?: number;
|
|
110
114
|
}
|
|
111
115
|
interface DB2ConnectionParams {
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
DSN?: string;
|
|
117
|
+
SIGNON?: 0 | 1 | 2 | 3 | 4;
|
|
118
|
+
SSL?: 0 | 1;
|
|
119
|
+
CMT?: 0 | 1 | 2 | 3 | 4;
|
|
120
|
+
CONNTYPE?: 0 | 1 | 2;
|
|
121
|
+
DATABASE?: string;
|
|
114
122
|
DBQ?: string;
|
|
115
123
|
MAXDECPREC?: 31 | 63;
|
|
116
124
|
MAXDECSCALE?: number;
|
|
@@ -126,17 +134,57 @@ interface DB2ConnectionParams {
|
|
|
126
134
|
TSP?: 0 | 1 | 2 | 3;
|
|
127
135
|
TSFT?: 0 | 1;
|
|
128
136
|
XMLCURIMPPARSE?: 0 | 1;
|
|
129
|
-
XMLDECLARATION?: 1 | 2 | 3 | 4;
|
|
130
|
-
ALLOWPROCCALLS?: 0 | 1;
|
|
131
|
-
XDYNAMIC?: 0 | 1;
|
|
137
|
+
XMLDECLARATION?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
132
138
|
DFTPKGLIB?: string;
|
|
133
|
-
PKG?:
|
|
139
|
+
PKG?: string;
|
|
140
|
+
XDYNAMIC?: 0 | 1;
|
|
134
141
|
BLOCKFETCH?: 0 | 1;
|
|
142
|
+
BLOCKSIZE?: number;
|
|
135
143
|
COMPRESSION?: 0 | 1;
|
|
136
144
|
CONCURRENCY?: 0 | 1;
|
|
137
145
|
CURSORSENSITIVITY?: 0 | 1 | 2;
|
|
138
|
-
EXTCOLINFO?:
|
|
146
|
+
EXTCOLINFO?: 0 | 1;
|
|
147
|
+
LAZYCLOSE?: 0 | 1;
|
|
148
|
+
MAXFIELDLEN?: number;
|
|
149
|
+
PREFETCH?: 0 | 1;
|
|
150
|
+
QRYSTGLMT?: number | "*NOMAX";
|
|
151
|
+
QUERYOPTIMIZEGOAL?: 0 | 1 | 2;
|
|
152
|
+
QUERYTIMEOUT?: 0 | 1;
|
|
153
|
+
LANGUAGEID?: "AFR" | "ARA" | "BEL" | "BGR" | "CAT" | "CHS" | "CHT" | "CSY" | "DAN" | "DES" | "DEU" | "ELL" | "ENA" | "ENB" | "ENG" | "ENP" | "ENU" | "ESP" | "EST" | "FAR" | "FIN" | "FRA" | "FRB" | "FRC" | "FRS" | "GAE" | "HEB" | "HRV" | "HUN" | "ISL" | "ITA" | "ITS" | "JPN" | "KOR" | "LAO" | "LVA" | "LTU" | "MKD" | "NLB" | "NLD" | "NON" | "NOR" | "PLK" | "PTB" | "PTG" | "RMS" | "ROM" | "RUS" | "SKY" | "SLO" | "SQI" | "SRB" | "SRL" | "SVE" | "THA" | "TRK" | "UKR" | "URD" | "VIE";
|
|
154
|
+
SORTTABLE?: string;
|
|
155
|
+
SORTTYPE?: 0 | 1 | 2 | 3;
|
|
156
|
+
SORTWEIGHT?: 0 | 1;
|
|
157
|
+
CATALOGOPTIONS?: number;
|
|
158
|
+
LIBVIEW?: 0 | 1 | 2;
|
|
159
|
+
REMARKS?: 0 | 1;
|
|
160
|
+
SEARCHPATTERN?: 0 | 1;
|
|
161
|
+
ALLOWUNSCHAR?: 0 | 1;
|
|
162
|
+
CCSID?: number;
|
|
163
|
+
GRAPHIC?: 0 | 1 | 2 | 3;
|
|
164
|
+
HEXPARSEROPT?: 0 | 1;
|
|
165
|
+
TRANSLATE?: 0 | 1;
|
|
166
|
+
TRIMCHAR?: 0 | 1;
|
|
167
|
+
UNICODESQL?: 0 | 1;
|
|
168
|
+
XLATEDLL?: string;
|
|
169
|
+
XLATEOPT?: number;
|
|
170
|
+
QAQQINILIB?: string;
|
|
171
|
+
SQDIAGCODE?: string;
|
|
172
|
+
TRACE?: number;
|
|
173
|
+
ALWAYSCALCLEN?: 0 | 1;
|
|
174
|
+
ALLOWPROCCALLS?: 0 | 1;
|
|
175
|
+
CONCURRENTACCESSRESOLUTION?: 0 | 1 | 2 | 3;
|
|
176
|
+
DB2SQLSTATES?: 0 | 1;
|
|
177
|
+
DATETIMETOCHAR?: number;
|
|
178
|
+
DBCSNoTruncError?: 0 | 1;
|
|
179
|
+
DEBUG?: number;
|
|
180
|
+
KEEPALIVE?: 0 | 1 | 2;
|
|
181
|
+
LOGINTIMEOUT?: number;
|
|
182
|
+
TIMEOUT?: number;
|
|
139
183
|
TRUEAUTOCOMMIT?: 0 | 1;
|
|
184
|
+
NEWPWD?: string;
|
|
185
|
+
XALCS?: 0 | 1;
|
|
186
|
+
XALOCKTIMEOUT?: number;
|
|
187
|
+
XATXNTIMEOUT?: number;
|
|
140
188
|
}
|
|
141
189
|
interface DB2ConnectionConfig {
|
|
142
190
|
database: string;
|
|
@@ -157,6 +205,7 @@ interface DB2Config extends Knex.Config {
|
|
|
157
205
|
preparedStatementCache?: boolean;
|
|
158
206
|
preparedStatementCacheSize?: number;
|
|
159
207
|
readUncommitted?: boolean;
|
|
208
|
+
normalizeBigintToString?: boolean;
|
|
160
209
|
};
|
|
161
210
|
}
|
|
162
211
|
declare const DB2Dialect: typeof DB2Client;
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
42
|
var import_node_process = __toESM(require("process"));
|
|
43
|
+
var import_node_buffer = require("buffer");
|
|
43
44
|
var import_knex = __toESM(require("knex"));
|
|
44
45
|
var import_odbc = __toESM(require("odbc"));
|
|
45
46
|
|
|
@@ -838,6 +839,7 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
838
839
|
super(config);
|
|
839
840
|
// Per-connection statement cache (WeakMap so it's GC'd with connections)
|
|
840
841
|
__publicField(this, "statementCaches", /* @__PURE__ */ new WeakMap());
|
|
842
|
+
__publicField(this, "normalizeBigintToString");
|
|
841
843
|
this.driverName = "odbc";
|
|
842
844
|
if (this.dialect && !this.config.client) {
|
|
843
845
|
this.printWarn(
|
|
@@ -863,6 +865,8 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
863
865
|
if (config.useNullAsDefault) {
|
|
864
866
|
this.valueForUndefined = null;
|
|
865
867
|
}
|
|
868
|
+
const ibmiConfig = config?.ibmi;
|
|
869
|
+
this.normalizeBigintToString = ibmiConfig?.normalizeBigintToString !== false;
|
|
866
870
|
}
|
|
867
871
|
// Helper method to safely stringify objects that might have circular references
|
|
868
872
|
safeStringify(obj, indent = 0) {
|
|
@@ -1143,7 +1147,8 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1143
1147
|
obj.bindings
|
|
1144
1148
|
);
|
|
1145
1149
|
if (rows) {
|
|
1146
|
-
|
|
1150
|
+
const normalizedRows = this.maybeNormalizeBigint(rows);
|
|
1151
|
+
obj.response = { rows: normalizedRows, rowCount: normalizedRows.length };
|
|
1147
1152
|
}
|
|
1148
1153
|
}
|
|
1149
1154
|
async executeStatementQuery(connection, obj) {
|
|
@@ -1161,7 +1166,9 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1161
1166
|
statement = cache.get(obj.sql);
|
|
1162
1167
|
if (statement) {
|
|
1163
1168
|
usedCache = true;
|
|
1164
|
-
this.printDebug(
|
|
1169
|
+
this.printDebug(
|
|
1170
|
+
`Using cached statement for: ${obj.sql.substring(0, 50)}...`
|
|
1171
|
+
);
|
|
1165
1172
|
} else {
|
|
1166
1173
|
statement = await connection.createStatement();
|
|
1167
1174
|
await statement.prepare(obj.sql);
|
|
@@ -1212,6 +1219,44 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1212
1219
|
const msg = String(error?.message || error || "").toLowerCase();
|
|
1213
1220
|
return msg.includes("02000") || msg.includes("no data") || msg.includes("no rows") || msg.includes("0 rows");
|
|
1214
1221
|
}
|
|
1222
|
+
shouldNormalizeBigintValues() {
|
|
1223
|
+
return this.normalizeBigintToString;
|
|
1224
|
+
}
|
|
1225
|
+
maybeNormalizeBigint(value) {
|
|
1226
|
+
if (value === null || value === void 0) {
|
|
1227
|
+
return value;
|
|
1228
|
+
}
|
|
1229
|
+
if (!this.shouldNormalizeBigintValues()) {
|
|
1230
|
+
return value;
|
|
1231
|
+
}
|
|
1232
|
+
return this.normalizeBigintValue(value);
|
|
1233
|
+
}
|
|
1234
|
+
normalizeBigintValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1235
|
+
if (typeof value === "bigint") {
|
|
1236
|
+
return value.toString();
|
|
1237
|
+
}
|
|
1238
|
+
if (Array.isArray(value)) {
|
|
1239
|
+
for (let i = 0; i < value.length; i++) {
|
|
1240
|
+
value[i] = this.normalizeBigintValue(value[i], seen);
|
|
1241
|
+
}
|
|
1242
|
+
return value;
|
|
1243
|
+
}
|
|
1244
|
+
if (value && typeof value === "object") {
|
|
1245
|
+
if (value instanceof Date || import_node_buffer.Buffer.isBuffer(value) || ArrayBuffer.isView(value)) {
|
|
1246
|
+
return value;
|
|
1247
|
+
}
|
|
1248
|
+
const obj = value;
|
|
1249
|
+
if (seen.has(obj)) {
|
|
1250
|
+
return value;
|
|
1251
|
+
}
|
|
1252
|
+
seen.add(obj);
|
|
1253
|
+
for (const key of Object.keys(obj)) {
|
|
1254
|
+
obj[key] = this.normalizeBigintValue(obj[key], seen);
|
|
1255
|
+
}
|
|
1256
|
+
return value;
|
|
1257
|
+
}
|
|
1258
|
+
return value;
|
|
1259
|
+
}
|
|
1215
1260
|
/**
|
|
1216
1261
|
* Format statement response from ODBC driver
|
|
1217
1262
|
* Handles special case for IDENTITY_VAL_LOCAL() function
|
|
@@ -1219,16 +1264,18 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1219
1264
|
formatStatementResponse(result) {
|
|
1220
1265
|
const isIdentityQuery = result.statement?.includes("IDENTITY_VAL_LOCAL()");
|
|
1221
1266
|
if (isIdentityQuery && result.columns?.length > 0) {
|
|
1267
|
+
const identityRows = result.map(
|
|
1268
|
+
(row) => row[result.columns[0].name]
|
|
1269
|
+
);
|
|
1270
|
+
const normalizedIdentityRows = this.maybeNormalizeBigint(identityRows);
|
|
1222
1271
|
return {
|
|
1223
|
-
rows:
|
|
1224
|
-
(row) => row[result.columns[0].name]
|
|
1225
|
-
),
|
|
1272
|
+
rows: normalizedIdentityRows,
|
|
1226
1273
|
rowCount: result.count
|
|
1227
1274
|
};
|
|
1228
1275
|
}
|
|
1229
1276
|
const rowCount = typeof result?.count === "number" ? result.count : 0;
|
|
1230
1277
|
return {
|
|
1231
|
-
rows: result,
|
|
1278
|
+
rows: this.maybeNormalizeBigint(result),
|
|
1232
1279
|
rowCount
|
|
1233
1280
|
};
|
|
1234
1281
|
}
|
|
@@ -1300,7 +1347,7 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1300
1347
|
return;
|
|
1301
1348
|
}
|
|
1302
1349
|
if (!cursor.noData) {
|
|
1303
|
-
this.push(result);
|
|
1350
|
+
this.push(parentThis.maybeNormalizeBigint(result));
|
|
1304
1351
|
} else {
|
|
1305
1352
|
isClosed = true;
|
|
1306
1353
|
cursor.close((closeError) => {
|
|
@@ -1308,7 +1355,7 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1308
1355
|
parentThis.printError(parentThis.safeStringify(closeError, 2));
|
|
1309
1356
|
}
|
|
1310
1357
|
if (result) {
|
|
1311
|
-
this.push(result);
|
|
1358
|
+
this.push(parentThis.maybeNormalizeBigint(result));
|
|
1312
1359
|
}
|
|
1313
1360
|
this.push(null);
|
|
1314
1361
|
});
|
|
@@ -1372,6 +1419,9 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
1372
1419
|
throw wrappedError;
|
|
1373
1420
|
}
|
|
1374
1421
|
}
|
|
1422
|
+
if (response) {
|
|
1423
|
+
this.maybeNormalizeBigint(response.rows);
|
|
1424
|
+
}
|
|
1375
1425
|
const validationResult = this.validateResponse(obj);
|
|
1376
1426
|
if (validationResult !== null) return validationResult;
|
|
1377
1427
|
return this.processSqlMethod(obj);
|