@bdkinc/knex-ibmi 0.0.2 → 0.0.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/README.md +22 -11
- package/dist/index.js +371 -138
- package/dist/index.mjs +336 -103
- package/package.json +3 -1
- package/src/execution/ibmi-transaction.ts +24 -0
- package/src/index.ts +197 -129
- package/src/query/ibmi-querycompiler.ts +59 -0
- package/src/schema/ibmi-columncompiler.ts +13 -0
- package/src/schema/ibmi-compiler.ts +57 -0
- package/src/schema/ibmi-tablecompiler.ts +70 -0
package/README.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
[](https://npmjs.org/package/@bdkinc/knex-ibmi)
|
|
2
2
|
|
|
3
|
-
**Disclaimer: this library is in early stages of development.
|
|
3
|
+
**Disclaimer: this library is in early stages of development. Please submit an issue for any bugs encounter or any questions you have.**
|
|
4
4
|
|
|
5
5
|
## Description
|
|
6
6
|
|
|
7
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
8
|
|
|
9
|
+
## Supported functionality
|
|
10
|
+
|
|
11
|
+
- Query building
|
|
12
|
+
- Query execution (see [Limitations](#Limitations))
|
|
13
|
+
- Transactions
|
|
14
|
+
|
|
9
15
|
## Limitations
|
|
10
16
|
|
|
11
|
-
Currently this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:
|
|
17
|
+
Currently, this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:
|
|
12
18
|
|
|
13
|
-
- No transaction support
|
|
14
19
|
- No streaming support
|
|
15
20
|
- Possibly other missing functionality
|
|
16
|
-
|
|
17
|
-
## Supported functionality
|
|
18
|
-
|
|
19
|
-
- Query building
|
|
20
|
-
- Query execution (see [Limitations](#Limitations))
|
|
21
|
+
- Uses a pool for all connections
|
|
21
22
|
|
|
22
23
|
## Installing
|
|
23
24
|
|
|
@@ -105,11 +106,21 @@ try {
|
|
|
105
106
|
|
|
106
107
|
## Configuring your driver
|
|
107
108
|
|
|
108
|
-
If you don't know the name of your installed driver, then look in
|
|
109
|
+
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`.
|
|
109
110
|
There you should see an entry like the one below:
|
|
110
111
|
|
|
111
112
|
```
|
|
112
|
-
[IBM i Access ODBC Driver
|
|
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]
|
|
113
124
|
Description=IBM i Access for Linux 64-bit ODBC Driver
|
|
114
125
|
Driver=/opt/ibm/iaccess/lib64/libcwbodbc.so
|
|
115
126
|
Setup=/opt/ibm/iaccess/lib64/libcwbodbcs.so
|
package/dist/index.js
CHANGED
|
@@ -1,138 +1,371 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
DB2Dialect: () => DB2Dialect,
|
|
34
|
-
default: () => src_default
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(src_exports);
|
|
37
|
-
var process = __toESM(require("process"));
|
|
38
|
-
var import_knex = __toESM(require("knex"));
|
|
39
|
-
var odbc = __toESM(require("odbc"));
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
var
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
DB2Dialect: () => DB2Dialect,
|
|
34
|
+
default: () => src_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var process = __toESM(require("process"));
|
|
38
|
+
var import_knex = __toESM(require("knex"));
|
|
39
|
+
var odbc = __toESM(require("odbc"));
|
|
40
|
+
var console3 = __toESM(require("console"));
|
|
41
|
+
|
|
42
|
+
// src/schema/ibmi-compiler.ts
|
|
43
|
+
var import_compiler = __toESM(require("knex/lib/schema/compiler"));
|
|
44
|
+
var console = __toESM(require("console"));
|
|
45
|
+
var IBMiSchemaCompiler = class extends import_compiler.default {
|
|
46
|
+
constructor(client, builder) {
|
|
47
|
+
super(client, builder);
|
|
48
|
+
}
|
|
49
|
+
hasTable(tableName) {
|
|
50
|
+
const formattedTable = this.client.parameter(
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
prefixedTableName(this.schema, tableName),
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
this.builder,
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
this.bindingsHolder
|
|
57
|
+
);
|
|
58
|
+
const bindings = [tableName.toUpperCase()];
|
|
59
|
+
let sql = `SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE TYPE = 'T' AND TABLE_NAME = ${formattedTable}`;
|
|
60
|
+
if (this.schema) {
|
|
61
|
+
sql += " AND TABLE_SCHEMA = ?";
|
|
62
|
+
bindings.push(this.schema);
|
|
63
|
+
}
|
|
64
|
+
this.pushQuery({
|
|
65
|
+
sql,
|
|
66
|
+
bindings,
|
|
67
|
+
output: (resp) => {
|
|
68
|
+
return resp.rowCount > 0;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
toSQL() {
|
|
73
|
+
const sequence = this.builder._sequence;
|
|
74
|
+
for (let i = 0, l = sequence.length; i < l; i++) {
|
|
75
|
+
const query = sequence[i];
|
|
76
|
+
console.log(query.method, query);
|
|
77
|
+
this[query.method].apply(this, query.args);
|
|
78
|
+
}
|
|
79
|
+
return this.sequence;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function prefixedTableName(prefix, table) {
|
|
83
|
+
return prefix ? `${prefix}.${table}` : table;
|
|
84
|
+
}
|
|
85
|
+
var ibmi_compiler_default = IBMiSchemaCompiler;
|
|
86
|
+
|
|
87
|
+
// src/schema/ibmi-tablecompiler.ts
|
|
88
|
+
var import_tablecompiler = __toESM(require("knex/lib/schema/tablecompiler"));
|
|
89
|
+
var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
90
|
+
createQuery(columns, ifNot, like) {
|
|
91
|
+
let createStatement = ifNot ? `if object_id('${this.tableName()}', 'U') is null ` : "";
|
|
92
|
+
if (like) {
|
|
93
|
+
createStatement += `SELECT * INTO ${this.tableName()} FROM ${this.tableNameLike()} WHERE 0=1`;
|
|
94
|
+
} else {
|
|
95
|
+
createStatement += "CREATE TABLE " + // @ts-ignore
|
|
96
|
+
this.tableName() + // @ts-ignore
|
|
97
|
+
(this._formatting ? " (\n " : " (") + // @ts-ignore
|
|
98
|
+
columns.sql.join(this._formatting ? ",\n " : ", ") + // @ts-ignore
|
|
99
|
+
this._addChecks() + ")";
|
|
100
|
+
}
|
|
101
|
+
this.pushQuery(createStatement);
|
|
102
|
+
if (this.single.comment) {
|
|
103
|
+
this.comment(this.single.comment);
|
|
104
|
+
}
|
|
105
|
+
if (like) {
|
|
106
|
+
this.addColumns(columns, this.addColumnsPrefix);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// All of the columns to "add" for the query
|
|
110
|
+
addColumns(columns, prefix) {
|
|
111
|
+
prefix = prefix || this.addColumnsPrefix;
|
|
112
|
+
if (columns.sql.length > 0) {
|
|
113
|
+
const columnSql = columns.sql.map((column) => {
|
|
114
|
+
return prefix + column;
|
|
115
|
+
});
|
|
116
|
+
this.pushQuery({
|
|
117
|
+
sql: (
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
(this.lowerCase ? "alter table " : "ALTER TABLE ") + // @ts-ignore
|
|
120
|
+
this.tableName() + " " + columnSql.join(" ")
|
|
121
|
+
),
|
|
122
|
+
bindings: columns.bindings
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async commit(conn, value) {
|
|
127
|
+
return await conn.commit();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var ibmi_tablecompiler_default = IBMiTableCompiler;
|
|
131
|
+
|
|
132
|
+
// src/schema/ibmi-columncompiler.ts
|
|
133
|
+
var import_columncompiler = __toESM(require("knex/lib/schema/columncompiler"));
|
|
134
|
+
var IBMiColumnCompiler = class extends import_columncompiler.default {
|
|
135
|
+
increments(options = { primaryKey: true }) {
|
|
136
|
+
return "int not null generated always as identity (start with 1, increment by 1)" + // @ts-ignore
|
|
137
|
+
(this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : "");
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
141
|
+
|
|
142
|
+
// src/execution/ibmi-transaction.ts
|
|
143
|
+
var import_transaction = __toESM(require("knex/lib/execution/transaction"));
|
|
144
|
+
var console2 = __toESM(require("console"));
|
|
145
|
+
var IBMiTransaction = class extends import_transaction.default {
|
|
146
|
+
async begin(conn) {
|
|
147
|
+
const connection = await conn.connect();
|
|
148
|
+
await connection.beginTransaction();
|
|
149
|
+
return connection;
|
|
150
|
+
}
|
|
151
|
+
async rollback(conn) {
|
|
152
|
+
console2.log({ conn });
|
|
153
|
+
const connection = await conn.connect();
|
|
154
|
+
await connection.rollback();
|
|
155
|
+
return connection;
|
|
156
|
+
}
|
|
157
|
+
async commit(conn) {
|
|
158
|
+
await conn.commit();
|
|
159
|
+
return conn;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var ibmi_transaction_default = IBMiTransaction;
|
|
163
|
+
|
|
164
|
+
// src/query/ibmi-querycompiler.ts
|
|
165
|
+
var import_querycompiler = __toESM(require("knex/lib/query/querycompiler"));
|
|
166
|
+
var import_isObject = __toESM(require("lodash/isObject"));
|
|
167
|
+
var import_wrappingFormatter = require("knex/lib/formatter/wrappingFormatter");
|
|
168
|
+
var import_date_fns = require("date-fns");
|
|
169
|
+
var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
170
|
+
_prepInsert(data) {
|
|
171
|
+
if ((0, import_isObject.default)(data)) {
|
|
172
|
+
if (data.hasOwnProperty("migration_time")) {
|
|
173
|
+
const parsed = new Date(data.migration_time);
|
|
174
|
+
data.migration_time = (0, import_date_fns.format)(parsed, "yyyy-MM-dd HH:mm:ss");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const isRaw = (0, import_wrappingFormatter.rawOrFn)(
|
|
178
|
+
data,
|
|
179
|
+
void 0,
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
this.builder,
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
this.client,
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
this.bindingsHolder
|
|
186
|
+
);
|
|
187
|
+
if (isRaw)
|
|
188
|
+
return isRaw;
|
|
189
|
+
let columns = [];
|
|
190
|
+
const values = [];
|
|
191
|
+
if (!Array.isArray(data))
|
|
192
|
+
data = data ? [data] : [];
|
|
193
|
+
let i = -1;
|
|
194
|
+
while (++i < data.length) {
|
|
195
|
+
if (data[i] == null)
|
|
196
|
+
break;
|
|
197
|
+
if (i === 0)
|
|
198
|
+
columns = Object.keys(data[i]).sort();
|
|
199
|
+
const row = new Array(columns.length);
|
|
200
|
+
const keys = Object.keys(data[i]);
|
|
201
|
+
let j = -1;
|
|
202
|
+
while (++j < keys.length) {
|
|
203
|
+
const key = keys[j];
|
|
204
|
+
let idx = columns.indexOf(key);
|
|
205
|
+
if (idx === -1) {
|
|
206
|
+
columns = columns.concat(key).sort();
|
|
207
|
+
idx = columns.indexOf(key);
|
|
208
|
+
let k = -1;
|
|
209
|
+
while (++k < values.length) {
|
|
210
|
+
values[k].splice(idx, 0, void 0);
|
|
211
|
+
}
|
|
212
|
+
row.splice(idx, 0, void 0);
|
|
213
|
+
}
|
|
214
|
+
row[idx] = data[i][key];
|
|
215
|
+
}
|
|
216
|
+
values.push(row);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
columns,
|
|
220
|
+
values
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var ibmi_querycompiler_default = IBMiQueryCompiler;
|
|
225
|
+
|
|
226
|
+
// src/index.ts
|
|
227
|
+
var DB2Client = class extends import_knex.default.Client {
|
|
228
|
+
constructor(config) {
|
|
229
|
+
super(config);
|
|
230
|
+
this.driverName = "odbc";
|
|
231
|
+
if (this.dialect && !this.config.client) {
|
|
232
|
+
this.logger.warn(
|
|
233
|
+
`Using 'this.dialect' to identify the client is deprecated and support for it will be removed in the future. Please use configuration option 'client' instead.`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
const dbClient = this.config.client || this.dialect;
|
|
237
|
+
if (!dbClient) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`knex: Required configuration option 'client' is missing.`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
if (config.version) {
|
|
243
|
+
this.version = config.version;
|
|
244
|
+
}
|
|
245
|
+
if (this.driverName && config.connection) {
|
|
246
|
+
this.initializeDriver();
|
|
247
|
+
if (!config.pool || config.pool && config.pool.max !== 0) {
|
|
248
|
+
this.initializePool(config);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
this.valueForUndefined = this.raw("DEFAULT");
|
|
252
|
+
if (config.useNullAsDefault) {
|
|
253
|
+
this.valueForUndefined = null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
_driver() {
|
|
257
|
+
return odbc;
|
|
258
|
+
}
|
|
259
|
+
wrapIdentifierImpl(value) {
|
|
260
|
+
if (value.includes("knex_migrations")) {
|
|
261
|
+
return value.toUpperCase();
|
|
262
|
+
}
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
265
|
+
printDebug(message) {
|
|
266
|
+
if (process.env.DEBUG === "true") {
|
|
267
|
+
this.logger.debug(message);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Get a raw connection, called by the pool manager whenever a new
|
|
271
|
+
// connection needs to be added to the pool.
|
|
272
|
+
async acquireRawConnection() {
|
|
273
|
+
this.printDebug("acquiring raw connection");
|
|
274
|
+
const connectionConfig = this.config.connection;
|
|
275
|
+
console3.log(this._getConnectionString(connectionConfig));
|
|
276
|
+
return await this.driver.pool(this._getConnectionString(connectionConfig));
|
|
277
|
+
}
|
|
278
|
+
// Used to explicitly close a connection, called internally by the pool manager
|
|
279
|
+
// when a connection times out or the pool is shutdown.
|
|
280
|
+
async destroyRawConnection(connection) {
|
|
281
|
+
console3.log("destroy connection");
|
|
282
|
+
return await connection.close();
|
|
283
|
+
}
|
|
284
|
+
_getConnectionString(connectionConfig) {
|
|
285
|
+
const connectionStringParams = connectionConfig.connectionStringParams || {};
|
|
286
|
+
const connectionStringExtension = Object.keys(
|
|
287
|
+
connectionStringParams
|
|
288
|
+
).reduce((result, key) => {
|
|
289
|
+
const value = connectionStringParams[key];
|
|
290
|
+
return `${result}${key}=${value};`;
|
|
291
|
+
}, "");
|
|
292
|
+
return `${`DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};`}${connectionStringExtension}`;
|
|
293
|
+
}
|
|
294
|
+
// Runs the query on the specified connection, providing the bindings
|
|
295
|
+
// and any other necessary prep work.
|
|
296
|
+
async _query(pool, obj) {
|
|
297
|
+
if (!obj || typeof obj == "string")
|
|
298
|
+
obj = { sql: obj };
|
|
299
|
+
const method = (obj.hasOwnProperty("method") && obj.method !== "raw" ? obj.method : obj.sql.split(" ")[0]).toLowerCase();
|
|
300
|
+
obj.sqlMethod = method;
|
|
301
|
+
if (method === "select" || method === "first" || method === "pluck") {
|
|
302
|
+
const rows = await pool.query(obj.sql, obj.bindings);
|
|
303
|
+
if (rows) {
|
|
304
|
+
obj.response = { rows, rowCount: rows.length };
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
try {
|
|
308
|
+
const connection = await pool.connect();
|
|
309
|
+
const statement = await connection.createStatement();
|
|
310
|
+
await statement.prepare(obj.sql);
|
|
311
|
+
if (obj.bindings) {
|
|
312
|
+
await statement.bind(obj.bindings);
|
|
313
|
+
}
|
|
314
|
+
const result = await statement.execute();
|
|
315
|
+
obj.response = { rows: [result.count], rowCount: result.count };
|
|
316
|
+
} catch (err) {
|
|
317
|
+
console3.error(err);
|
|
318
|
+
throw new Error(err);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
console3.log({ obj });
|
|
322
|
+
return obj;
|
|
323
|
+
}
|
|
324
|
+
transaction(container, config, outerTx) {
|
|
325
|
+
return new ibmi_transaction_default(this, ...arguments);
|
|
326
|
+
}
|
|
327
|
+
schemaCompiler() {
|
|
328
|
+
return new ibmi_compiler_default(this, ...arguments);
|
|
329
|
+
}
|
|
330
|
+
tableCompiler() {
|
|
331
|
+
return new ibmi_tablecompiler_default(this, ...arguments);
|
|
332
|
+
}
|
|
333
|
+
columnCompiler() {
|
|
334
|
+
return new ibmi_columncompiler_default(this, ...arguments);
|
|
335
|
+
}
|
|
336
|
+
queryCompiler() {
|
|
337
|
+
return new ibmi_querycompiler_default(this, ...arguments);
|
|
338
|
+
}
|
|
339
|
+
processResponse(obj, runner) {
|
|
340
|
+
if (obj === null)
|
|
341
|
+
return null;
|
|
342
|
+
const resp = obj.response;
|
|
343
|
+
const method = obj.sqlMethod;
|
|
344
|
+
const { rows } = resp;
|
|
345
|
+
if (obj.output)
|
|
346
|
+
return obj.output.call(runner, resp);
|
|
347
|
+
switch (method) {
|
|
348
|
+
case "select":
|
|
349
|
+
case "pluck":
|
|
350
|
+
case "first": {
|
|
351
|
+
if (method === "pluck")
|
|
352
|
+
return rows.map(obj.pluck);
|
|
353
|
+
return method === "first" ? rows[0] : rows;
|
|
354
|
+
}
|
|
355
|
+
case "insert":
|
|
356
|
+
case "del":
|
|
357
|
+
case "delete":
|
|
358
|
+
case "update":
|
|
359
|
+
case "counter":
|
|
360
|
+
return resp.rowCount;
|
|
361
|
+
default:
|
|
362
|
+
return resp;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var DB2Dialect = DB2Client;
|
|
367
|
+
var src_default = DB2Client;
|
|
368
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
369
|
+
0 && (module.exports = {
|
|
370
|
+
DB2Dialect
|
|
371
|
+
});
|