@bdkinc/knex-ibmi 0.1.7 → 0.2.1
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 +5 -31
- package/dist/index.d.ts +22 -14
- package/dist/index.js +75 -108
- package/package.json +21 -17
- package/src/execution/ibmi-transaction.js +0 -99
- package/src/execution/ibmi-transaction.ts +0 -21
- package/src/index.ts +0 -293
- package/src/knex-shim.d.ts +0 -283
- package/src/query/ibmi-querycompiler.js +0 -249
- package/src/query/ibmi-querycompiler.ts +0 -219
- package/src/schema/ibmi-columncompiler.js +0 -33
- package/src/schema/ibmi-columncompiler.ts +0 -14
- package/src/schema/ibmi-compiler.js +0 -67
- package/src/schema/ibmi-compiler.ts +0 -52
- package/src/schema/ibmi-tablecompiler.js +0 -166
- package/src/schema/ibmi-tablecompiler.ts +0 -114
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Currently, this dialect has limited functionality compared to the Knex built-in
|
|
|
24
24
|
|
|
25
25
|
`npm install @bdkinc/knex-ibmi`
|
|
26
26
|
|
|
27
|
-
Requires Node
|
|
27
|
+
Requires Node v16 or higher.
|
|
28
28
|
|
|
29
29
|
## Dependencies
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@ Requires Node v14 or higher.
|
|
|
34
34
|
|
|
35
35
|
## Usage
|
|
36
36
|
|
|
37
|
-
This library
|
|
37
|
+
This library can be used as commonjs, esm or typescript.
|
|
38
38
|
|
|
39
39
|
```javascript
|
|
40
40
|
const knex = require("knex");
|
|
@@ -105,7 +105,6 @@ try {
|
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
or as Typescript
|
|
108
|
-
note: you will probably need to add skipLibCheck: true in your tsconfig compilerOptions if not there already. I plan to clean up the types so this is not an issue.
|
|
109
108
|
|
|
110
109
|
```typescript
|
|
111
110
|
import { knex } from "knex";
|
|
@@ -143,33 +142,6 @@ try {
|
|
|
143
142
|
}
|
|
144
143
|
```
|
|
145
144
|
|
|
146
|
-
## Pooling
|
|
147
|
-
|
|
148
|
-
Tarn Pooling Configuration
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
const db = knex({
|
|
152
|
-
client: DB2Dialect,
|
|
153
|
-
connection: {
|
|
154
|
-
host: "localhost",
|
|
155
|
-
database: "knextest",
|
|
156
|
-
port: 50000,
|
|
157
|
-
user: "<user>",
|
|
158
|
-
password: "<password>",
|
|
159
|
-
driver: "IBM i Access ODBC Driver",
|
|
160
|
-
connectionStringParams: {
|
|
161
|
-
ALLOWPROCCALLS: 1,
|
|
162
|
-
CMT: 0,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
pool: {
|
|
166
|
-
min: 2,
|
|
167
|
-
max: 10,
|
|
168
|
-
acquireConnectionTimeout: 6000,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
145
|
## Configuring your driver
|
|
174
146
|
|
|
175
147
|
If you don't know the name of your installed driver, then look in `odbcinst.ini`. You can find the full path of the file by running `odbcinst -j`.
|
|
@@ -195,5 +167,7 @@ DontDLClose=1
|
|
|
195
167
|
UsageCount=1
|
|
196
168
|
```
|
|
197
169
|
|
|
198
|
-
If that still doesn't work, then unixodbc is probably looking for the config files in the wrong directory.
|
|
170
|
+
If that still doesn't work, then unixodbc is probably looking for the config files in the wrong directory.
|
|
171
|
+
A common case is that the configs are in `/etc` but your system expects them to be somewhere else.
|
|
172
|
+
In such a case, override the path unixodbc looks in via the `ODBCSYSINI` and `ODBCINI` environment variables.
|
|
199
173
|
E.g., `ODBCINI=/etc ODBCSYSINI=/etc`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as odbc from 'odbc';
|
|
2
|
-
import { Connection } from 'odbc';
|
|
3
1
|
import { knex, Knex } from 'knex';
|
|
2
|
+
import odbc, { Connection } from 'odbc';
|
|
4
3
|
import SchemaCompiler from 'knex/lib/schema/compiler';
|
|
5
4
|
import TableCompiler from 'knex/lib/schema/tablecompiler';
|
|
6
5
|
import ColumnCompiler from 'knex/lib/schema/columncompiler';
|
|
@@ -12,11 +11,17 @@ declare class IBMiSchemaCompiler extends SchemaCompiler {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
declare class IBMiTableCompiler extends TableCompiler {
|
|
15
|
-
createQuery(columns:
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
createQuery(columns: {
|
|
15
|
+
sql: any[];
|
|
16
|
+
}, ifNot: any, like: any): void;
|
|
17
|
+
dropUnique(columns: string[], indexName: any): void;
|
|
18
|
+
unique(columns: string[], indexName: {
|
|
19
|
+
indexName: any;
|
|
20
|
+
deferrable: any;
|
|
21
|
+
predicate: any;
|
|
22
|
+
}): void;
|
|
18
23
|
addColumns(columns: any, prefix: any): void;
|
|
19
|
-
commit(
|
|
24
|
+
commit(connection: Connection): Promise<void>;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
declare class IBMiColumnCompiler extends ColumnCompiler {
|
|
@@ -30,32 +35,33 @@ declare class IBMiQueryCompiler extends QueryCompiler {
|
|
|
30
35
|
sql: string;
|
|
31
36
|
returning: any;
|
|
32
37
|
};
|
|
33
|
-
_buildInsertData(insertValues: any, returningSql:
|
|
38
|
+
_buildInsertData(insertValues: string | any[], returningSql: string): string;
|
|
34
39
|
_prepInsert(data: any): any;
|
|
35
40
|
update(): {
|
|
36
41
|
sql: string;
|
|
37
42
|
returning: any;
|
|
38
43
|
selectReturning: string;
|
|
39
44
|
};
|
|
40
|
-
_returning(method:
|
|
41
|
-
columnizeWithPrefix(prefix:
|
|
45
|
+
_returning(method: string, value: any, withTrigger: undefined): string | undefined;
|
|
46
|
+
columnizeWithPrefix(prefix: string, target: any): string;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
declare class DB2Client extends knex.Client {
|
|
45
50
|
constructor(config: Knex.Config<DB2Config>);
|
|
46
51
|
_driver(): typeof odbc;
|
|
52
|
+
wrapIdentifierImpl(value: any): any;
|
|
47
53
|
printDebug(message: string): void;
|
|
48
54
|
printError(message: string): void;
|
|
49
55
|
printWarn(message: string): void;
|
|
50
56
|
acquireRawConnection(): Promise<any>;
|
|
51
|
-
destroyRawConnection(connection:
|
|
57
|
+
destroyRawConnection(connection: any): Promise<any>;
|
|
52
58
|
_getConnectionString(connectionConfig: DB2ConnectionConfig): string;
|
|
53
59
|
_query(connection: any, obj: any): Promise<any>;
|
|
54
60
|
transaction(container: any, config: any, outerTx: any): Knex.Transaction;
|
|
55
|
-
schemaCompiler(): IBMiSchemaCompiler;
|
|
56
|
-
tableCompiler(): IBMiTableCompiler;
|
|
57
|
-
columnCompiler(): IBMiColumnCompiler;
|
|
58
|
-
queryCompiler(): IBMiQueryCompiler;
|
|
61
|
+
schemaCompiler(tableBuilder: any): IBMiSchemaCompiler;
|
|
62
|
+
tableCompiler(tableBuilder: any): IBMiTableCompiler;
|
|
63
|
+
columnCompiler(tableCompiler: any, columnCompiler: any): IBMiColumnCompiler;
|
|
64
|
+
queryCompiler(builder: Knex.QueryBuilder): IBMiQueryCompiler;
|
|
59
65
|
processResponse(obj: any, runner: any): any;
|
|
60
66
|
}
|
|
61
67
|
interface DB2PoolConfig {
|
|
@@ -92,6 +98,8 @@ interface DB2Config {
|
|
|
92
98
|
client: any;
|
|
93
99
|
connection: DB2ConnectionConfig;
|
|
94
100
|
pool?: DB2PoolConfig;
|
|
101
|
+
version?: string;
|
|
102
|
+
useNullAsDefault?: boolean;
|
|
95
103
|
}
|
|
96
104
|
declare const DB2Dialect: typeof DB2Client;
|
|
97
105
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -34,20 +33,17 @@ __export(src_exports, {
|
|
|
34
33
|
default: () => src_default
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
var
|
|
36
|
+
var import_node_process = __toESM(require("process"));
|
|
38
37
|
var import_knex = require("knex");
|
|
39
|
-
var
|
|
38
|
+
var import_odbc = __toESM(require("odbc"));
|
|
40
39
|
|
|
41
40
|
// src/schema/ibmi-compiler.ts
|
|
42
41
|
var import_compiler = __toESM(require("knex/lib/schema/compiler"));
|
|
43
42
|
var IBMiSchemaCompiler = class extends import_compiler.default {
|
|
44
43
|
hasTable(tableName) {
|
|
45
44
|
const formattedTable = this.client.parameter(
|
|
46
|
-
// @ts-ignore
|
|
47
45
|
prefixedTableName(this.schema, tableName),
|
|
48
|
-
// @ts-ignore
|
|
49
46
|
this.builder,
|
|
50
|
-
// @ts-ignore
|
|
51
47
|
this.bindingsHolder
|
|
52
48
|
);
|
|
53
49
|
const bindings = [tableName];
|
|
@@ -87,11 +83,7 @@ var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
|
87
83
|
if (like) {
|
|
88
84
|
createStatement += `select * into ${this.tableName()} from ${this.tableNameLike()} WHERE 0=1`;
|
|
89
85
|
} else {
|
|
90
|
-
createStatement += "create table " +
|
|
91
|
-
this.tableName() + // @ts-ignore
|
|
92
|
-
(this._formatting ? " (\n " : " (") + // @ts-ignore
|
|
93
|
-
columns.sql.join(this._formatting ? ",\n " : ", ") + // @ts-ignore
|
|
94
|
-
this._addChecks() + ")";
|
|
86
|
+
createStatement += "create table " + this.tableName() + (this._formatting ? " (\n " : " (") + columns.sql.join(this._formatting ? ",\n " : ", ") + this._addChecks() + ")";
|
|
95
87
|
}
|
|
96
88
|
this.pushQuery(createStatement);
|
|
97
89
|
if (this.single.comment) {
|
|
@@ -106,13 +98,15 @@ var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
|
106
98
|
this.pushQuery(`drop index ${indexName}`);
|
|
107
99
|
}
|
|
108
100
|
unique(columns, indexName) {
|
|
109
|
-
let deferrable;
|
|
101
|
+
let deferrable = "";
|
|
110
102
|
let predicate;
|
|
111
103
|
if ((0, import_isObject.default)(indexName)) {
|
|
112
|
-
|
|
104
|
+
deferrable = indexName.deferrable;
|
|
105
|
+
predicate = indexName.predicate;
|
|
106
|
+
indexName = indexName.indexName;
|
|
113
107
|
}
|
|
114
108
|
if (deferrable && deferrable !== "not deferrable") {
|
|
115
|
-
this.client.logger.warn(
|
|
109
|
+
this.client.logger.warn?.(
|
|
116
110
|
`IBMi: unique index \`${indexName}\` will not be deferrable ${deferrable}.`
|
|
117
111
|
);
|
|
118
112
|
}
|
|
@@ -120,7 +114,6 @@ var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
|
120
114
|
columns = this.formatter.columnize(columns);
|
|
121
115
|
const predicateQuery = predicate ? " " + this.client.queryCompiler(predicate).where() : "";
|
|
122
116
|
this.pushQuery(
|
|
123
|
-
// @ts-ignore
|
|
124
117
|
`create unique index ${indexName} on ${this.tableName()} (${columns})${predicateQuery}`
|
|
125
118
|
);
|
|
126
119
|
}
|
|
@@ -132,17 +125,13 @@ var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
|
132
125
|
return prefix + column;
|
|
133
126
|
});
|
|
134
127
|
this.pushQuery({
|
|
135
|
-
sql: (
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
(this.lowerCase ? "alter table " : "ALTER TABLE ") + // @ts-ignore
|
|
138
|
-
this.tableName() + " " + columnSql.join(" ")
|
|
139
|
-
),
|
|
128
|
+
sql: (this.lowerCase ? "alter table " : "ALTER TABLE ") + this.tableName() + " " + columnSql.join(" "),
|
|
140
129
|
bindings: columns.bindings
|
|
141
130
|
});
|
|
142
131
|
}
|
|
143
132
|
}
|
|
144
|
-
async commit(
|
|
145
|
-
return await
|
|
133
|
+
async commit(connection) {
|
|
134
|
+
return await connection.commit();
|
|
146
135
|
}
|
|
147
136
|
};
|
|
148
137
|
var ibmi_tablecompiler_default = IBMiTableCompiler;
|
|
@@ -151,8 +140,7 @@ var ibmi_tablecompiler_default = IBMiTableCompiler;
|
|
|
151
140
|
var import_columncompiler = __toESM(require("knex/lib/schema/columncompiler"));
|
|
152
141
|
var IBMiColumnCompiler = class extends import_columncompiler.default {
|
|
153
142
|
increments(options = { primaryKey: true }) {
|
|
154
|
-
return "int not null generated always as identity (start with 1, increment by 1)" +
|
|
155
|
-
(this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : "");
|
|
143
|
+
return "int not null generated always as identity (start with 1, increment by 1)" + (this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : "");
|
|
156
144
|
}
|
|
157
145
|
};
|
|
158
146
|
var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
@@ -160,16 +148,16 @@ var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
|
160
148
|
// src/execution/ibmi-transaction.ts
|
|
161
149
|
var import_transaction = __toESM(require("knex/lib/execution/transaction"));
|
|
162
150
|
var IBMiTransaction = class extends import_transaction.default {
|
|
163
|
-
|
|
164
|
-
|
|
151
|
+
begin(connection) {
|
|
152
|
+
connection.beginTransaction();
|
|
165
153
|
return connection;
|
|
166
154
|
}
|
|
167
|
-
|
|
168
|
-
|
|
155
|
+
rollback(connection) {
|
|
156
|
+
connection.rollback();
|
|
169
157
|
return connection;
|
|
170
158
|
}
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
commit(connection) {
|
|
160
|
+
connection.commit();
|
|
173
161
|
return connection;
|
|
174
162
|
}
|
|
175
163
|
};
|
|
@@ -184,24 +172,16 @@ var import_isEmpty = __toESM(require("lodash/isEmpty"));
|
|
|
184
172
|
var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
185
173
|
insert() {
|
|
186
174
|
const insertValues = this.single.insert || [];
|
|
187
|
-
let sql = `select ${
|
|
188
|
-
this.single.returning ? (
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
this.formatter.columnize(this.single.returning)
|
|
191
|
-
) : "IDENTITY_VAL_LOCAL()"} from FINAL TABLE(`;
|
|
175
|
+
let sql = `select ${this.single.returning ? this.formatter.columnize(this.single.returning) : "IDENTITY_VAL_LOCAL()"} from FINAL TABLE(`;
|
|
192
176
|
sql += this.with() + `insert into ${this.tableName} `;
|
|
193
177
|
const { returning } = this.single;
|
|
194
|
-
const returningSql = returning ? (
|
|
195
|
-
// @ts-ignore
|
|
196
|
-
this._returning("insert", returning) + " "
|
|
197
|
-
) : "";
|
|
178
|
+
const returningSql = returning ? this._returning("insert", returning, void 0) + " " : "";
|
|
198
179
|
if (Array.isArray(insertValues)) {
|
|
199
180
|
if (insertValues.length === 0) {
|
|
200
181
|
return "";
|
|
201
182
|
}
|
|
202
183
|
} else if (typeof insertValues === "object" && (0, import_isEmpty.default)(insertValues)) {
|
|
203
184
|
return {
|
|
204
|
-
// @ts-ignore
|
|
205
185
|
sql: sql + returningSql + this._emptyInsertValue,
|
|
206
186
|
returning
|
|
207
187
|
};
|
|
@@ -221,8 +201,7 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
|
221
201
|
} else {
|
|
222
202
|
if (insertData.columns.length) {
|
|
223
203
|
sql += `(${this.formatter.columnize(insertData.columns)}`;
|
|
224
|
-
sql += `) ${returningSql}values (` +
|
|
225
|
-
this._buildInsertValues(insertData) + ")";
|
|
204
|
+
sql += `) ${returningSql}values (` + this._buildInsertValues(insertData) + ")";
|
|
226
205
|
} else if (insertValues.length === 1 && insertValues[0]) {
|
|
227
206
|
sql += returningSql + this._emptyInsertValue;
|
|
228
207
|
} else {
|
|
@@ -241,25 +220,26 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
|
241
220
|
const isRaw = (0, import_wrappingFormatter.rawOrFn)(
|
|
242
221
|
data,
|
|
243
222
|
void 0,
|
|
244
|
-
// @ts-ignore
|
|
245
223
|
this.builder,
|
|
246
|
-
// @ts-ignore
|
|
247
224
|
this.client,
|
|
248
|
-
// @ts-ignore
|
|
249
225
|
this.bindingsHolder
|
|
250
226
|
);
|
|
251
|
-
if (isRaw)
|
|
227
|
+
if (isRaw) {
|
|
252
228
|
return isRaw;
|
|
229
|
+
}
|
|
253
230
|
let columns = [];
|
|
254
231
|
const values = [];
|
|
255
|
-
if (!Array.isArray(data))
|
|
232
|
+
if (!Array.isArray(data)) {
|
|
256
233
|
data = data ? [data] : [];
|
|
234
|
+
}
|
|
257
235
|
let i = -1;
|
|
258
236
|
while (++i < data.length) {
|
|
259
|
-
if (data[i] == null)
|
|
237
|
+
if (data[i] == null) {
|
|
260
238
|
break;
|
|
261
|
-
|
|
239
|
+
}
|
|
240
|
+
if (i === 0) {
|
|
262
241
|
columns = Object.keys(data[i]).sort();
|
|
242
|
+
}
|
|
263
243
|
const row = new Array(columns.length);
|
|
264
244
|
const keys = Object.keys(data[i]);
|
|
265
245
|
let j = -1;
|
|
@@ -292,51 +272,34 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
|
292
272
|
const limit = this.limit();
|
|
293
273
|
const { returning } = this.single;
|
|
294
274
|
const values = Object.values(this.single.update).map((a) => `${a}`).join(", ");
|
|
295
|
-
const moreWheres = (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return;
|
|
302
|
-
if (!w.value)
|
|
303
|
-
return;
|
|
304
|
-
return `"${w.column}" ${w.not ? "!" : ""}${w.operator} ${w.value}`;
|
|
305
|
-
})
|
|
306
|
-
) : []
|
|
307
|
-
);
|
|
308
|
-
let selectReturning = returning ? `select ${returning.map((a) => `"${a}"`).join(", ")} from ${// @ts-ignore
|
|
309
|
-
this.tableName} where ${Object.entries(this.single.update).map(([key, value]) => `"${key}" = '${value}'`).join(" and ")}${moreWheres.length > 0 && " and "}${moreWheres.join(
|
|
275
|
+
const moreWheres = this.grouped.where && this.grouped.where.length > 0 ? this.grouped.where.map((w) => {
|
|
276
|
+
if (this.single.update.hasOwnProperty(w.column)) return;
|
|
277
|
+
if (!w.value) return;
|
|
278
|
+
return `"${w.column}" ${w.not ? "!" : ""}${w.operator} ${w.value}`;
|
|
279
|
+
}) : [];
|
|
280
|
+
let selectReturning = returning ? `select ${returning.map((a) => `"${a}"`).join(", ")} from ${this.tableName} where ${Object.entries(this.single.update).map(([key, value]) => `"${key}" = '${value}'`).join(" and ")}${moreWheres.length > 0 && " and "}${moreWheres.join(
|
|
310
281
|
" and "
|
|
311
282
|
)}` : "";
|
|
312
|
-
const sql = withSQL +
|
|
313
|
-
`update ${this.single.only ? "only " : ""}${this.tableName} set ` + // @ts-ignore
|
|
314
|
-
updates.join(", ") + (where ? ` ${where}` : "") + (order ? ` ${order}` : "") + (limit ? ` ${limit}` : "");
|
|
283
|
+
const sql = withSQL + `update ${this.single.only ? "only " : ""}${this.tableName} set ` + updates.join(", ") + (where ? ` ${where}` : "") + (order ? ` ${order}` : "") + (limit ? ` ${limit}` : "");
|
|
315
284
|
return { sql, returning, selectReturning };
|
|
316
285
|
}
|
|
317
286
|
_returning(method, value, withTrigger) {
|
|
318
287
|
switch (method) {
|
|
319
288
|
case "update":
|
|
320
289
|
case "insert":
|
|
321
|
-
return value ?
|
|
322
|
-
// @ts-ignore
|
|
323
|
-
`${withTrigger ? " into #out" : ""}`
|
|
324
|
-
) : "";
|
|
290
|
+
return value ? `${withTrigger ? " into #out" : ""}` : "";
|
|
325
291
|
case "del":
|
|
326
|
-
return value ?
|
|
327
|
-
// @ts-ignore
|
|
328
|
-
`${withTrigger ? " into #out" : ""}`
|
|
329
|
-
) : "";
|
|
292
|
+
return value ? `${withTrigger ? " into #out" : ""}` : "";
|
|
330
293
|
case "rowcount":
|
|
331
294
|
return value ? "select @@rowcount" : "";
|
|
332
295
|
}
|
|
333
296
|
}
|
|
334
297
|
columnizeWithPrefix(prefix, target) {
|
|
335
298
|
const columns = typeof target === "string" ? [target] : target;
|
|
336
|
-
let str = ""
|
|
299
|
+
let str = "";
|
|
300
|
+
let i = -1;
|
|
337
301
|
while (++i < columns.length) {
|
|
338
|
-
if (i > 0)
|
|
339
|
-
str += ", ";
|
|
302
|
+
if (i > 0) str += ", ";
|
|
340
303
|
str += prefix + this.wrap(columns[i]);
|
|
341
304
|
}
|
|
342
305
|
return str;
|
|
@@ -360,9 +323,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
360
323
|
`knex: Required configuration option 'client' is missing.`
|
|
361
324
|
);
|
|
362
325
|
}
|
|
363
|
-
if (config.version) {
|
|
364
|
-
this.version = config.version;
|
|
365
|
-
}
|
|
366
326
|
if (this.driverName && config.connection) {
|
|
367
327
|
this.initializeDriver();
|
|
368
328
|
if (!config.pool || config.pool && config.pool.max !== 0) {
|
|
@@ -375,21 +335,30 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
375
335
|
}
|
|
376
336
|
}
|
|
377
337
|
_driver() {
|
|
378
|
-
return
|
|
338
|
+
return import_odbc.default;
|
|
339
|
+
}
|
|
340
|
+
wrapIdentifierImpl(value) {
|
|
341
|
+
return value;
|
|
379
342
|
}
|
|
380
343
|
printDebug(message) {
|
|
381
|
-
if (
|
|
382
|
-
this.logger.debug
|
|
344
|
+
if (import_node_process.default.env.DEBUG === "true") {
|
|
345
|
+
if (this.logger.debug) {
|
|
346
|
+
this.logger.debug("knex-ibmi: " + message);
|
|
347
|
+
}
|
|
383
348
|
}
|
|
384
349
|
}
|
|
385
350
|
printError(message) {
|
|
386
|
-
if (
|
|
387
|
-
this.logger.error
|
|
351
|
+
if (import_node_process.default.env.DEBUG === "true") {
|
|
352
|
+
if (this.logger.error) {
|
|
353
|
+
this.logger.error("knex-ibmi: " + message);
|
|
354
|
+
}
|
|
388
355
|
}
|
|
389
356
|
}
|
|
390
357
|
printWarn(message) {
|
|
391
|
-
if (
|
|
392
|
-
this.logger.warn
|
|
358
|
+
if (import_node_process.default.env.DEBUG === "true") {
|
|
359
|
+
if (this.logger.warn) {
|
|
360
|
+
this.logger.warn("knex-ibmi: " + message);
|
|
361
|
+
}
|
|
393
362
|
}
|
|
394
363
|
}
|
|
395
364
|
// Get a raw connection, called by the pool manager whenever a new
|
|
@@ -397,13 +366,14 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
397
366
|
async acquireRawConnection() {
|
|
398
367
|
this.printDebug("acquiring raw connection");
|
|
399
368
|
const connectionConfig = this.config.connection;
|
|
369
|
+
if (!connectionConfig) {
|
|
370
|
+
return this.printError("There is no connection config defined");
|
|
371
|
+
}
|
|
400
372
|
this.printDebug(
|
|
401
|
-
// @ts-ignore
|
|
402
373
|
"connection config: " + this._getConnectionString(connectionConfig)
|
|
403
374
|
);
|
|
404
375
|
if (this.config?.pool) {
|
|
405
376
|
const poolConfig = {
|
|
406
|
-
// @ts-ignore
|
|
407
377
|
connectionString: this._getConnectionString(connectionConfig),
|
|
408
378
|
connectionTimeout: this.config?.acquireConnectionTimeout || 6e4,
|
|
409
379
|
initialSize: this.config?.pool?.min || 2,
|
|
@@ -414,7 +384,6 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
414
384
|
return await pool.connect();
|
|
415
385
|
}
|
|
416
386
|
return await this.driver.connect(
|
|
417
|
-
// @ts-ignore
|
|
418
387
|
this._getConnectionString(connectionConfig)
|
|
419
388
|
);
|
|
420
389
|
}
|
|
@@ -432,12 +401,13 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
432
401
|
const value = connectionStringParams[key];
|
|
433
402
|
return `${result}${key}=${value};`;
|
|
434
403
|
}, "");
|
|
435
|
-
return `${`DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};`
|
|
404
|
+
return `${`DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};` + connectionStringExtension}`;
|
|
436
405
|
}
|
|
437
406
|
// Runs the query on the specified connection, providing the bindings
|
|
438
407
|
async _query(connection, obj) {
|
|
439
|
-
if (!obj || typeof obj == "string")
|
|
408
|
+
if (!obj || typeof obj == "string") {
|
|
440
409
|
obj = { sql: obj };
|
|
410
|
+
}
|
|
441
411
|
const method = (obj.hasOwnProperty("method") && obj.method !== "raw" ? obj.method : obj.sql.split(" ")[0]).toLowerCase();
|
|
442
412
|
obj.sqlMethod = method;
|
|
443
413
|
if (method === "select" || method === "first" || method === "pluck") {
|
|
@@ -478,8 +448,7 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
478
448
|
obj.response = { rows: result, rowCount: result.count };
|
|
479
449
|
}
|
|
480
450
|
} catch (err) {
|
|
481
|
-
this.
|
|
482
|
-
console.error(err);
|
|
451
|
+
this.printError(err);
|
|
483
452
|
throw new Error(err);
|
|
484
453
|
}
|
|
485
454
|
}
|
|
@@ -487,31 +456,29 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
487
456
|
return obj;
|
|
488
457
|
}
|
|
489
458
|
transaction(container, config, outerTx) {
|
|
490
|
-
return new ibmi_transaction_default(this,
|
|
459
|
+
return new ibmi_transaction_default(this, container, config, outerTx);
|
|
491
460
|
}
|
|
492
|
-
schemaCompiler() {
|
|
493
|
-
return new ibmi_compiler_default(this,
|
|
461
|
+
schemaCompiler(tableBuilder) {
|
|
462
|
+
return new ibmi_compiler_default(this, tableBuilder);
|
|
494
463
|
}
|
|
495
|
-
tableCompiler() {
|
|
496
|
-
return new ibmi_tablecompiler_default(this,
|
|
464
|
+
tableCompiler(tableBuilder) {
|
|
465
|
+
return new ibmi_tablecompiler_default(this, tableBuilder);
|
|
497
466
|
}
|
|
498
|
-
columnCompiler() {
|
|
499
|
-
return new ibmi_columncompiler_default(this,
|
|
467
|
+
columnCompiler(tableCompiler, columnCompiler) {
|
|
468
|
+
return new ibmi_columncompiler_default(this, tableCompiler, columnCompiler);
|
|
500
469
|
}
|
|
501
|
-
queryCompiler() {
|
|
502
|
-
return new ibmi_querycompiler_default(this,
|
|
470
|
+
queryCompiler(builder) {
|
|
471
|
+
return new ibmi_querycompiler_default(this, builder);
|
|
503
472
|
}
|
|
504
473
|
processResponse(obj, runner) {
|
|
505
|
-
if (obj === null)
|
|
506
|
-
return null;
|
|
474
|
+
if (obj === null) return null;
|
|
507
475
|
const resp = obj.response;
|
|
508
476
|
const method = obj.sqlMethod;
|
|
509
477
|
if (!resp) {
|
|
510
478
|
this.printDebug("response undefined" + obj);
|
|
511
479
|
}
|
|
512
480
|
const { rows, rowCount } = resp;
|
|
513
|
-
if (obj.output)
|
|
514
|
-
return obj.output.call(runner, resp);
|
|
481
|
+
if (obj.output) return obj.output.call(runner, resp);
|
|
515
482
|
switch (method) {
|
|
516
483
|
case "select":
|
|
517
484
|
return rows;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bdkinc/knex-ibmi",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Knex dialect for IBMi",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"/dist"
|
|
9
|
-
"/src"
|
|
8
|
+
"/dist"
|
|
10
9
|
],
|
|
11
10
|
"engines": {
|
|
12
11
|
"node": ">=16"
|
|
13
12
|
},
|
|
14
13
|
"scripts": {
|
|
15
14
|
"build": "tsup src/index.ts --dts",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
15
|
+
"test": "ts-mocha -p tsconfig.json --import=tsx test/**/*.spec.ts test/**/**/*.spec.ts --exit",
|
|
16
|
+
"lint": "eslint . --ext .ts",
|
|
17
|
+
"format": "prettier . --write"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"knex",
|
|
@@ -35,22 +35,26 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
38
|
+
"@types/chai": "^4.3.17",
|
|
39
39
|
"@types/knex": "^0.16.1",
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"eslint": "^
|
|
40
|
+
"@types/lodash": "^4.17.7",
|
|
41
|
+
"@types/mocha": "^10.0.7",
|
|
42
|
+
"@types/node": "^22.1.0",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
44
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
45
|
+
"chai": "^5.1.1",
|
|
46
|
+
"debug": "^4.3.6",
|
|
47
|
+
"eslint": "^8.57.0",
|
|
44
48
|
"eslint-config-prettier": "^9.1.0",
|
|
45
|
-
"
|
|
46
|
-
"prettier": "^3.
|
|
47
|
-
"ts-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"typescript": "^5.
|
|
49
|
+
"mocha": "^10.7.0",
|
|
50
|
+
"prettier": "^3.3.3",
|
|
51
|
+
"ts-mocha": "^10.0.0",
|
|
52
|
+
"tsup": "^8.2.4",
|
|
53
|
+
"tsx": "^4.16.5",
|
|
54
|
+
"typescript": "^5.5.4"
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"date-fns": "^
|
|
57
|
+
"date-fns": "^3.6.0",
|
|
54
58
|
"knex": "^3",
|
|
55
59
|
"lodash": "^4.17.21",
|
|
56
60
|
"odbc": "^2.4.8"
|