@bdkinc/knex-ibmi 0.0.1 → 0.0.3
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 +133 -150
- package/dist/index.js +466 -138
- package/dist/index.mjs +434 -103
- package/package.json +3 -1
- package/src/execution/ibmi-transaction.ts +25 -0
- package/src/index.ts +81 -13
- package/src/query/ibmi-querycompiler.ts +132 -0
- package/src/schema/ibmi-columncompiler.ts +34 -0
- package/src/schema/ibmi-compiler.ts +50 -0
- package/src/schema/ibmi-tablecompiler.ts +109 -0
package/README.md
CHANGED
|
@@ -1,150 +1,133 @@
|
|
|
1
|
-
[](https://npmjs.org/package/knex-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
##
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
https://github.com/ibmdb/node-ibm_db#-download-clidriver-based-on-your-platform--architecture-from-the-below-ibm-hosted-url
|
|
136
|
-
|
|
137
|
-
### Install driver
|
|
138
|
-
|
|
139
|
-
- Extract downloaded file. This will create a `clidriver` folder with the driver contents
|
|
140
|
-
- Copy this folder to wherever your system keeps drivers. If you're not sure where to put it, just copy it to `/opt/ibm`.
|
|
141
|
-
- Add the configuration your `/etc/odbcinst.ini` file. Below is what the contents of the file should look like if your odbc path is `/opt`
|
|
142
|
-
|
|
143
|
-
```
|
|
144
|
-
[IBM Cli Driver]
|
|
145
|
-
Description=IBM CLI Driver for Linux 64-bit
|
|
146
|
-
Driver=/opt/ibm/clidriver/lib/libdb2.soSetup=libdb2.so.1
|
|
147
|
-
hreading=0
|
|
148
|
-
DontDLClose=1
|
|
149
|
-
UsageCount=1
|
|
150
|
-
```
|
|
1
|
+
[](https://npmjs.org/package/@bdkinc/knex-ibmi)
|
|
2
|
+
|
|
3
|
+
**Disclaimer: this library is in early stages of development. Please submit an issue for any bugs encounter or any questions you have.**
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
This is an external dialect for [knex](https://github.com/tgriesser/knex). This library uses the ODBC driver and is only tested on IBMi. Here are the IBM OSS Docs https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/README.html
|
|
8
|
+
|
|
9
|
+
## Supported functionality
|
|
10
|
+
|
|
11
|
+
- Query building
|
|
12
|
+
- Query execution (see [Limitations](#Limitations))
|
|
13
|
+
- Transactions
|
|
14
|
+
|
|
15
|
+
## Limitations
|
|
16
|
+
|
|
17
|
+
Currently, this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:
|
|
18
|
+
|
|
19
|
+
- No streaming support
|
|
20
|
+
- Possibly other missing functionality
|
|
21
|
+
- Uses a pool for all connections
|
|
22
|
+
|
|
23
|
+
## Installing
|
|
24
|
+
|
|
25
|
+
`npm install @bdkinc/knex-ibmi`
|
|
26
|
+
|
|
27
|
+
Requires Node v14 or higher.
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
`npm install odbc` see [IBM ODBC Docs for dependencies](https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/README.html) if you run into any issues
|
|
32
|
+
|
|
33
|
+
`npm install knex`
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
This library is written in typescript and compiled to both commonjs and esm.
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const knex = require("knex");
|
|
41
|
+
const { Db2Dialect } = require("knex-ibmi");
|
|
42
|
+
|
|
43
|
+
const db = knex({
|
|
44
|
+
client: Db2Dialect,
|
|
45
|
+
connection: {
|
|
46
|
+
host: "localhost",
|
|
47
|
+
database: "knextest",
|
|
48
|
+
port: 50000,
|
|
49
|
+
user: "<user>",
|
|
50
|
+
password: "<password>",
|
|
51
|
+
driver: "IBM i Access ODBC Driver",
|
|
52
|
+
connectionStringParams: {
|
|
53
|
+
ALLOWPROCCALLS: 1,
|
|
54
|
+
CMT: 0,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
pool: {
|
|
58
|
+
min: 2,
|
|
59
|
+
max: 10,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const query = db.select("*").from("table").where({ foo: "bar" });
|
|
64
|
+
|
|
65
|
+
query
|
|
66
|
+
.then((result) => console.log(result))
|
|
67
|
+
.catch((err) => console.error(err))
|
|
68
|
+
.finally(() => process.exit());
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
or as ESM
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import knex from "knex";
|
|
75
|
+
import { Db2Dialect } from "knex-ibmi";
|
|
76
|
+
|
|
77
|
+
const db = knex({
|
|
78
|
+
client: Db2Dialect,
|
|
79
|
+
connection: {
|
|
80
|
+
host: "localhost",
|
|
81
|
+
database: "knextest",
|
|
82
|
+
port: 50000,
|
|
83
|
+
user: "<user>",
|
|
84
|
+
password: "<password>",
|
|
85
|
+
driver: "IBM i Access ODBC Driver",
|
|
86
|
+
connectionStringParams: {
|
|
87
|
+
ALLOWPROCCALLS: 1,
|
|
88
|
+
CMT: 0,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
pool: {
|
|
92
|
+
min: 2,
|
|
93
|
+
max: 10,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const data = await db.select("*").from("table").where({ foo: "bar" });
|
|
99
|
+
console.log(data);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throw new Error(err);
|
|
102
|
+
} finally {
|
|
103
|
+
process.exit();
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Configuring your driver
|
|
108
|
+
|
|
109
|
+
If you don't know the name of your installed driver, then look in look in `odbcinst.ini`. You can find the full path of the file by running `odbcinst -j`.
|
|
110
|
+
There you should see an entry like the one below:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
[IBM i Access ODBC Driver] <== driver name in square brackets
|
|
114
|
+
Description=IBM i Access for Linux ODBC Driver
|
|
115
|
+
Driver=/opt/ibm/iaccess/lib/libcwbodbc.so
|
|
116
|
+
Setup=/opt/ibm/iaccess/lib/libcwbodbcs.so
|
|
117
|
+
Driver64=/opt/ibm/iaccess/lib64/libcwbodbc.so
|
|
118
|
+
Setup64=/opt/ibm/iaccess/lib64/libcwbodbcs.so
|
|
119
|
+
Threading=0
|
|
120
|
+
DontDLClose=1
|
|
121
|
+
UsageCount=1
|
|
122
|
+
|
|
123
|
+
[IBM i Access ODBC Driver 64-bit]
|
|
124
|
+
Description=IBM i Access for Linux 64-bit ODBC Driver
|
|
125
|
+
Driver=/opt/ibm/iaccess/lib64/libcwbodbc.so
|
|
126
|
+
Setup=/opt/ibm/iaccess/lib64/libcwbodbcs.so
|
|
127
|
+
Threading=0
|
|
128
|
+
DontDLClose=1
|
|
129
|
+
UsageCount=1
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If that still doesn't work, then unixodbc is probably looking for the config files in the wrong directory. A common case is that the configs are in `/etc` but your system expects them to be somewhere else. In such case, override the path unixodbc looks in via the `ODBCSYSINI` and `ODBCINI` environment variables.
|
|
133
|
+
E.g., `ODBCINI=/etc ODBCSYSINI=/etc`.
|