@bdkinc/knex-ibmi 0.0.4 → 0.0.5
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 +1 -0
- package/dist/index.js +37 -22
- package/dist/index.mjs +37 -22
- package/package.json +1 -1
- package/src/execution/ibmi-transaction.ts +0 -1
- package/src/index.ts +6 -16
- package/src/query/ibmi-querycompiler.ts +1 -0
- package/src/schema/ibmi-compiler.ts +1 -1
- package/src/schema/ibmi-tablecompiler.ts +43 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Currently, this dialect has limited functionality compared to the Knex built-in
|
|
|
19
19
|
- No streaming support
|
|
20
20
|
- Possibly other missing functionality
|
|
21
21
|
- Uses a pool for all connections
|
|
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
23
|
|
|
23
24
|
## Installing
|
|
24
25
|
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
37
37
|
var process = __toESM(require("process"));
|
|
38
38
|
var import_knex = __toESM(require("knex"));
|
|
39
39
|
var odbc = __toESM(require("odbc"));
|
|
40
|
-
var
|
|
40
|
+
var console2 = __toESM(require("console"));
|
|
41
41
|
|
|
42
42
|
// src/schema/ibmi-compiler.ts
|
|
43
43
|
var import_compiler = __toESM(require("knex/lib/schema/compiler"));
|
|
@@ -55,7 +55,7 @@ var IBMiSchemaCompiler = class extends import_compiler.default {
|
|
|
55
55
|
// @ts-ignore
|
|
56
56
|
this.bindingsHolder
|
|
57
57
|
);
|
|
58
|
-
const bindings = [tableName
|
|
58
|
+
const bindings = [tableName];
|
|
59
59
|
let sql = `SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE TYPE = 'T' AND TABLE_NAME = ${formattedTable}`;
|
|
60
60
|
if (this.schema) {
|
|
61
61
|
sql += " AND TABLE_SCHEMA = ?";
|
|
@@ -86,6 +86,7 @@ var ibmi_compiler_default = IBMiSchemaCompiler;
|
|
|
86
86
|
|
|
87
87
|
// src/schema/ibmi-tablecompiler.ts
|
|
88
88
|
var import_tablecompiler = __toESM(require("knex/lib/schema/tablecompiler"));
|
|
89
|
+
var import_isObject = __toESM(require("lodash/isObject"));
|
|
89
90
|
var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
90
91
|
createQuery(columns, ifNot, like) {
|
|
91
92
|
let createStatement = ifNot ? `if object_id('${this.tableName()}', 'U') is null ` : "";
|
|
@@ -106,6 +107,29 @@ var IBMiTableCompiler = class extends import_tablecompiler.default {
|
|
|
106
107
|
this.addColumns(columns, this.addColumnsPrefix);
|
|
107
108
|
}
|
|
108
109
|
}
|
|
110
|
+
dropUnique(columns, indexName) {
|
|
111
|
+
indexName = indexName ? this.formatter.wrap(indexName) : this._indexCommand("unique", this.tableNameRaw, columns);
|
|
112
|
+
this.pushQuery(`drop index ${indexName}`);
|
|
113
|
+
}
|
|
114
|
+
unique(columns, indexName) {
|
|
115
|
+
let deferrable;
|
|
116
|
+
let predicate;
|
|
117
|
+
if ((0, import_isObject.default)(indexName)) {
|
|
118
|
+
({ indexName, deferrable, predicate } = indexName);
|
|
119
|
+
}
|
|
120
|
+
if (deferrable && deferrable !== "not deferrable") {
|
|
121
|
+
this.client.logger.warn(
|
|
122
|
+
`IBMi: unique index \`${indexName}\` will not be deferrable ${deferrable}.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
indexName = indexName ? this.formatter.wrap(indexName) : this._indexCommand("unique", this.tableNameRaw, columns);
|
|
126
|
+
columns = this.formatter.columnize(columns);
|
|
127
|
+
const predicateQuery = predicate ? " " + this.client.queryCompiler(predicate).where() : "";
|
|
128
|
+
this.pushQuery(
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
`CREATE UNIQUE INDEX ${indexName} ON ${this.tableName()} (${columns})${predicateQuery}`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
109
133
|
// All of the columns to "add" for the query
|
|
110
134
|
addColumns(columns, prefix) {
|
|
111
135
|
prefix = prefix || this.addColumnsPrefix;
|
|
@@ -141,7 +165,6 @@ var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
|
141
165
|
|
|
142
166
|
// src/execution/ibmi-transaction.ts
|
|
143
167
|
var import_transaction = __toESM(require("knex/lib/execution/transaction"));
|
|
144
|
-
var console2 = __toESM(require("console"));
|
|
145
168
|
var IBMiTransaction = class extends import_transaction.default {
|
|
146
169
|
async begin(conn) {
|
|
147
170
|
const connection = await conn.connect();
|
|
@@ -149,7 +172,6 @@ var IBMiTransaction = class extends import_transaction.default {
|
|
|
149
172
|
return connection;
|
|
150
173
|
}
|
|
151
174
|
async rollback(conn) {
|
|
152
|
-
console2.log({ conn });
|
|
153
175
|
const connection = await conn.connect();
|
|
154
176
|
await connection.rollback();
|
|
155
177
|
return connection;
|
|
@@ -163,12 +185,12 @@ var ibmi_transaction_default = IBMiTransaction;
|
|
|
163
185
|
|
|
164
186
|
// src/query/ibmi-querycompiler.ts
|
|
165
187
|
var import_querycompiler = __toESM(require("knex/lib/query/querycompiler"));
|
|
166
|
-
var
|
|
188
|
+
var import_isObject2 = __toESM(require("lodash/isObject"));
|
|
167
189
|
var import_wrappingFormatter = require("knex/lib/formatter/wrappingFormatter");
|
|
168
190
|
var import_date_fns = require("date-fns");
|
|
169
191
|
var IBMiQueryCompiler = class extends import_querycompiler.default {
|
|
170
192
|
_prepInsert(data) {
|
|
171
|
-
if ((0,
|
|
193
|
+
if ((0, import_isObject2.default)(data)) {
|
|
172
194
|
if (data.hasOwnProperty("migration_time")) {
|
|
173
195
|
const parsed = new Date(data.migration_time);
|
|
174
196
|
data.migration_time = (0, import_date_fns.format)(parsed, "yyyy-MM-dd HH:mm:ss");
|
|
@@ -256,12 +278,6 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
256
278
|
_driver() {
|
|
257
279
|
return odbc;
|
|
258
280
|
}
|
|
259
|
-
wrapIdentifierImpl(value) {
|
|
260
|
-
if (value.includes("knex_migrations")) {
|
|
261
|
-
return value.toUpperCase();
|
|
262
|
-
}
|
|
263
|
-
return value;
|
|
264
|
-
}
|
|
265
281
|
printDebug(message) {
|
|
266
282
|
if (process.env.DEBUG === "true") {
|
|
267
283
|
this.logger.debug(message);
|
|
@@ -272,13 +288,13 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
272
288
|
async acquireRawConnection() {
|
|
273
289
|
this.printDebug("acquiring raw connection");
|
|
274
290
|
const connectionConfig = this.config.connection;
|
|
275
|
-
|
|
291
|
+
console2.log(this._getConnectionString(connectionConfig));
|
|
276
292
|
return await this.driver.pool(this._getConnectionString(connectionConfig));
|
|
277
293
|
}
|
|
278
294
|
// Used to explicitly close a connection, called internally by the pool manager
|
|
279
295
|
// when a connection times out or the pool is shutdown.
|
|
280
296
|
async destroyRawConnection(connection) {
|
|
281
|
-
|
|
297
|
+
console2.log("destroy connection");
|
|
282
298
|
return await connection.close();
|
|
283
299
|
}
|
|
284
300
|
_getConnectionString(connectionConfig) {
|
|
@@ -312,13 +328,12 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
312
328
|
await statement.bind(obj.bindings);
|
|
313
329
|
}
|
|
314
330
|
const result = await statement.execute();
|
|
315
|
-
obj.response = {
|
|
331
|
+
obj.response = { rowCount: result.count };
|
|
316
332
|
} catch (err) {
|
|
317
|
-
|
|
333
|
+
console2.error(err);
|
|
318
334
|
throw new Error(err);
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
|
-
console3.log({ obj });
|
|
322
337
|
return obj;
|
|
323
338
|
}
|
|
324
339
|
transaction(container, config, outerTx) {
|
|
@@ -342,16 +357,16 @@ var DB2Client = class extends import_knex.default.Client {
|
|
|
342
357
|
const resp = obj.response;
|
|
343
358
|
const method = obj.sqlMethod;
|
|
344
359
|
const { rows } = resp;
|
|
360
|
+
console2.log({ method, rows });
|
|
345
361
|
if (obj.output)
|
|
346
362
|
return obj.output.call(runner, resp);
|
|
347
363
|
switch (method) {
|
|
348
364
|
case "select":
|
|
365
|
+
return rows;
|
|
349
366
|
case "pluck":
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return method === "first" ? rows[0] : rows;
|
|
354
|
-
}
|
|
367
|
+
return rows.map(obj.pluck);
|
|
368
|
+
case "first":
|
|
369
|
+
return rows[0];
|
|
355
370
|
case "insert":
|
|
356
371
|
case "del":
|
|
357
372
|
case "delete":
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as process from "process";
|
|
3
3
|
import knex from "knex";
|
|
4
4
|
import * as odbc from "odbc";
|
|
5
|
-
import * as
|
|
5
|
+
import * as console2 from "console";
|
|
6
6
|
|
|
7
7
|
// src/schema/ibmi-compiler.ts
|
|
8
8
|
import SchemaCompiler from "knex/lib/schema/compiler";
|
|
@@ -20,7 +20,7 @@ var IBMiSchemaCompiler = class extends SchemaCompiler {
|
|
|
20
20
|
// @ts-ignore
|
|
21
21
|
this.bindingsHolder
|
|
22
22
|
);
|
|
23
|
-
const bindings = [tableName
|
|
23
|
+
const bindings = [tableName];
|
|
24
24
|
let sql = `SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE TYPE = 'T' AND TABLE_NAME = ${formattedTable}`;
|
|
25
25
|
if (this.schema) {
|
|
26
26
|
sql += " AND TABLE_SCHEMA = ?";
|
|
@@ -51,6 +51,7 @@ var ibmi_compiler_default = IBMiSchemaCompiler;
|
|
|
51
51
|
|
|
52
52
|
// src/schema/ibmi-tablecompiler.ts
|
|
53
53
|
import TableCompiler from "knex/lib/schema/tablecompiler";
|
|
54
|
+
import isObject from "lodash/isObject";
|
|
54
55
|
var IBMiTableCompiler = class extends TableCompiler {
|
|
55
56
|
createQuery(columns, ifNot, like) {
|
|
56
57
|
let createStatement = ifNot ? `if object_id('${this.tableName()}', 'U') is null ` : "";
|
|
@@ -71,6 +72,29 @@ var IBMiTableCompiler = class extends TableCompiler {
|
|
|
71
72
|
this.addColumns(columns, this.addColumnsPrefix);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
dropUnique(columns, indexName) {
|
|
76
|
+
indexName = indexName ? this.formatter.wrap(indexName) : this._indexCommand("unique", this.tableNameRaw, columns);
|
|
77
|
+
this.pushQuery(`drop index ${indexName}`);
|
|
78
|
+
}
|
|
79
|
+
unique(columns, indexName) {
|
|
80
|
+
let deferrable;
|
|
81
|
+
let predicate;
|
|
82
|
+
if (isObject(indexName)) {
|
|
83
|
+
({ indexName, deferrable, predicate } = indexName);
|
|
84
|
+
}
|
|
85
|
+
if (deferrable && deferrable !== "not deferrable") {
|
|
86
|
+
this.client.logger.warn(
|
|
87
|
+
`IBMi: unique index \`${indexName}\` will not be deferrable ${deferrable}.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
indexName = indexName ? this.formatter.wrap(indexName) : this._indexCommand("unique", this.tableNameRaw, columns);
|
|
91
|
+
columns = this.formatter.columnize(columns);
|
|
92
|
+
const predicateQuery = predicate ? " " + this.client.queryCompiler(predicate).where() : "";
|
|
93
|
+
this.pushQuery(
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
`CREATE UNIQUE INDEX ${indexName} ON ${this.tableName()} (${columns})${predicateQuery}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
74
98
|
// All of the columns to "add" for the query
|
|
75
99
|
addColumns(columns, prefix) {
|
|
76
100
|
prefix = prefix || this.addColumnsPrefix;
|
|
@@ -106,7 +130,6 @@ var ibmi_columncompiler_default = IBMiColumnCompiler;
|
|
|
106
130
|
|
|
107
131
|
// src/execution/ibmi-transaction.ts
|
|
108
132
|
import Transaction from "knex/lib/execution/transaction";
|
|
109
|
-
import * as console2 from "console";
|
|
110
133
|
var IBMiTransaction = class extends Transaction {
|
|
111
134
|
async begin(conn) {
|
|
112
135
|
const connection = await conn.connect();
|
|
@@ -114,7 +137,6 @@ var IBMiTransaction = class extends Transaction {
|
|
|
114
137
|
return connection;
|
|
115
138
|
}
|
|
116
139
|
async rollback(conn) {
|
|
117
|
-
console2.log({ conn });
|
|
118
140
|
const connection = await conn.connect();
|
|
119
141
|
await connection.rollback();
|
|
120
142
|
return connection;
|
|
@@ -128,12 +150,12 @@ var ibmi_transaction_default = IBMiTransaction;
|
|
|
128
150
|
|
|
129
151
|
// src/query/ibmi-querycompiler.ts
|
|
130
152
|
import QueryCompiler from "knex/lib/query/querycompiler";
|
|
131
|
-
import
|
|
153
|
+
import isObject2 from "lodash/isObject";
|
|
132
154
|
import { rawOrFn as rawOrFn_ } from "knex/lib/formatter/wrappingFormatter";
|
|
133
155
|
import { format } from "date-fns";
|
|
134
156
|
var IBMiQueryCompiler = class extends QueryCompiler {
|
|
135
157
|
_prepInsert(data) {
|
|
136
|
-
if (
|
|
158
|
+
if (isObject2(data)) {
|
|
137
159
|
if (data.hasOwnProperty("migration_time")) {
|
|
138
160
|
const parsed = new Date(data.migration_time);
|
|
139
161
|
data.migration_time = format(parsed, "yyyy-MM-dd HH:mm:ss");
|
|
@@ -221,12 +243,6 @@ var DB2Client = class extends knex.Client {
|
|
|
221
243
|
_driver() {
|
|
222
244
|
return odbc;
|
|
223
245
|
}
|
|
224
|
-
wrapIdentifierImpl(value) {
|
|
225
|
-
if (value.includes("knex_migrations")) {
|
|
226
|
-
return value.toUpperCase();
|
|
227
|
-
}
|
|
228
|
-
return value;
|
|
229
|
-
}
|
|
230
246
|
printDebug(message) {
|
|
231
247
|
if (process.env.DEBUG === "true") {
|
|
232
248
|
this.logger.debug(message);
|
|
@@ -237,13 +253,13 @@ var DB2Client = class extends knex.Client {
|
|
|
237
253
|
async acquireRawConnection() {
|
|
238
254
|
this.printDebug("acquiring raw connection");
|
|
239
255
|
const connectionConfig = this.config.connection;
|
|
240
|
-
|
|
256
|
+
console2.log(this._getConnectionString(connectionConfig));
|
|
241
257
|
return await this.driver.pool(this._getConnectionString(connectionConfig));
|
|
242
258
|
}
|
|
243
259
|
// Used to explicitly close a connection, called internally by the pool manager
|
|
244
260
|
// when a connection times out or the pool is shutdown.
|
|
245
261
|
async destroyRawConnection(connection) {
|
|
246
|
-
|
|
262
|
+
console2.log("destroy connection");
|
|
247
263
|
return await connection.close();
|
|
248
264
|
}
|
|
249
265
|
_getConnectionString(connectionConfig) {
|
|
@@ -277,13 +293,12 @@ var DB2Client = class extends knex.Client {
|
|
|
277
293
|
await statement.bind(obj.bindings);
|
|
278
294
|
}
|
|
279
295
|
const result = await statement.execute();
|
|
280
|
-
obj.response = {
|
|
296
|
+
obj.response = { rowCount: result.count };
|
|
281
297
|
} catch (err) {
|
|
282
|
-
|
|
298
|
+
console2.error(err);
|
|
283
299
|
throw new Error(err);
|
|
284
300
|
}
|
|
285
301
|
}
|
|
286
|
-
console3.log({ obj });
|
|
287
302
|
return obj;
|
|
288
303
|
}
|
|
289
304
|
transaction(container, config, outerTx) {
|
|
@@ -307,16 +322,16 @@ var DB2Client = class extends knex.Client {
|
|
|
307
322
|
const resp = obj.response;
|
|
308
323
|
const method = obj.sqlMethod;
|
|
309
324
|
const { rows } = resp;
|
|
325
|
+
console2.log({ method, rows });
|
|
310
326
|
if (obj.output)
|
|
311
327
|
return obj.output.call(runner, resp);
|
|
312
328
|
switch (method) {
|
|
313
329
|
case "select":
|
|
330
|
+
return rows;
|
|
314
331
|
case "pluck":
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return method === "first" ? rows[0] : rows;
|
|
319
|
-
}
|
|
332
|
+
return rows.map(obj.pluck);
|
|
333
|
+
case "first":
|
|
334
|
+
return rows[0];
|
|
320
335
|
case "insert":
|
|
321
336
|
case "del":
|
|
322
337
|
case "delete":
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ import QueryCompiler from "./query/ibmi-querycompiler";
|
|
|
12
12
|
class DB2Client extends knex.Client {
|
|
13
13
|
constructor(config) {
|
|
14
14
|
super(config);
|
|
15
|
-
|
|
16
15
|
this.driverName = "odbc";
|
|
17
16
|
|
|
18
17
|
if (this.dialect && !this.config.client) {
|
|
@@ -49,15 +48,6 @@ class DB2Client extends knex.Client {
|
|
|
49
48
|
return odbc;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
wrapIdentifierImpl(value: any) {
|
|
53
|
-
// override default wrapper ("). we don't want to use it since
|
|
54
|
-
// it makes identifiers case-sensitive in DB2
|
|
55
|
-
if (value.includes("knex_migrations")) {
|
|
56
|
-
return value.toUpperCase();
|
|
57
|
-
}
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
51
|
printDebug(message: string) {
|
|
62
52
|
if (process.env.DEBUG === "true") {
|
|
63
53
|
// @ts-ignore
|
|
@@ -128,13 +118,12 @@ class DB2Client extends knex.Client {
|
|
|
128
118
|
await statement.bind(obj.bindings);
|
|
129
119
|
}
|
|
130
120
|
const result = await statement.execute();
|
|
131
|
-
obj.response = {
|
|
121
|
+
obj.response = { rowCount: result.count };
|
|
132
122
|
} catch (err: any) {
|
|
133
123
|
console.error(err);
|
|
134
124
|
throw new Error(err);
|
|
135
125
|
}
|
|
136
126
|
}
|
|
137
|
-
console.log({ obj });
|
|
138
127
|
|
|
139
128
|
return obj;
|
|
140
129
|
}
|
|
@@ -171,16 +160,17 @@ class DB2Client extends knex.Client {
|
|
|
171
160
|
const resp = obj.response;
|
|
172
161
|
const method = obj.sqlMethod;
|
|
173
162
|
const { rows } = resp;
|
|
163
|
+
console.log({ method, rows });
|
|
174
164
|
|
|
175
165
|
if (obj.output) return obj.output.call(runner, resp);
|
|
176
166
|
|
|
177
167
|
switch (method) {
|
|
178
168
|
case "select":
|
|
169
|
+
return rows;
|
|
179
170
|
case "pluck":
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return
|
|
183
|
-
}
|
|
171
|
+
return rows.map(obj.pluck);
|
|
172
|
+
case "first":
|
|
173
|
+
return rows[0];
|
|
184
174
|
case "insert":
|
|
185
175
|
case "del":
|
|
186
176
|
case "delete":
|
|
@@ -2,6 +2,7 @@ import QueryCompiler from "knex/lib/query/querycompiler";
|
|
|
2
2
|
import isObject from "lodash/isObject";
|
|
3
3
|
import { rawOrFn as rawOrFn_ } from "knex/lib/formatter/wrappingFormatter";
|
|
4
4
|
import { format } from "date-fns";
|
|
5
|
+
import * as console from "console";
|
|
5
6
|
|
|
6
7
|
class IBMiQueryCompiler extends QueryCompiler {
|
|
7
8
|
_prepInsert(data) {
|
|
@@ -16,7 +16,7 @@ class IBMiSchemaCompiler extends SchemaCompiler {
|
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
this.bindingsHolder,
|
|
18
18
|
);
|
|
19
|
-
const bindings = [tableName
|
|
19
|
+
const bindings = [tableName];
|
|
20
20
|
let sql =
|
|
21
21
|
`SELECT TABLE_NAME FROM QSYS2.SYSTABLES ` +
|
|
22
22
|
`WHERE TYPE = 'T' AND TABLE_NAME = ${formattedTable}`;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import TableCompiler from "knex/lib/schema/tablecompiler";
|
|
2
|
+
import isObject from "lodash/isObject";
|
|
2
3
|
|
|
3
4
|
class IBMiTableCompiler extends TableCompiler {
|
|
4
5
|
createQuery(columns, ifNot, like) {
|
|
@@ -39,6 +40,48 @@ class IBMiTableCompiler extends TableCompiler {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
dropUnique(columns, indexName) {
|
|
44
|
+
indexName = indexName
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
? this.formatter.wrap(indexName)
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
this.pushQuery(`drop index ${indexName}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
unique(columns, indexName) {
|
|
54
|
+
let deferrable;
|
|
55
|
+
let predicate;
|
|
56
|
+
if (isObject(indexName)) {
|
|
57
|
+
({ indexName, deferrable, predicate } = indexName);
|
|
58
|
+
}
|
|
59
|
+
if (deferrable && deferrable !== 'not deferrable') {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
this.client.logger.warn(
|
|
62
|
+
`IBMi: unique index \`${indexName}\` will not be deferrable ${deferrable}.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
indexName = indexName
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
? this.formatter.wrap(indexName)
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
columns = this.formatter.columnize(columns);
|
|
72
|
+
|
|
73
|
+
const predicateQuery = predicate
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
? ' ' + this.client.queryCompiler(predicate).where()
|
|
76
|
+
: '';
|
|
77
|
+
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
this.pushQuery(
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
`CREATE UNIQUE INDEX ${indexName} ON ${this.tableName()} (${columns})${predicateQuery}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
42
85
|
// All of the columns to "add" for the query
|
|
43
86
|
addColumns(columns, prefix) {
|
|
44
87
|
// @ts-ignore
|