@bdkinc/knex-ibmi 0.0.2 → 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 CHANGED
@@ -1,23 +1,24 @@
1
1
  [![npm version](http://img.shields.io/npm/v/knex-db2.svg)](https://npmjs.org/package/@bdkinc/knex-ibmi)
2
2
 
3
- **Disclaimer: this library is in early stages of development. Use at your own risk. Please submit an issue for any bugs encounter or any questions you have.**
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
 
@@ -109,7 +110,17 @@ If you don't know the name of your installed driver, then look in look in `odbci
109
110
  There you should see an entry like the one below:
110
111
 
111
112
  ```
112
- [IBM i Access ODBC Driver 64-bit] <= driver name enclosed in square brackets
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,466 @@
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 DB2Client = class extends import_knex.default.Client {
41
- constructor(config = {}) {
42
- super(config);
43
- this.driverName = "odbc";
44
- if (this.driverName && config.connection) {
45
- this.initializeDriver();
46
- if (!config.pool || config.pool && config.pool.max !== 0) {
47
- this.initializePool(config);
48
- }
49
- }
50
- }
51
- _driver() {
52
- return odbc;
53
- }
54
- wrapIdentifierImpl(value) {
55
- return value;
56
- }
57
- printDebug(message) {
58
- if (process.env.DEBUG === "true") {
59
- this.logger.debug(message);
60
- }
61
- }
62
- // Get a raw connection, called by the pool manager whenever a new
63
- // connection needs to be added to the pool.
64
- async acquireRawConnection() {
65
- this.printDebug("acquiring raw connection");
66
- const connectionConfig = this.config.connection;
67
- return await this.driver.connect(
68
- this._getConnectionString(connectionConfig)
69
- );
70
- }
71
- // Used to explicitly close a connection, called internally by the pool manager
72
- // when a connection times out or the pool is shutdown.
73
- async destroyRawConnection(connection) {
74
- return await connection.close();
75
- }
76
- _getConnectionString(connectionConfig = {}) {
77
- const connectionStringParams = connectionConfig.connectionStringParams || {};
78
- const connectionStringExtension = Object.keys(
79
- connectionStringParams
80
- ).reduce((result, key) => {
81
- const value = connectionStringParams[key];
82
- return `${result}${key}=${value};`;
83
- }, "");
84
- return `${`DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};`}${connectionStringExtension}`;
85
- }
86
- // Runs the query on the specified connection, providing the bindings
87
- // and any other necessary prep work.
88
- async _query(connection, obj) {
89
- if (!obj || typeof obj == "string")
90
- obj = { sql: obj };
91
- const method = (obj.method !== "raw" ? obj.method : obj.sql.split(" ")[0]).toLowerCase();
92
- obj.sqlMethod = method;
93
- if (method === "select" || method === "first" || method === "pluck") {
94
- const rows = await connection.query(obj.sql, obj.bindings);
95
- if (rows) {
96
- obj.response = { rows, rowCount: rows.length };
97
- }
98
- return obj;
99
- }
100
- const statement = await connection.createStatement();
101
- await statement.prepare(obj.sql);
102
- await statement.bind(obj.bindings);
103
- obj.response = await statement.execute();
104
- return obj;
105
- }
106
- processResponse(obj, runner) {
107
- if (obj === null)
108
- return null;
109
- const resp = obj.response;
110
- const method = obj.sqlMethod;
111
- const { rows } = resp;
112
- if (obj.output)
113
- return obj.output.call(runner, resp);
114
- switch (method) {
115
- case "select":
116
- case "pluck":
117
- case "first": {
118
- if (method === "pluck")
119
- return rows.map(obj.pluck);
120
- return method === "first" ? rows[0] : rows;
121
- }
122
- case "insert":
123
- case "del":
124
- case "delete":
125
- case "update":
126
- case "counter":
127
- return resp.rowCount;
128
- default:
129
- return resp;
130
- }
131
- }
132
- };
133
- var DB2Dialect = DB2Client;
134
- var src_default = DB2Client;
135
- // Annotate the CommonJS export names for ESM import in node:
136
- 0 && (module.exports = {
137
- DB2Dialect
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 console5 = __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
+ prefixedTableName(this.schema, tableName),
52
+ this.builder,
53
+ this.bindingsHolder
54
+ );
55
+ const bindings = [tableName.toUpperCase()];
56
+ let sql = `SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE TYPE = 'T' AND TABLE_NAME = ${formattedTable}`;
57
+ if (this.schema) {
58
+ sql += " AND TABLE_SCHEMA = ?";
59
+ bindings.push(this.schema);
60
+ }
61
+ this.pushQuery({
62
+ sql,
63
+ bindings,
64
+ output: (resp) => {
65
+ return resp.rowCount > 0;
66
+ }
67
+ });
68
+ }
69
+ toSQL() {
70
+ const sequence = this.builder._sequence;
71
+ for (let i = 0, l = sequence.length; i < l; i++) {
72
+ const query = sequence[i];
73
+ console.log(query.method, query);
74
+ this[query.method].apply(this, query.args);
75
+ }
76
+ return this.sequence;
77
+ }
78
+ };
79
+ function prefixedTableName(prefix, table) {
80
+ return prefix ? `${prefix}.${table}` : table;
81
+ }
82
+ var ibmi_compiler_default = IBMiSchemaCompiler;
83
+
84
+ // src/schema/ibmi-tablecompiler.ts
85
+ var import_tablecompiler = __toESM(require("knex/lib/schema/tablecompiler"));
86
+ var IBMiTableCompiler = class extends import_tablecompiler.default {
87
+ constructor(client, tableBuilder) {
88
+ super(client, tableBuilder);
89
+ }
90
+ unique(columns, indexName) {
91
+ let deferrable;
92
+ let useConstraint = false;
93
+ let predicate;
94
+ if (typeof indexName === "object") {
95
+ ({ indexName, deferrable, useConstraint, predicate } = indexName);
96
+ }
97
+ if (deferrable && deferrable !== "not deferrable") {
98
+ this.client.logger.warn(
99
+ `ibmi: unique index [${indexName}] will not be deferrable ${deferrable} because mssql does not support deferred constraints.`
100
+ );
101
+ }
102
+ if (useConstraint && predicate) {
103
+ throw new Error("ibmi cannot create constraint with predicate");
104
+ }
105
+ indexName = indexName ? this.formatter.wrap(indexName) : this._indexCommand("unique", this.tableNameRaw, columns);
106
+ if (!Array.isArray(columns)) {
107
+ columns = [columns];
108
+ }
109
+ if (useConstraint) {
110
+ this.pushQuery(
111
+ `ALTER TABLE ${this.tableName()} ADD CONSTRAINT ${indexName} UNIQUE (${this.formatter.columnize(
112
+ columns
113
+ )})`
114
+ );
115
+ } else {
116
+ const predicateQuery = predicate ? " " + this.client.queryCompiler(predicate).where() : " WHERE " + columns.map((column) => this.formatter.columnize(column) + " IS NOT NULL").join(" AND ");
117
+ this.pushQuery(
118
+ `CREATE UNIQUE INDEX ${indexName} ON ${this.tableName()} (${this.formatter.columnize(
119
+ columns
120
+ )})${predicateQuery}`
121
+ );
122
+ }
123
+ }
124
+ createQuery(columns, ifNot, like) {
125
+ let createStatement = ifNot ? `if object_id('${this.tableName()}', 'U') is null ` : "";
126
+ if (like) {
127
+ createStatement += `SELECT * INTO ${this.tableName()} FROM ${this.tableNameLike()} WHERE 0=1`;
128
+ } else {
129
+ createStatement += "CREATE TABLE " + this.tableName() + (this._formatting ? " (\n " : " (") + columns.sql.join(this._formatting ? ",\n " : ", ") + this._addChecks() + ")";
130
+ }
131
+ this.pushQuery(createStatement);
132
+ if (this.single.comment) {
133
+ this.comment(this.single.comment);
134
+ }
135
+ if (like) {
136
+ this.addColumns(columns, this.addColumnsPrefix);
137
+ }
138
+ }
139
+ // All of the columns to "add" for the query
140
+ addColumns(columns, prefix) {
141
+ prefix = prefix || this.addColumnsPrefix;
142
+ if (columns.sql.length > 0) {
143
+ const columnSql = columns.sql.map((column) => {
144
+ return prefix + column;
145
+ });
146
+ this.pushQuery({
147
+ sql: (this.lowerCase ? "alter table " : "ALTER TABLE ") + this.tableName() + " " + columnSql.join(" "),
148
+ bindings: columns.bindings
149
+ });
150
+ }
151
+ }
152
+ async commit(conn, value) {
153
+ return await conn.commit();
154
+ }
155
+ };
156
+ var ibmi_tablecompiler_default = IBMiTableCompiler;
157
+
158
+ // src/schema/ibmi-columncompiler.ts
159
+ var import_columncompiler = __toESM(require("knex/lib/schema/columncompiler"));
160
+ var console2 = __toESM(require("console"));
161
+ var IBMiColumnCompiler = class extends import_columncompiler.default {
162
+ constructor(client, tableCompiler, columnBuilder) {
163
+ super(client, tableCompiler, columnBuilder);
164
+ }
165
+ increments(options = { primaryKey: true }) {
166
+ return "int not null generated always as identity (start with 1, increment by 1)" + (this.tableCompiler._canBeAddPrimaryKey(options) ? " primary key" : "");
167
+ }
168
+ datetime(withoutTz = false, precision) {
169
+ let useTz;
170
+ if (isObject(withoutTz)) {
171
+ ({ useTz, precision } = withoutTz);
172
+ } else {
173
+ useTz = !withoutTz;
174
+ }
175
+ useTz = typeof useTz === "boolean" ? useTz : true;
176
+ precision = precision !== void 0 && precision !== null ? "(" + precision + ")" : "";
177
+ console2.log(useTz, precision);
178
+ return `${useTz ? "timestamptz" : "timestamp"}${precision}`;
179
+ }
180
+ };
181
+ var ibmi_columncompiler_default = IBMiColumnCompiler;
182
+
183
+ // src/execution/ibmi-transaction.ts
184
+ var import_transaction = __toESM(require("knex/lib/execution/transaction"));
185
+ var console3 = __toESM(require("console"));
186
+ var IBMiTransaction = class extends import_transaction.default {
187
+ async begin(conn) {
188
+ const connection = await conn.connect();
189
+ await connection.beginTransaction();
190
+ return connection;
191
+ }
192
+ async rollback(conn) {
193
+ console3.log({ conn });
194
+ const connection = await conn.connect();
195
+ await connection.rollback();
196
+ return connection;
197
+ }
198
+ async commit(conn) {
199
+ await conn.commit();
200
+ return conn;
201
+ }
202
+ };
203
+ var ibmi_transaction_default = IBMiTransaction;
204
+
205
+ // src/query/ibmi-querycompiler.ts
206
+ var import_querycompiler = __toESM(require("knex/lib/query/querycompiler"));
207
+ var import_has = __toESM(require("lodash/has"));
208
+ var import_isEmpty = __toESM(require("lodash/isEmpty"));
209
+ var import_omitBy = __toESM(require("lodash/omitBy"));
210
+ var import_isObject = __toESM(require("lodash/isObject"));
211
+ var import_wrappingFormatter = require("knex/lib/formatter/wrappingFormatter");
212
+ var import_date_fns = require("date-fns");
213
+ var console4 = __toESM(require("console"));
214
+ var IBMiQueryCompiler = class extends import_querycompiler.default {
215
+ _prepInsert(data) {
216
+ if ((0, import_isObject.default)(data)) {
217
+ console4.log("data is object", data);
218
+ if (data.hasOwnProperty("migration_time")) {
219
+ console4.log("data has migration_time", data.migration_time);
220
+ const parsed = new Date(data.migration_time);
221
+ console4.log(parsed);
222
+ data.migration_time = (0, import_date_fns.format)(parsed, "yyyy-MM-dd HH:mm:ss");
223
+ console4.log(data.migration_time);
224
+ }
225
+ console4.log("data date after change", data);
226
+ }
227
+ const isRaw = (0, import_wrappingFormatter.rawOrFn)(
228
+ data,
229
+ void 0,
230
+ this.builder,
231
+ this.client,
232
+ this.bindingsHolder
233
+ );
234
+ if (isRaw)
235
+ return isRaw;
236
+ let columns = [];
237
+ const values = [];
238
+ if (!Array.isArray(data))
239
+ data = data ? [data] : [];
240
+ let i = -1;
241
+ while (++i < data.length) {
242
+ if (data[i] == null)
243
+ break;
244
+ if (i === 0)
245
+ columns = Object.keys(data[i]).sort();
246
+ const row = new Array(columns.length);
247
+ const keys = Object.keys(data[i]);
248
+ let j = -1;
249
+ while (++j < keys.length) {
250
+ const key = keys[j];
251
+ let idx = columns.indexOf(key);
252
+ if (idx === -1) {
253
+ columns = columns.concat(key).sort();
254
+ idx = columns.indexOf(key);
255
+ let k = -1;
256
+ while (++k < values.length) {
257
+ values[k].splice(idx, 0, void 0);
258
+ }
259
+ row.splice(idx, 0, void 0);
260
+ }
261
+ row[idx] = data[i][key];
262
+ }
263
+ values.push(row);
264
+ }
265
+ return {
266
+ columns,
267
+ values
268
+ };
269
+ }
270
+ _prepUpdate(data = {}) {
271
+ const { counter = {} } = this.single;
272
+ for (const column of Object.keys(counter)) {
273
+ if ((0, import_has.default)(data, column)) {
274
+ this.client.logger.warn(
275
+ `increment/decrement called for a column that has already been specified in main .update() call. Ignoring increment/decrement and using value from .update() call.`
276
+ );
277
+ continue;
278
+ }
279
+ let value = counter[column];
280
+ const symbol = value < 0 ? "-" : "+";
281
+ if (symbol === "-") {
282
+ value = -value;
283
+ }
284
+ data[column] = this.client.raw(`?? ${symbol} ?`, [column, value]);
285
+ }
286
+ data = (0, import_omitBy.default)(data, (value) => typeof value === "undefined");
287
+ const vals = [];
288
+ const columns = Object.keys(data);
289
+ let i = -1;
290
+ while (++i < columns.length) {
291
+ vals.push(
292
+ (0, import_wrappingFormatter.wrap)(
293
+ columns[i],
294
+ void 0,
295
+ this.builder,
296
+ this.client,
297
+ this.bindingsHolder
298
+ ) + " = " + this.client.parameter(
299
+ data[columns[i]],
300
+ this.builder,
301
+ this.bindingsHolder
302
+ )
303
+ );
304
+ }
305
+ if ((0, import_isEmpty.default)(vals)) {
306
+ throw new Error(
307
+ [
308
+ "Empty .update() call detected!",
309
+ "Update data does not contain any values to update.",
310
+ "This will result in a faulty query.",
311
+ this.single.table ? `Table: ${this.single.table}.` : "",
312
+ this.single.update ? `Columns: ${Object.keys(this.single.update)}.` : ""
313
+ ].join(" ")
314
+ );
315
+ }
316
+ return vals;
317
+ }
318
+ };
319
+ var ibmi_querycompiler_default = IBMiQueryCompiler;
320
+
321
+ // src/index.ts
322
+ var DB2Client = class extends import_knex.default.Client {
323
+ constructor(config) {
324
+ super(config);
325
+ this.driverName = "odbc";
326
+ if (this.dialect && !this.config.client) {
327
+ this.logger.warn(
328
+ `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.`
329
+ );
330
+ }
331
+ const dbClient = this.config.client || this.dialect;
332
+ if (!dbClient) {
333
+ throw new Error(
334
+ `knex: Required configuration option 'client' is missing.`
335
+ );
336
+ }
337
+ if (config.version) {
338
+ this.version = config.version;
339
+ }
340
+ if (this.driverName && config.connection) {
341
+ this.initializeDriver();
342
+ if (!config.pool || config.pool && config.pool.max !== 0) {
343
+ this.initializePool(config);
344
+ }
345
+ }
346
+ this.valueForUndefined = this.raw("DEFAULT");
347
+ if (config.useNullAsDefault) {
348
+ this.valueForUndefined = null;
349
+ }
350
+ }
351
+ _driver() {
352
+ return odbc;
353
+ }
354
+ wrapIdentifierImpl(value) {
355
+ if (value.includes("knex_migrations")) {
356
+ return value.toUpperCase();
357
+ }
358
+ return value;
359
+ }
360
+ printDebug(message) {
361
+ if (process.env.DEBUG === "true") {
362
+ this.logger.debug(message);
363
+ }
364
+ }
365
+ // Get a raw connection, called by the pool manager whenever a new
366
+ // connection needs to be added to the pool.
367
+ async acquireRawConnection() {
368
+ this.printDebug("acquiring raw connection");
369
+ const connectionConfig = this.config.connection;
370
+ console5.log(this._getConnectionString(connectionConfig));
371
+ return await this.driver.pool(this._getConnectionString(connectionConfig));
372
+ }
373
+ // Used to explicitly close a connection, called internally by the pool manager
374
+ // when a connection times out or the pool is shutdown.
375
+ async destroyRawConnection(connection) {
376
+ console5.log("destroy connection");
377
+ return await connection.close();
378
+ }
379
+ _getConnectionString(connectionConfig) {
380
+ const connectionStringParams = connectionConfig.connectionStringParams || {};
381
+ const connectionStringExtension = Object.keys(
382
+ connectionStringParams
383
+ ).reduce((result, key) => {
384
+ const value = connectionStringParams[key];
385
+ return `${result}${key}=${value};`;
386
+ }, "");
387
+ return `${`DRIVER=${connectionConfig.driver};SYSTEM=${connectionConfig.host};HOSTNAME=${connectionConfig.host};PORT=${connectionConfig.port};DATABASE=${connectionConfig.database};UID=${connectionConfig.user};PWD=${connectionConfig.password};`}${connectionStringExtension}`;
388
+ }
389
+ // Runs the query on the specified connection, providing the bindings
390
+ // and any other necessary prep work.
391
+ async _query(pool, obj) {
392
+ if (!obj || typeof obj == "string")
393
+ obj = { sql: obj };
394
+ const method = (obj.hasOwnProperty("method") && obj.method !== "raw" ? obj.method : obj.sql.split(" ")[0]).toLowerCase();
395
+ obj.sqlMethod = method;
396
+ if (method === "select" || method === "first" || method === "pluck") {
397
+ const rows = await pool.query(obj.sql, obj.bindings);
398
+ if (rows) {
399
+ obj.response = { rows, rowCount: rows.length };
400
+ }
401
+ } else {
402
+ try {
403
+ const connection = await pool.connect();
404
+ const statement = await connection.createStatement();
405
+ await statement.prepare(obj.sql);
406
+ if (obj.bindings) {
407
+ await statement.bind(obj.bindings);
408
+ }
409
+ const result = await statement.execute();
410
+ obj.response = { rows: [result.count], rowCount: result.count };
411
+ } catch (err) {
412
+ console5.error(err);
413
+ throw new Error(err);
414
+ }
415
+ }
416
+ console5.log({ obj });
417
+ return obj;
418
+ }
419
+ transaction() {
420
+ return new ibmi_transaction_default(this, ...arguments);
421
+ }
422
+ schemaCompiler() {
423
+ return new ibmi_compiler_default(this, ...arguments);
424
+ }
425
+ tableCompiler() {
426
+ return new ibmi_tablecompiler_default(this, ...arguments);
427
+ }
428
+ columnCompiler() {
429
+ return new ibmi_columncompiler_default(this, ...arguments);
430
+ }
431
+ queryCompiler() {
432
+ return new ibmi_querycompiler_default(this, ...arguments);
433
+ }
434
+ processResponse(obj, runner) {
435
+ if (obj === null)
436
+ return null;
437
+ const resp = obj.response;
438
+ const method = obj.sqlMethod;
439
+ const { rows } = resp;
440
+ if (obj.output)
441
+ return obj.output.call(runner, resp);
442
+ switch (method) {
443
+ case "select":
444
+ case "pluck":
445
+ case "first": {
446
+ if (method === "pluck")
447
+ return rows.map(obj.pluck);
448
+ return method === "first" ? rows[0] : rows;
449
+ }
450
+ case "insert":
451
+ case "del":
452
+ case "delete":
453
+ case "update":
454
+ case "counter":
455
+ return resp.rowCount;
456
+ default:
457
+ return resp;
458
+ }
459
+ }
460
+ };
461
+ var DB2Dialect = DB2Client;
462
+ var src_default = DB2Client;
463
+ // Annotate the CommonJS export names for ESM import in node:
464
+ 0 && (module.exports = {
465
+ DB2Dialect
466
+ });