@bdkinc/knex-ibmi 0.0.11 → 0.0.13
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 +94 -2
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +10 -5
- package/dist/index.mjs +10 -5
- package/package.json +2 -2
- package/src/index.ts +49 -5
- package/src/query/ibmi-querycompiler.ts +1 -0
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ This is an external dialect for [knex](https://github.com/tgriesser/knex). This
|
|
|
17
17
|
Currently, this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:
|
|
18
18
|
|
|
19
19
|
- No streaming support
|
|
20
|
-
- Updates return the value of the first column in that row. Make sure your identifier is the first column in the table. The returning option does not work on updates.
|
|
20
|
+
- Updates return the value of the first column in that row. Make sure your identifier is the first column in the table. The returning option does not work on updates.
|
|
21
21
|
- Possibly other missing functionality
|
|
22
|
-
- Journaling must be handled separately. After a migration is ran journaling can be configured on the newly created tables. I recommend using the schema utility in the i access client solutions software.
|
|
22
|
+
- Journaling must be handled separately. After a migration is ran journaling can be configured on the newly created tables. I recommend using the schema utility in the i access client solutions software.
|
|
23
23
|
|
|
24
24
|
## Installing
|
|
25
25
|
|
|
@@ -105,6 +105,98 @@ try {
|
|
|
105
105
|
}
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
or as Typescript
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import knex from "knex";
|
|
112
|
+
import { Db2Dialect, DB2Config } from "knex-ibmi";
|
|
113
|
+
|
|
114
|
+
const config: DB2Config = {
|
|
115
|
+
client: Db2Dialect,
|
|
116
|
+
connection: {
|
|
117
|
+
host: "localhost",
|
|
118
|
+
database: "knextest",
|
|
119
|
+
port: 50000,
|
|
120
|
+
user: "<user>",
|
|
121
|
+
password: "<password>",
|
|
122
|
+
driver: "IBM i Access ODBC Driver",
|
|
123
|
+
connectionStringParams: {
|
|
124
|
+
ALLOWPROCCALLS: 1,
|
|
125
|
+
CMT: 0,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
pool: {
|
|
129
|
+
min: 2,
|
|
130
|
+
max: 10,
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const db = knex(config);
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const data = await db.select("*").from("table").where({ foo: "bar" });
|
|
138
|
+
console.log(data);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
throw new Error(err);
|
|
141
|
+
} finally {
|
|
142
|
+
process.exit();
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Pooling
|
|
147
|
+
|
|
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
|
+
Tarn Pooling Configuration
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
const db = knex({
|
|
156
|
+
client: Db2Dialect,
|
|
157
|
+
connection: {
|
|
158
|
+
host: "localhost",
|
|
159
|
+
database: "knextest",
|
|
160
|
+
port: 50000,
|
|
161
|
+
user: "<user>",
|
|
162
|
+
password: "<password>",
|
|
163
|
+
driver: "IBM i Access ODBC Driver",
|
|
164
|
+
connectionStringParams: {
|
|
165
|
+
ALLOWPROCCALLS: 1,
|
|
166
|
+
CMT: 0,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
pool: {
|
|
170
|
+
min: 2,
|
|
171
|
+
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
|
+
},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
108
200
|
## Configuring your driver
|
|
109
201
|
|
|
110
202
|
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`.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as odbc from 'odbc';
|
|
2
|
+
import { Connection } from 'odbc';
|
|
3
|
+
import { knex, Knex } from 'knex';
|
|
4
|
+
import SchemaCompiler from 'knex/lib/schema/compiler';
|
|
5
|
+
import TableCompiler from 'knex/lib/schema/tablecompiler';
|
|
6
|
+
import ColumnCompiler from 'knex/lib/schema/columncompiler';
|
|
7
|
+
import QueryCompiler from 'knex/lib/query/querycompiler';
|
|
8
|
+
|
|
9
|
+
declare class IBMiSchemaCompiler extends SchemaCompiler {
|
|
10
|
+
hasTable(tableName: any): void;
|
|
11
|
+
toSQL(): any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class IBMiTableCompiler extends TableCompiler {
|
|
15
|
+
createQuery(columns: any, ifNot: any, like: any): void;
|
|
16
|
+
dropUnique(columns: any, indexName: any): void;
|
|
17
|
+
unique(columns: any, indexName: any): void;
|
|
18
|
+
addColumns(columns: any, prefix: any): void;
|
|
19
|
+
commit(conn: any, value: any): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class IBMiColumnCompiler extends ColumnCompiler {
|
|
23
|
+
increments(options?: {
|
|
24
|
+
primaryKey: boolean;
|
|
25
|
+
}): string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare class IBMiQueryCompiler extends QueryCompiler {
|
|
29
|
+
insert(): "" | {
|
|
30
|
+
sql: string;
|
|
31
|
+
returning: any;
|
|
32
|
+
};
|
|
33
|
+
_buildInsertData(insertValues: any, returningSql: any): string;
|
|
34
|
+
_prepInsert(data: any): any;
|
|
35
|
+
_returning(method: any, value: any, withTrigger: any): string | undefined;
|
|
36
|
+
columnizeWithPrefix(prefix: any, target: any): string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare class DB2Client extends knex.Client {
|
|
40
|
+
constructor(config: any);
|
|
41
|
+
_driver(): typeof odbc;
|
|
42
|
+
printDebug(message: string): void;
|
|
43
|
+
acquireRawConnection(): Promise<any>;
|
|
44
|
+
destroyRawConnection(connection: Connection): Promise<void>;
|
|
45
|
+
_getConnectionString(connectionConfig: any): string;
|
|
46
|
+
_query(connection: any, obj: any): Promise<any>;
|
|
47
|
+
_selectAfterUpdate(): string;
|
|
48
|
+
transaction(container: any, config: any, outerTx: any): Knex.Transaction;
|
|
49
|
+
schemaCompiler(): IBMiSchemaCompiler;
|
|
50
|
+
tableCompiler(): IBMiTableCompiler;
|
|
51
|
+
columnCompiler(): IBMiColumnCompiler;
|
|
52
|
+
queryCompiler(): IBMiQueryCompiler;
|
|
53
|
+
processResponse(obj: any, runner: any): any;
|
|
54
|
+
}
|
|
55
|
+
interface DB2PoolConfig {
|
|
56
|
+
min: number;
|
|
57
|
+
max: number;
|
|
58
|
+
}
|
|
59
|
+
interface DB2ConnectionParams {
|
|
60
|
+
CMT?: number;
|
|
61
|
+
CONNTYPE?: number;
|
|
62
|
+
DBQ?: string;
|
|
63
|
+
MAXDECPREC?: 31 | 63;
|
|
64
|
+
MAXDECSCALE?: number;
|
|
65
|
+
MINDIVSCALE?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
66
|
+
NAM?: 0 | 1;
|
|
67
|
+
DFT?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
68
|
+
DSP?: 0 | 1 | 2 | 3 | 4;
|
|
69
|
+
DEC?: 0 | 1;
|
|
70
|
+
DECFLOATERROROPTION?: 0 | 1;
|
|
71
|
+
DECFLOATROUNDMODE?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
72
|
+
MAPDECIMALFLOATDESCRIBE?: 1 | 3;
|
|
73
|
+
}
|
|
74
|
+
interface DB2ConnectionConfig {
|
|
75
|
+
database: string;
|
|
76
|
+
host: string;
|
|
77
|
+
port: 50000 | number;
|
|
78
|
+
user: string;
|
|
79
|
+
password: string;
|
|
80
|
+
driver: "IBM i Access ODBC Driver" | string;
|
|
81
|
+
connectionStringParams?: DB2ConnectionParams;
|
|
82
|
+
pool?: DB2PoolConfig;
|
|
83
|
+
}
|
|
84
|
+
interface DB2Config {
|
|
85
|
+
client: any;
|
|
86
|
+
connection: DB2ConnectionConfig;
|
|
87
|
+
pool?: DB2PoolConfig;
|
|
88
|
+
}
|
|
89
|
+
declare const DB2Dialect: typeof DB2Client;
|
|
90
|
+
|
|
91
|
+
export { DB2Config, DB2Dialect, DB2Client as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as odbc from 'odbc';
|
|
2
|
+
import { Connection } from 'odbc';
|
|
3
|
+
import { knex, Knex } from 'knex';
|
|
4
|
+
import SchemaCompiler from 'knex/lib/schema/compiler';
|
|
5
|
+
import TableCompiler from 'knex/lib/schema/tablecompiler';
|
|
6
|
+
import ColumnCompiler from 'knex/lib/schema/columncompiler';
|
|
7
|
+
import QueryCompiler from 'knex/lib/query/querycompiler';
|
|
8
|
+
|
|
9
|
+
declare class IBMiSchemaCompiler extends SchemaCompiler {
|
|
10
|
+
hasTable(tableName: any): void;
|
|
11
|
+
toSQL(): any;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class IBMiTableCompiler extends TableCompiler {
|
|
15
|
+
createQuery(columns: any, ifNot: any, like: any): void;
|
|
16
|
+
dropUnique(columns: any, indexName: any): void;
|
|
17
|
+
unique(columns: any, indexName: any): void;
|
|
18
|
+
addColumns(columns: any, prefix: any): void;
|
|
19
|
+
commit(conn: any, value: any): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class IBMiColumnCompiler extends ColumnCompiler {
|
|
23
|
+
increments(options?: {
|
|
24
|
+
primaryKey: boolean;
|
|
25
|
+
}): string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare class IBMiQueryCompiler extends QueryCompiler {
|
|
29
|
+
insert(): "" | {
|
|
30
|
+
sql: string;
|
|
31
|
+
returning: any;
|
|
32
|
+
};
|
|
33
|
+
_buildInsertData(insertValues: any, returningSql: any): string;
|
|
34
|
+
_prepInsert(data: any): any;
|
|
35
|
+
_returning(method: any, value: any, withTrigger: any): string | undefined;
|
|
36
|
+
columnizeWithPrefix(prefix: any, target: any): string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare class DB2Client extends knex.Client {
|
|
40
|
+
constructor(config: any);
|
|
41
|
+
_driver(): typeof odbc;
|
|
42
|
+
printDebug(message: string): void;
|
|
43
|
+
acquireRawConnection(): Promise<any>;
|
|
44
|
+
destroyRawConnection(connection: Connection): Promise<void>;
|
|
45
|
+
_getConnectionString(connectionConfig: any): string;
|
|
46
|
+
_query(connection: any, obj: any): Promise<any>;
|
|
47
|
+
_selectAfterUpdate(): string;
|
|
48
|
+
transaction(container: any, config: any, outerTx: any): Knex.Transaction;
|
|
49
|
+
schemaCompiler(): IBMiSchemaCompiler;
|
|
50
|
+
tableCompiler(): IBMiTableCompiler;
|
|
51
|
+
columnCompiler(): IBMiColumnCompiler;
|
|
52
|
+
queryCompiler(): IBMiQueryCompiler;
|
|
53
|
+
processResponse(obj: any, runner: any): any;
|
|
54
|
+
}
|
|
55
|
+
interface DB2PoolConfig {
|
|
56
|
+
min: number;
|
|
57
|
+
max: number;
|
|
58
|
+
}
|
|
59
|
+
interface DB2ConnectionParams {
|
|
60
|
+
CMT?: number;
|
|
61
|
+
CONNTYPE?: number;
|
|
62
|
+
DBQ?: string;
|
|
63
|
+
MAXDECPREC?: 31 | 63;
|
|
64
|
+
MAXDECSCALE?: number;
|
|
65
|
+
MINDIVSCALE?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
66
|
+
NAM?: 0 | 1;
|
|
67
|
+
DFT?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
68
|
+
DSP?: 0 | 1 | 2 | 3 | 4;
|
|
69
|
+
DEC?: 0 | 1;
|
|
70
|
+
DECFLOATERROROPTION?: 0 | 1;
|
|
71
|
+
DECFLOATROUNDMODE?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
72
|
+
MAPDECIMALFLOATDESCRIBE?: 1 | 3;
|
|
73
|
+
}
|
|
74
|
+
interface DB2ConnectionConfig {
|
|
75
|
+
database: string;
|
|
76
|
+
host: string;
|
|
77
|
+
port: 50000 | number;
|
|
78
|
+
user: string;
|
|
79
|
+
password: string;
|
|
80
|
+
driver: "IBM i Access ODBC Driver" | string;
|
|
81
|
+
connectionStringParams?: DB2ConnectionParams;
|
|
82
|
+
pool?: DB2PoolConfig;
|
|
83
|
+
}
|
|
84
|
+
interface DB2Config {
|
|
85
|
+
client: any;
|
|
86
|
+
connection: DB2ConnectionConfig;
|
|
87
|
+
pool?: DB2PoolConfig;
|
|
88
|
+
}
|
|
89
|
+
declare const DB2Dialect: typeof DB2Client;
|
|
90
|
+
|
|
91
|
+
export { DB2Config, DB2Dialect, DB2Client as default };
|
package/dist/index.js
CHANGED
|
@@ -361,15 +361,20 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
361
361
|
this.printDebug("acquiring raw connection");
|
|
362
362
|
const connectionConfig = this.config.connection;
|
|
363
363
|
console.log(this._getConnectionString(connectionConfig));
|
|
364
|
-
|
|
364
|
+
console.log({ config: this.config, pool: this.pool });
|
|
365
|
+
if (this.config?.connection?.pool) {
|
|
365
366
|
const poolConfig = {
|
|
366
367
|
connectionString: this._getConnectionString(connectionConfig),
|
|
367
|
-
connectionTimeout:
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
connectionTimeout: (
|
|
369
|
+
// @ts-ignore
|
|
370
|
+
this.config?.connection?.acquireConnectionTimeout || 6e4
|
|
371
|
+
),
|
|
372
|
+
// @ts-ignore
|
|
373
|
+
initialSize: this.config?.connection?.pool?.min || 2,
|
|
374
|
+
// @ts-ignore
|
|
375
|
+
maxSize: this.config?.connection?.pool?.max || 10,
|
|
370
376
|
reuseConnection: true
|
|
371
377
|
};
|
|
372
|
-
console.log({ config: this.config, pool: this.pool, poolConfig });
|
|
373
378
|
const pool = await this.driver.pool(poolConfig);
|
|
374
379
|
return await pool.connect();
|
|
375
380
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -326,15 +326,20 @@ var DB2Client = class extends knex.Client {
|
|
|
326
326
|
this.printDebug("acquiring raw connection");
|
|
327
327
|
const connectionConfig = this.config.connection;
|
|
328
328
|
console.log(this._getConnectionString(connectionConfig));
|
|
329
|
-
|
|
329
|
+
console.log({ config: this.config, pool: this.pool });
|
|
330
|
+
if (this.config?.connection?.pool) {
|
|
330
331
|
const poolConfig = {
|
|
331
332
|
connectionString: this._getConnectionString(connectionConfig),
|
|
332
|
-
connectionTimeout:
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
connectionTimeout: (
|
|
334
|
+
// @ts-ignore
|
|
335
|
+
this.config?.connection?.acquireConnectionTimeout || 6e4
|
|
336
|
+
),
|
|
337
|
+
// @ts-ignore
|
|
338
|
+
initialSize: this.config?.connection?.pool?.min || 2,
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
maxSize: this.config?.connection?.pool?.max || 10,
|
|
335
341
|
reuseConnection: true
|
|
336
342
|
};
|
|
337
|
-
console.log({ config: this.config, pool: this.pool, poolConfig });
|
|
338
343
|
const pool = await this.driver.pool(poolConfig);
|
|
339
344
|
return await pool.connect();
|
|
340
345
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bdkinc/knex-ibmi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Knex dialect for IBMi",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"engineStrict": true,
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tsup src/index.ts --format esm,cjs",
|
|
16
|
+
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
17
17
|
"lint:scripts": "eslint . --ext .ts",
|
|
18
18
|
"format:scripts": "prettier . --write"
|
|
19
19
|
},
|
package/src/index.ts
CHANGED
|
@@ -62,15 +62,21 @@ class DB2Client extends knex.Client {
|
|
|
62
62
|
const connectionConfig = this.config.connection;
|
|
63
63
|
console.log(this._getConnectionString(connectionConfig));
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
console.log({ config: this.config, pool: this.pool });
|
|
66
|
+
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
if (this.config?.connection?.pool) {
|
|
66
69
|
const poolConfig = {
|
|
67
70
|
connectionString: this._getConnectionString(connectionConfig),
|
|
68
|
-
connectionTimeout:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
connectionTimeout:
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
this.config?.connection?.acquireConnectionTimeout || 60000,
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
initialSize: this.config?.connection?.pool?.min || 2,
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
maxSize: this.config?.connection?.pool?.max || 10,
|
|
71
78
|
reuseConnection: true,
|
|
72
79
|
};
|
|
73
|
-
console.log({ config: this.config, pool: this.pool, poolConfig });
|
|
74
80
|
const pool = await this.driver.pool(poolConfig);
|
|
75
81
|
return await pool.connect();
|
|
76
82
|
}
|
|
@@ -259,5 +265,43 @@ class DB2Client extends knex.Client {
|
|
|
259
265
|
}
|
|
260
266
|
}
|
|
261
267
|
|
|
268
|
+
interface DB2PoolConfig {
|
|
269
|
+
min: number;
|
|
270
|
+
max: number;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface DB2ConnectionParams {
|
|
274
|
+
CMT?: number;
|
|
275
|
+
CONNTYPE?: number;
|
|
276
|
+
DBQ?: string;
|
|
277
|
+
MAXDECPREC?: 31 | 63;
|
|
278
|
+
MAXDECSCALE?: number;
|
|
279
|
+
MINDIVSCALE?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
280
|
+
NAM?: 0 | 1;
|
|
281
|
+
DFT?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
282
|
+
DSP?: 0 | 1 | 2 | 3 | 4;
|
|
283
|
+
DEC?: 0 | 1;
|
|
284
|
+
DECFLOATERROROPTION?: 0 | 1;
|
|
285
|
+
DECFLOATROUNDMODE?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
286
|
+
MAPDECIMALFLOATDESCRIBE?: 1 | 3;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface DB2ConnectionConfig {
|
|
290
|
+
database: string;
|
|
291
|
+
host: string;
|
|
292
|
+
port: 50000 | number;
|
|
293
|
+
user: string;
|
|
294
|
+
password: string;
|
|
295
|
+
driver: "IBM i Access ODBC Driver" | string;
|
|
296
|
+
connectionStringParams?: DB2ConnectionParams;
|
|
297
|
+
pool?: DB2PoolConfig;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface DB2Config {
|
|
301
|
+
client: any;
|
|
302
|
+
connection: DB2ConnectionConfig;
|
|
303
|
+
pool?: DB2PoolConfig;
|
|
304
|
+
}
|
|
305
|
+
|
|
262
306
|
export const DB2Dialect = DB2Client;
|
|
263
307
|
export default DB2Client;
|