@bdkinc/knex-ibmi 0.0.21 → 0.0.23
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/dist/execution/ibmi-transaction.d.ts +7 -0
- package/dist/execution/ibmi-transaction.js +20 -0
- package/dist/execution/ibmi-transaction.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +217 -0
- package/dist/index.js.map +1 -0
- package/dist/query/ibmi-querycompiler.d.ts +17 -0
- package/dist/query/ibmi-querycompiler.js +226 -0
- package/dist/query/ibmi-querycompiler.js.map +1 -0
- package/dist/schema/ibmi-columncompiler.d.ts +7 -0
- package/dist/schema/ibmi-columncompiler.js +13 -0
- package/dist/schema/ibmi-columncompiler.js.map +1 -0
- package/dist/schema/ibmi-compiler.d.ts +6 -0
- package/dist/schema/ibmi-compiler.js +48 -0
- package/dist/schema/ibmi-compiler.js.map +1 -0
- package/dist/schema/ibmi-tablecompiler.d.ts +9 -0
- package/dist/schema/ibmi-tablecompiler.js +103 -0
- package/dist/schema/ibmi-tablecompiler.js.map +1 -0
- package/package.json +3 -2
- package/src/execution/ibmi-transaction.js +99 -0
- package/src/execution/ibmi-transaction.ts +21 -0
- package/src/index.d.ts +4 -0
- package/src/index.ts +281 -0
- package/src/query/ibmi-querycompiler.js +249 -0
- package/src/query/ibmi-querycompiler.ts +236 -0
- package/src/schema/ibmi-columncompiler.js +33 -0
- package/src/schema/ibmi-columncompiler.ts +14 -0
- package/src/schema/ibmi-compiler.js +67 -0
- package/src/schema/ibmi-compiler.ts +52 -0
- package/src/schema/ibmi-tablecompiler.js +166 -0
- package/src/schema/ibmi-tablecompiler.ts +114 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
var tablecompiler_1 = require("knex/lib/schema/tablecompiler");
|
|
56
|
+
var isObject_1 = require("lodash/isObject");
|
|
57
|
+
var IBMiTableCompiler = /** @class */ (function (_super) {
|
|
58
|
+
__extends(IBMiTableCompiler, _super);
|
|
59
|
+
function IBMiTableCompiler() {
|
|
60
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
61
|
+
}
|
|
62
|
+
IBMiTableCompiler.prototype.createQuery = function (columns, ifNot, like) {
|
|
63
|
+
var createStatement = ifNot
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
? "if object_id('".concat(this.tableName(), "', 'U') is null ")
|
|
66
|
+
: "";
|
|
67
|
+
if (like) {
|
|
68
|
+
// This query copy only columns and not all indexes and keys like other databases.
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
createStatement += "SELECT * INTO ".concat(this.tableName(), " FROM ").concat(this.tableNameLike(), " WHERE 0=1");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
createStatement +=
|
|
74
|
+
"CREATE TABLE " +
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
this.tableName() +
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
(this._formatting ? " (\n " : " (") +
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
columns.sql.join(this._formatting ? ",\n " : ", ") +
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
this._addChecks() +
|
|
83
|
+
")";
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
this.pushQuery(createStatement);
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
if (this.single.comment) {
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
this.comment(this.single.comment);
|
|
91
|
+
}
|
|
92
|
+
if (like) {
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
this.addColumns(columns, this.addColumnsPrefix);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
IBMiTableCompiler.prototype.dropUnique = function (columns, indexName) {
|
|
98
|
+
indexName = indexName
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
? this.formatter.wrap(indexName)
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
this.pushQuery("drop index ".concat(indexName));
|
|
105
|
+
};
|
|
106
|
+
IBMiTableCompiler.prototype.unique = function (columns, indexName) {
|
|
107
|
+
var _a;
|
|
108
|
+
var deferrable;
|
|
109
|
+
var predicate;
|
|
110
|
+
if ((0, isObject_1.default)(indexName)) {
|
|
111
|
+
(_a = indexName, indexName = _a.indexName, deferrable = _a.deferrable, predicate = _a.predicate);
|
|
112
|
+
}
|
|
113
|
+
if (deferrable && deferrable !== 'not deferrable') {
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
this.client.logger.warn("IBMi: unique index `".concat(indexName, "` will not be deferrable ").concat(deferrable, "."));
|
|
116
|
+
}
|
|
117
|
+
indexName = indexName
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
? this.formatter.wrap(indexName)
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
columns = this.formatter.columnize(columns);
|
|
124
|
+
var predicateQuery = predicate
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
? ' ' + this.client.queryCompiler(predicate).where()
|
|
127
|
+
: '';
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
this.pushQuery(
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
"create unique index ".concat(indexName, " on ").concat(this.tableName(), " (").concat(columns, ")").concat(predicateQuery));
|
|
132
|
+
};
|
|
133
|
+
// All of the columns to "add" for the query
|
|
134
|
+
IBMiTableCompiler.prototype.addColumns = function (columns, prefix) {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
prefix = prefix || this.addColumnsPrefix;
|
|
137
|
+
if (columns.sql.length > 0) {
|
|
138
|
+
var columnSql = columns.sql.map(function (column) {
|
|
139
|
+
return prefix + column;
|
|
140
|
+
});
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
this.pushQuery({
|
|
143
|
+
sql:
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
(this.lowerCase ? 'alter table ' : 'ALTER TABLE ') +
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
this.tableName() +
|
|
148
|
+
' ' +
|
|
149
|
+
columnSql.join(' '),
|
|
150
|
+
bindings: columns.bindings,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
IBMiTableCompiler.prototype.commit = function (conn) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, conn.commit()];
|
|
159
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
return IBMiTableCompiler;
|
|
165
|
+
}(tablecompiler_1.default));
|
|
166
|
+
exports.default = IBMiTableCompiler;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import TableCompiler from "knex/lib/schema/tablecompiler";
|
|
3
|
+
import isObject from "lodash/isObject";
|
|
4
|
+
|
|
5
|
+
class IBMiTableCompiler extends TableCompiler {
|
|
6
|
+
createQuery(columns, ifNot, like) {
|
|
7
|
+
let createStatement = ifNot
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
? `if object_id('${this.tableName()}', 'U') is null `
|
|
10
|
+
: "";
|
|
11
|
+
|
|
12
|
+
if (like) {
|
|
13
|
+
// This query copy only columns and not all indexes and keys like other databases.
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
createStatement += `SELECT * INTO ${this.tableName()} FROM ${this.tableNameLike()} WHERE 0=1`;
|
|
16
|
+
} else {
|
|
17
|
+
createStatement +=
|
|
18
|
+
"CREATE TABLE " +
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
this.tableName() +
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
(this._formatting ? " (\n " : " (") +
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
columns.sql.join(this._formatting ? ",\n " : ", ") +
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
this._addChecks() +
|
|
27
|
+
")";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
this.pushQuery(createStatement);
|
|
32
|
+
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
if (this.single.comment) {
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
this.comment(this.single.comment);
|
|
37
|
+
}
|
|
38
|
+
if (like) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
this.addColumns(columns, this.addColumnsPrefix);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dropUnique(columns, indexName) {
|
|
45
|
+
indexName = indexName
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
? this.formatter.wrap(indexName)
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
this.pushQuery(`drop index ${indexName}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
unique(columns, indexName) {
|
|
55
|
+
let deferrable;
|
|
56
|
+
let predicate;
|
|
57
|
+
if (isObject(indexName)) {
|
|
58
|
+
({ indexName, deferrable, predicate } = indexName);
|
|
59
|
+
}
|
|
60
|
+
if (deferrable && deferrable !== 'not deferrable') {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
this.client.logger.warn(
|
|
63
|
+
`IBMi: unique index \`${indexName}\` will not be deferrable ${deferrable}.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
indexName = indexName
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
? this.formatter.wrap(indexName)
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
: this._indexCommand('unique', this.tableNameRaw, columns);
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
columns = this.formatter.columnize(columns);
|
|
73
|
+
|
|
74
|
+
const predicateQuery = predicate
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
? ' ' + this.client.queryCompiler(predicate).where()
|
|
77
|
+
: '';
|
|
78
|
+
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
this.pushQuery(
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
`create unique index ${indexName} on ${this.tableName()} (${columns})${predicateQuery}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// All of the columns to "add" for the query
|
|
87
|
+
addColumns(columns, prefix) {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
prefix = prefix || this.addColumnsPrefix;
|
|
90
|
+
|
|
91
|
+
if (columns.sql.length > 0) {
|
|
92
|
+
const columnSql = columns.sql.map((column) => {
|
|
93
|
+
return prefix + column;
|
|
94
|
+
});
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
this.pushQuery({
|
|
97
|
+
sql:
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
(this.lowerCase ? 'alter table ' : 'ALTER TABLE ') +
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
this.tableName() +
|
|
102
|
+
' ' +
|
|
103
|
+
columnSql.join(' '),
|
|
104
|
+
bindings: columns.bindings,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async commit(conn) {
|
|
110
|
+
return await conn.commit();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default IBMiTableCompiler
|