@mrnafisia/type-query 1.2.10 → 2.0.0
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/prd.tsconfig.tsbuildinfo +1 -0
- package/dist/src/Table.d.ts +82 -0
- package/dist/src/Table.d.ts.map +1 -0
- package/dist/{types/pool.js → src/Table.js} +3 -3
- package/dist/{types → src}/Table.js.map +1 -1
- package/dist/src/context.d.ts +76 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +70 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/createModelParser.d.ts +33 -0
- package/dist/src/createModelParser.d.ts.map +1 -0
- package/dist/src/createModelParser.js +178 -0
- package/dist/src/createModelParser.js.map +1 -0
- package/dist/src/ddl.d.ts +11 -0
- package/dist/src/ddl.d.ts.map +1 -0
- package/dist/src/ddl.js +83 -0
- package/dist/src/ddl.js.map +1 -0
- package/dist/src/entity.d.ts +100 -0
- package/dist/src/entity.d.ts.map +1 -0
- package/dist/src/entity.js +425 -0
- package/dist/src/entity.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +54 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/keywords.d.ts +143 -0
- package/dist/src/keywords.d.ts.map +1 -0
- package/dist/src/keywords.js +169 -0
- package/dist/src/keywords.js.map +1 -0
- package/dist/src/resolve.d.ts +15 -0
- package/dist/src/resolve.d.ts.map +1 -0
- package/dist/src/resolve.js +535 -0
- package/dist/src/resolve.js.map +1 -0
- package/dist/src/testTransaction.d.ts +19 -0
- package/dist/src/testTransaction.d.ts.map +1 -0
- package/dist/src/testTransaction.js +85 -0
- package/dist/src/testTransaction.js.map +1 -0
- package/dist/src/transaction.d.ts +6 -0
- package/dist/src/transaction.d.ts.map +1 -0
- package/dist/src/transaction.js +28 -0
- package/dist/src/transaction.js.map +1 -0
- package/dist/src/utils.d.ts +70 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +229 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +29 -25
- package/dist/U.d.ts +0 -3
- package/dist/U.d.ts.map +0 -1
- package/dist/U.js +0 -29
- package/dist/U.js.map +0 -1
- package/dist/cast.d.ts +0 -15
- package/dist/cast.d.ts.map +0 -1
- package/dist/cast.js +0 -151
- package/dist/cast.js.map +0 -1
- package/dist/context.d.ts +0 -949
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -85
- package/dist/context.js.map +0 -1
- package/dist/dictionary.d.ts +0 -13
- package/dist/dictionary.d.ts.map +0 -1
- package/dist/dictionary.js +0 -180
- package/dist/dictionary.js.map +0 -1
- package/dist/entity.d.ts +0 -3469
- package/dist/entity.d.ts.map +0 -1
- package/dist/entity.js +0 -1067
- package/dist/entity.js.map +0 -1
- package/dist/error.d.ts +0 -5
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -8
- package/dist/error.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -35
- package/dist/index.js.map +0 -1
- package/dist/model.d.ts +0 -967
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js +0 -244
- package/dist/model.js.map +0 -1
- package/dist/pool.d.ts +0 -7
- package/dist/pool.d.ts.map +0 -1
- package/dist/pool.js +0 -123
- package/dist/pool.js.map +0 -1
- package/dist/schema.d.ts +0 -26
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -406
- package/dist/schema.js.map +0 -1
- package/dist/testUtil.d.ts +0 -5
- package/dist/testUtil.d.ts.map +0 -1
- package/dist/testUtil.js +0 -338
- package/dist/testUtil.js.map +0 -1
- package/dist/types/Context.d.ts +0 -52
- package/dist/types/Context.d.ts.map +0 -1
- package/dist/types/Context.js +0 -3
- package/dist/types/Context.js.map +0 -1
- package/dist/types/Entity.d.ts +0 -71
- package/dist/types/Entity.d.ts.map +0 -1
- package/dist/types/Entity.js +0 -3
- package/dist/types/Entity.js.map +0 -1
- package/dist/types/Json.d.ts +0 -9
- package/dist/types/Json.d.ts.map +0 -1
- package/dist/types/Json.js +0 -3
- package/dist/types/Json.js.map +0 -1
- package/dist/types/Model.d.ts +0 -22
- package/dist/types/Model.d.ts.map +0 -1
- package/dist/types/Model.js +0 -3
- package/dist/types/Model.js.map +0 -1
- package/dist/types/Table.d.ts +0 -234
- package/dist/types/Table.d.ts.map +0 -1
- package/dist/types/Table.js +0 -3
- package/dist/types/pool.d.ts +0 -19
- package/dist/types/pool.d.ts.map +0 -1
- package/dist/types/pool.js.map +0 -1
- package/dist/types/postgres.d.ts +0 -10
- package/dist/types/postgres.d.ts.map +0 -1
- package/dist/types/postgres.js +0 -3
- package/dist/types/postgres.js.map +0 -1
- package/dist/types/testUtil.d.ts +0 -27
- package/dist/types/testUtil.d.ts.map +0 -1
- package/dist/types/testUtil.js +0 -3
- package/dist/types/testUtil.js.map +0 -1
- package/dist/utils.d.ts +0 -68
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -221
- package/dist/utils.js.map +0 -1
package/dist/entity.js
DELETED
|
@@ -1,1067 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
-
if (ar || !(i in from)) {
|
|
16
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
-
ar[i] = from[i];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.partialQuery = exports.resolveColumn = exports.getTableDataOfJoinSelectColumn = exports.resolveExpression = exports.resolveReturning = exports.resolveResult = exports.createQueryResult = exports.ReservedExpressionKeys = exports.createJoinSelectEntity = exports.createEntity = void 0;
|
|
27
|
-
var U_1 = require("./U");
|
|
28
|
-
var decimal_js_1 = __importDefault(require("decimal.js"));
|
|
29
|
-
var context_1 = require("./context");
|
|
30
|
-
var never_catch_1 = require("never-catch");
|
|
31
|
-
var dictionary_1 = require("./dictionary");
|
|
32
|
-
// entity
|
|
33
|
-
var createEntity = function (table) {
|
|
34
|
-
return ({
|
|
35
|
-
table: table,
|
|
36
|
-
context: (0, context_1.createContext)(table),
|
|
37
|
-
select: function (returning, where, options) {
|
|
38
|
-
var _this = this;
|
|
39
|
-
var _a, _b, _c, _d, _e, _f;
|
|
40
|
-
var ignoreInWhere = (_a = options === null || options === void 0 ? void 0 : options.ignoreInWhere) !== null && _a !== void 0 ? _a : false;
|
|
41
|
-
var ignoreInReturning = (_b = options === null || options === void 0 ? void 0 : options.ignoreInReturning) !== null && _b !== void 0 ? _b : false;
|
|
42
|
-
var ignoreInGroupBy = (_c = options === null || options === void 0 ? void 0 : options.ignoreInGroupBy) !== null && _c !== void 0 ? _c : false;
|
|
43
|
-
var distinct = (_d = options === null || options === void 0 ? void 0 : options.distinct) !== null && _d !== void 0 ? _d : false;
|
|
44
|
-
var groupBy = (_e = options === null || options === void 0 ? void 0 : options.groupBy) !== null && _e !== void 0 ? _e : [];
|
|
45
|
-
var orders = (_f = options === null || options === void 0 ? void 0 : options.orders) !== null && _f !== void 0 ? _f : [];
|
|
46
|
-
var start = options === null || options === void 0 ? void 0 : options.start;
|
|
47
|
-
var step = options === null || options === void 0 ? void 0 : options.step;
|
|
48
|
-
var _returning = typeof returning === 'function' ? returning(this.context) : returning;
|
|
49
|
-
var createQuery = function (params) {
|
|
50
|
-
var tokens = ['SELECT'];
|
|
51
|
-
// distinct
|
|
52
|
-
if (distinct === true) {
|
|
53
|
-
tokens.push('DISTINCT');
|
|
54
|
-
}
|
|
55
|
-
else if (Array.isArray(distinct)) {
|
|
56
|
-
tokens.push("DISTINCT ON ( ".concat(distinct.map(function (column) { return resolveColumn(table, column, false); }).join(', '), " )"));
|
|
57
|
-
}
|
|
58
|
-
// select
|
|
59
|
-
var resolvedReturning = resolveReturning(function (column) { return ({ type: table.columns[column].type, title: table.columns[column].title }); }, _returning, params.length + 1, ignoreInReturning);
|
|
60
|
-
if (!resolvedReturning.ok) {
|
|
61
|
-
return (0, never_catch_1.err)("<select> -> ".concat(resolvedReturning.error));
|
|
62
|
-
}
|
|
63
|
-
params.push.apply(params, resolvedReturning.value.params);
|
|
64
|
-
tokens.push(resolvedReturning.value.text);
|
|
65
|
-
// from
|
|
66
|
-
tokens.push("FROM \"".concat(table.schema, "\".\"").concat(table.title, "\""));
|
|
67
|
-
// where
|
|
68
|
-
var resolvedWhereResult = resolveExpression(typeof where === 'function' ? where(_this.context) : where, params.length + 1, ignoreInWhere);
|
|
69
|
-
if (!resolvedWhereResult.ok) {
|
|
70
|
-
return (0, never_catch_1.err)("<select>[where] -> ".concat(resolvedWhereResult.error));
|
|
71
|
-
}
|
|
72
|
-
if (resolvedWhereResult.value.text === '' && !ignoreInWhere) {
|
|
73
|
-
return (0, never_catch_1.err)("<select>[where] -> neutral");
|
|
74
|
-
}
|
|
75
|
-
params.push.apply(params, resolvedWhereResult.value.params);
|
|
76
|
-
tokens.push('WHERE', resolvedWhereResult.value.text === '' ? 'TRUE' : resolvedWhereResult.value.text);
|
|
77
|
-
// groupBy
|
|
78
|
-
var _groupBy = typeof groupBy === 'function' ? groupBy(_this.context) : groupBy;
|
|
79
|
-
if (_groupBy.length !== 0) {
|
|
80
|
-
var groupByTextArray = [];
|
|
81
|
-
for (var _i = 0, _groupBy_1 = _groupBy; _i < _groupBy_1.length; _i++) {
|
|
82
|
-
var aGroupBy = _groupBy_1[_i];
|
|
83
|
-
var resolvedGroupBy = resolveExpression(aGroupBy, params.length + 1, ignoreInGroupBy);
|
|
84
|
-
if (!resolvedGroupBy.ok) {
|
|
85
|
-
return (0, never_catch_1.err)("<select> -> ".concat(resolvedGroupBy.error));
|
|
86
|
-
}
|
|
87
|
-
params.push.apply(params, resolvedGroupBy.value.params);
|
|
88
|
-
groupByTextArray.push(resolvedGroupBy.value.text);
|
|
89
|
-
}
|
|
90
|
-
tokens.push('GROUP BY', groupByTextArray.join(', '));
|
|
91
|
-
}
|
|
92
|
-
// orders
|
|
93
|
-
if (orders.length !== 0) {
|
|
94
|
-
var ordersTextArray = [];
|
|
95
|
-
for (var _a = 0, orders_1 = orders; _a < orders_1.length; _a++) {
|
|
96
|
-
var order = orders_1[_a];
|
|
97
|
-
var by = order.by, direction = order.direction;
|
|
98
|
-
ordersTextArray.push("".concat(resolveColumn(table, by, false), " ").concat((0, dictionary_1.toOrderDirection)(direction)));
|
|
99
|
-
}
|
|
100
|
-
tokens.push('ORDER BY', ordersTextArray.join(', '));
|
|
101
|
-
}
|
|
102
|
-
// pagination
|
|
103
|
-
if (start !== undefined) {
|
|
104
|
-
if (start < 0) {
|
|
105
|
-
return (0, never_catch_1.err)("<select>[start] -> invalid");
|
|
106
|
-
}
|
|
107
|
-
tokens.push('OFFSET', start.toString());
|
|
108
|
-
}
|
|
109
|
-
if (step !== undefined) {
|
|
110
|
-
if (step <= 0) {
|
|
111
|
-
return (0, never_catch_1.err)("<select>[step] -> invalid");
|
|
112
|
-
}
|
|
113
|
-
tokens.push('LIMIT', step.toString());
|
|
114
|
-
}
|
|
115
|
-
tokens.push(';');
|
|
116
|
-
var sql = tokens.join(' ');
|
|
117
|
-
return (0, never_catch_1.ok)({ sql: sql, params: params });
|
|
118
|
-
};
|
|
119
|
-
return createQueryResult(function (column) { return [table.columns[column].type, table.columns[column].nullable]; }, createQuery, _returning);
|
|
120
|
-
},
|
|
121
|
-
insert: function (rows, returning, options) {
|
|
122
|
-
var _this = this;
|
|
123
|
-
var _a, _b, _c;
|
|
124
|
-
var nullableDefaultColumns = (_a = options === null || options === void 0 ? void 0 : options.nullableDefaultColumns) !== null && _a !== void 0 ? _a : [];
|
|
125
|
-
var ignoreInValues = (_b = options === null || options === void 0 ? void 0 : options.ignoreInValues) !== null && _b !== void 0 ? _b : false;
|
|
126
|
-
var ignoreInReturning = (_c = options === null || options === void 0 ? void 0 : options.ignoreInValues) !== null && _c !== void 0 ? _c : false;
|
|
127
|
-
var _returning = typeof returning === 'function' ? returning(this.context) : returning;
|
|
128
|
-
var createQuery = function (params) {
|
|
129
|
-
var tokens = ["INSERT INTO \"".concat(table.schema, "\".\"").concat(table.title, "\"")];
|
|
130
|
-
// columns
|
|
131
|
-
var insertingColumns = [];
|
|
132
|
-
var columnsTextArray = [];
|
|
133
|
-
for (var column in table.columns) {
|
|
134
|
-
if (nullableDefaultColumns.includes(column) || !table.columns[column].nullable) {
|
|
135
|
-
insertingColumns.push(column);
|
|
136
|
-
columnsTextArray.push(resolveColumn(table, column, false));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
tokens.push("( ".concat(columnsTextArray.join(', '), " )"), 'VALUES');
|
|
140
|
-
// values
|
|
141
|
-
var valuesTextArray = [];
|
|
142
|
-
var _rows = typeof rows === 'function' ? rows(_this.context) : rows;
|
|
143
|
-
if (_rows.length === 0) {
|
|
144
|
-
return (0, never_catch_1.err)('<insert>[values] -> empty');
|
|
145
|
-
}
|
|
146
|
-
for (var _i = 0, _rows_1 = _rows; _i < _rows_1.length; _i++) {
|
|
147
|
-
var _row = _rows_1[_i];
|
|
148
|
-
var rowTokens = [];
|
|
149
|
-
for (var _a = 0, insertingColumns_1 = insertingColumns; _a < insertingColumns_1.length; _a++) {
|
|
150
|
-
var insertingColumn = insertingColumns_1[_a];
|
|
151
|
-
if (_row[insertingColumn] === undefined) {
|
|
152
|
-
var column = table.columns[insertingColumn];
|
|
153
|
-
switch (column.default) {
|
|
154
|
-
case 'value':
|
|
155
|
-
rowTokens.push(U_1.U.stringify(column.value, true));
|
|
156
|
-
continue;
|
|
157
|
-
case true:
|
|
158
|
-
case 'auto-increment':
|
|
159
|
-
rowTokens.push('DEFAULT');
|
|
160
|
-
continue;
|
|
161
|
-
case 'created-at':
|
|
162
|
-
case 'updated-at':
|
|
163
|
-
rowTokens.push(U_1.U.stringify(new Date(), true));
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (column.nullable) {
|
|
167
|
-
rowTokens.push(U_1.U.stringify(null));
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
// never going to happen!
|
|
171
|
-
return (0, never_catch_1.err)("<insert>[rows][".concat(_rows.indexOf(_row), "][").concat(insertingColumn, "] -> no-value"));
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
var resolvedExpressionResult = resolveExpression(_row[insertingColumn], params.length + 1, ignoreInValues);
|
|
175
|
-
if (!resolvedExpressionResult.ok) {
|
|
176
|
-
return (0, never_catch_1.err)("<insert>[rows][".concat(_rows.indexOf(_row), "][").concat(insertingColumn, "] -> ").concat(resolvedExpressionResult.error));
|
|
177
|
-
}
|
|
178
|
-
if (resolvedExpressionResult.value.text === '') {
|
|
179
|
-
return (0, never_catch_1.err)("<insert>[rows][".concat(_rows.indexOf(_row), "][").concat(insertingColumn, "] -> neutral"));
|
|
180
|
-
}
|
|
181
|
-
params.push.apply(params, resolvedExpressionResult.value.params);
|
|
182
|
-
rowTokens.push(resolvedExpressionResult.value.text);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
valuesTextArray.push("( ".concat(rowTokens.join(', '), " )"));
|
|
186
|
-
}
|
|
187
|
-
tokens.push(valuesTextArray.join(', '));
|
|
188
|
-
// returning
|
|
189
|
-
if (_returning.length !== 0) {
|
|
190
|
-
var resolvedReturning = resolveReturning(function (column) { return ({ type: table.columns[column].type, title: table.columns[column].title }); }, _returning, params.length + 1, ignoreInReturning);
|
|
191
|
-
if (!resolvedReturning.ok) {
|
|
192
|
-
return (0, never_catch_1.err)("<insert> -> ".concat(resolvedReturning.error));
|
|
193
|
-
}
|
|
194
|
-
params.push.apply(params, resolvedReturning.value.params);
|
|
195
|
-
tokens.push('RETURNING', resolvedReturning.value.text);
|
|
196
|
-
}
|
|
197
|
-
tokens.push(';');
|
|
198
|
-
var sql = tokens.join(' ');
|
|
199
|
-
return (0, never_catch_1.ok)({ sql: sql, params: params });
|
|
200
|
-
};
|
|
201
|
-
return createQueryResult(function (column) { return [table.columns[column].type, table.columns[column].nullable]; }, createQuery, _returning);
|
|
202
|
-
},
|
|
203
|
-
update: function (sets, where, returning, options) {
|
|
204
|
-
var _this = this;
|
|
205
|
-
var _a, _b, _c;
|
|
206
|
-
var ignoreInSets = (_a = options === null || options === void 0 ? void 0 : options.ignoreInSets) !== null && _a !== void 0 ? _a : false;
|
|
207
|
-
var ignoreInWhere = (_b = options === null || options === void 0 ? void 0 : options.ignoreInWhere) !== null && _b !== void 0 ? _b : false;
|
|
208
|
-
var ignoreInReturning = (_c = options === null || options === void 0 ? void 0 : options.ignoreInReturning) !== null && _c !== void 0 ? _c : false;
|
|
209
|
-
var _returning = typeof returning === 'function' ? returning(this.context) : returning;
|
|
210
|
-
var createQuery = function (params) {
|
|
211
|
-
var tokens = ["UPDATE \"".concat(table.schema, "\".\"").concat(table.title, "\" SET")];
|
|
212
|
-
// set
|
|
213
|
-
var _set = typeof sets === 'function' ? sets(_this.context) : sets;
|
|
214
|
-
var setsTextArray = [];
|
|
215
|
-
var key;
|
|
216
|
-
for (key in _set) {
|
|
217
|
-
var setExpressionResult = resolveExpression(_set[key], params.length + 1, ignoreInSets);
|
|
218
|
-
if (!setExpressionResult.ok) {
|
|
219
|
-
return (0, never_catch_1.err)("<update>[sets][".concat(key, "] -> ").concat(setExpressionResult.error));
|
|
220
|
-
}
|
|
221
|
-
if (setExpressionResult.value.text === '') {
|
|
222
|
-
if (ignoreInSets) {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
return (0, never_catch_1.err)("<update>[sets][".concat(key, "] -> neutral"));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
params.push.apply(params, setExpressionResult.value.params);
|
|
230
|
-
setsTextArray.push("".concat(resolveColumn(table, key, false), " = ").concat(setExpressionResult.value.text));
|
|
231
|
-
}
|
|
232
|
-
for (var column in table.columns) {
|
|
233
|
-
switch (table.columns[column].default) {
|
|
234
|
-
case 'updated-at':
|
|
235
|
-
setsTextArray.push("".concat(resolveColumn(table, column, false), " = ").concat(U_1.U.stringify(new Date(), true)));
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (setsTextArray.length === 0) {
|
|
240
|
-
return (0, never_catch_1.err)('<update>[sets] -> empty');
|
|
241
|
-
}
|
|
242
|
-
tokens.push(setsTextArray.join(', '));
|
|
243
|
-
// where
|
|
244
|
-
var resolvedWhereResult = resolveExpression(typeof where === 'function' ? where(_this.context) : where, params.length + 1, ignoreInWhere);
|
|
245
|
-
if (!resolvedWhereResult.ok) {
|
|
246
|
-
return (0, never_catch_1.err)("<update>[where] -> ".concat(resolvedWhereResult.error));
|
|
247
|
-
}
|
|
248
|
-
if (resolvedWhereResult.value.text === '' && !ignoreInWhere) {
|
|
249
|
-
return (0, never_catch_1.err)("<update>[where] -> neutral");
|
|
250
|
-
}
|
|
251
|
-
params.push.apply(params, resolvedWhereResult.value.params);
|
|
252
|
-
tokens.push('WHERE', resolvedWhereResult.value.text === '' ? 'FALSE' : resolvedWhereResult.value.text);
|
|
253
|
-
// returning
|
|
254
|
-
if (_returning.length !== 0) {
|
|
255
|
-
var resolvedReturning = resolveReturning(function (column) { return ({ type: table.columns[column].type, title: table.columns[column].title }); }, _returning, params.length + 1, ignoreInReturning);
|
|
256
|
-
if (!resolvedReturning.ok) {
|
|
257
|
-
return (0, never_catch_1.err)("<update> -> ".concat(resolvedReturning.error));
|
|
258
|
-
}
|
|
259
|
-
params.push.apply(params, resolvedReturning.value.params);
|
|
260
|
-
tokens.push('RETURNING', resolvedReturning.value.text);
|
|
261
|
-
}
|
|
262
|
-
tokens.push(';');
|
|
263
|
-
var sql = tokens.join(' ');
|
|
264
|
-
return (0, never_catch_1.ok)({ sql: sql, params: params });
|
|
265
|
-
};
|
|
266
|
-
return createQueryResult(function (column) { return [table.columns[column].type, table.columns[column].nullable]; }, createQuery, _returning);
|
|
267
|
-
},
|
|
268
|
-
delete: function (where, returning, options) {
|
|
269
|
-
var _this = this;
|
|
270
|
-
var _a, _b;
|
|
271
|
-
var ignoreInWhere = (_a = options === null || options === void 0 ? void 0 : options.ignoreInWhere) !== null && _a !== void 0 ? _a : false;
|
|
272
|
-
var ignoreInReturning = (_b = options === null || options === void 0 ? void 0 : options.ignoreInReturning) !== null && _b !== void 0 ? _b : false;
|
|
273
|
-
var _returning = typeof returning === 'function' ? returning(this.context) : returning;
|
|
274
|
-
var createQuery = function (params) {
|
|
275
|
-
var tokens = ["DELETE FROM \"".concat(table.schema, "\".\"").concat(table.title, "\"")];
|
|
276
|
-
// where
|
|
277
|
-
var resolvedWhereResult = resolveExpression(typeof where === 'function' ? where(_this.context) : where, params.length + 1, ignoreInWhere);
|
|
278
|
-
if (!resolvedWhereResult.ok) {
|
|
279
|
-
return (0, never_catch_1.err)("<delete>[where] -> ".concat(resolvedWhereResult.error));
|
|
280
|
-
}
|
|
281
|
-
if (resolvedWhereResult.value.text === '' && !ignoreInWhere) {
|
|
282
|
-
return (0, never_catch_1.err)("<delete>[where] -> neutral");
|
|
283
|
-
}
|
|
284
|
-
params.push.apply(params, resolvedWhereResult.value.params);
|
|
285
|
-
tokens.push('WHERE', resolvedWhereResult.value.text === '' ? 'FALSE' : resolvedWhereResult.value.text);
|
|
286
|
-
// returning
|
|
287
|
-
if (_returning.length !== 0) {
|
|
288
|
-
var resolvedReturning = resolveReturning(function (column) { return ({ type: table.columns[column].type, title: table.columns[column].title }); }, _returning, params.length + 1, ignoreInReturning);
|
|
289
|
-
if (!resolvedReturning.ok) {
|
|
290
|
-
return (0, never_catch_1.err)("<delete> -> ".concat(resolvedReturning.error));
|
|
291
|
-
}
|
|
292
|
-
params.push.apply(params, resolvedReturning.value.params);
|
|
293
|
-
tokens.push('RETURNING', resolvedReturning.value.text);
|
|
294
|
-
}
|
|
295
|
-
tokens.push(';');
|
|
296
|
-
var sql = tokens.join(' ');
|
|
297
|
-
return (0, never_catch_1.ok)({ sql: sql, params: params });
|
|
298
|
-
};
|
|
299
|
-
return createQueryResult(function (column) { return [table.columns[column].type, table.columns[column].nullable]; }, createQuery, _returning);
|
|
300
|
-
},
|
|
301
|
-
join: function (mainAlias, joinType, joinTable, joinAlias, on) {
|
|
302
|
-
var _a;
|
|
303
|
-
return createJoinSelectEntity({ table: table, alias: mainAlias }, [{ table: joinTable, joinType: joinType, alias: joinAlias, on: on }], (_a = {},
|
|
304
|
-
_a[mainAlias] = (0, context_1.createContext)(table, mainAlias),
|
|
305
|
-
_a[joinAlias] = (0, context_1.createContext)(joinTable, joinAlias),
|
|
306
|
-
_a));
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
exports.createEntity = createEntity;
|
|
311
|
-
var createJoinSelectEntity = function (main, joinTables, contexts) {
|
|
312
|
-
return ({
|
|
313
|
-
contexts: contexts,
|
|
314
|
-
select: function (returning, where, options) {
|
|
315
|
-
var _this = this;
|
|
316
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
317
|
-
var ignoreInWhere = (_a = options === null || options === void 0 ? void 0 : options.ignoreInWhere) !== null && _a !== void 0 ? _a : false;
|
|
318
|
-
var ignoreInReturning = (_b = options === null || options === void 0 ? void 0 : options.ignoreInReturning) !== null && _b !== void 0 ? _b : false;
|
|
319
|
-
var ignoreInJoin = (_c = options === null || options === void 0 ? void 0 : options.ignoreInJoin) !== null && _c !== void 0 ? _c : false;
|
|
320
|
-
var ignoreInGroupBy = (_d = options === null || options === void 0 ? void 0 : options.ignoreInGroupBy) !== null && _d !== void 0 ? _d : false;
|
|
321
|
-
var distinct = (_e = options === null || options === void 0 ? void 0 : options.distinct) !== null && _e !== void 0 ? _e : false;
|
|
322
|
-
var groupBy = (_f = options === null || options === void 0 ? void 0 : options.groupBy) !== null && _f !== void 0 ? _f : [];
|
|
323
|
-
var orders = (_g = options === null || options === void 0 ? void 0 : options.orders) !== null && _g !== void 0 ? _g : [];
|
|
324
|
-
var start = options === null || options === void 0 ? void 0 : options.start;
|
|
325
|
-
var step = options === null || options === void 0 ? void 0 : options.step;
|
|
326
|
-
var allTables = __spreadArray([main], joinTables, true);
|
|
327
|
-
var _returning = typeof returning === 'function' ? returning(this.contexts) : returning;
|
|
328
|
-
var createQuery = function (params) {
|
|
329
|
-
var tokens = ['SELECT'];
|
|
330
|
-
// distinct
|
|
331
|
-
if (distinct === true) {
|
|
332
|
-
tokens.push('DISTINCT');
|
|
333
|
-
}
|
|
334
|
-
else if (Array.isArray(distinct)) {
|
|
335
|
-
tokens.push("DISTINCT ON ( ".concat(distinct
|
|
336
|
-
.map(function (column) {
|
|
337
|
-
var _a = getTableDataOfJoinSelectColumn(allTables, column), table = _a.table, alias = _a.alias;
|
|
338
|
-
return resolveColumn(table, column.substring((alias + '_').length), true, alias);
|
|
339
|
-
})
|
|
340
|
-
.join(', '), " )"));
|
|
341
|
-
}
|
|
342
|
-
// select
|
|
343
|
-
var resolvedReturning = resolveReturning(function (column) {
|
|
344
|
-
var _a = getTableDataOfJoinSelectColumn(allTables, column), table = _a.table, alias = _a.alias;
|
|
345
|
-
var columnKey = column.substring((alias + '_').length);
|
|
346
|
-
return { type: table.columns[columnKey].type, title: table.columns[columnKey].title, alias: alias };
|
|
347
|
-
}, _returning, params.length + 1, ignoreInReturning);
|
|
348
|
-
if (!resolvedReturning.ok) {
|
|
349
|
-
return (0, never_catch_1.err)("<join-select>[columns] -> ".concat(resolvedReturning.error));
|
|
350
|
-
}
|
|
351
|
-
params.push.apply(params, resolvedReturning.value.params);
|
|
352
|
-
tokens.push(resolvedReturning.value.text, "FROM \"".concat(main.table.schema, "\".\"").concat(main.table.title, "\" \"").concat(main.alias, "\""));
|
|
353
|
-
// join
|
|
354
|
-
for (var _i = 0, joinTables_1 = joinTables; _i < joinTables_1.length; _i++) {
|
|
355
|
-
var joinTable = joinTables_1[_i];
|
|
356
|
-
var onExpressionResult = resolveExpression(typeof joinTable.on === 'function' ? joinTable.on(_this.contexts) : joinTable.on, params.length + 1, ignoreInJoin);
|
|
357
|
-
if (!onExpressionResult.ok) {
|
|
358
|
-
return (0, never_catch_1.err)("<join-select>[join][".concat(joinTables.indexOf(joinTable), "] -> ").concat(onExpressionResult.error));
|
|
359
|
-
}
|
|
360
|
-
if (onExpressionResult.value.text === '' && !ignoreInJoin) {
|
|
361
|
-
return (0, never_catch_1.err)("<join-select>[join][".concat(joinTables.indexOf(joinTable), "] -> neutral"));
|
|
362
|
-
}
|
|
363
|
-
params.push.apply(params, onExpressionResult.value.params);
|
|
364
|
-
tokens.push("".concat((0, dictionary_1.toJoinType)(joinTable.joinType), " \"").concat(joinTable.table.schema, "\".\"").concat(joinTable.table.title, "\" \"").concat(joinTable.alias, "\" ON ").concat(onExpressionResult.value.text));
|
|
365
|
-
}
|
|
366
|
-
// where
|
|
367
|
-
var resolvedWhereResult = resolveExpression(typeof where === 'function' ? where(_this.contexts) : where, params.length + 1, ignoreInWhere);
|
|
368
|
-
if (!resolvedWhereResult.ok) {
|
|
369
|
-
return (0, never_catch_1.err)("<join-select>[where] -> ".concat(resolvedWhereResult.error));
|
|
370
|
-
}
|
|
371
|
-
if (resolvedWhereResult.value.text === '' && !ignoreInWhere) {
|
|
372
|
-
return (0, never_catch_1.err)("<join-select>[where] -> neutral");
|
|
373
|
-
}
|
|
374
|
-
params.push.apply(params, resolvedWhereResult.value.params);
|
|
375
|
-
tokens.push('WHERE', resolvedWhereResult.value.text === '' ? 'FALSE' : resolvedWhereResult.value.text);
|
|
376
|
-
// groupBy
|
|
377
|
-
var _groupBy = typeof groupBy === 'function' ? groupBy(_this.contexts) : groupBy;
|
|
378
|
-
if (_groupBy.length !== 0) {
|
|
379
|
-
var groupByTextArray = [];
|
|
380
|
-
for (var _a = 0, _groupBy_2 = _groupBy; _a < _groupBy_2.length; _a++) {
|
|
381
|
-
var aGroupBy = _groupBy_2[_a];
|
|
382
|
-
var resolvedGroupBy = resolveExpression(aGroupBy, params.length + 1, ignoreInGroupBy);
|
|
383
|
-
if (!resolvedGroupBy.ok) {
|
|
384
|
-
return (0, never_catch_1.err)("<join-select> -> ".concat(resolvedGroupBy.error));
|
|
385
|
-
}
|
|
386
|
-
params.push.apply(params, resolvedGroupBy.value.params);
|
|
387
|
-
groupByTextArray.push(resolvedGroupBy.value.text);
|
|
388
|
-
}
|
|
389
|
-
tokens.push('GROUP BY', groupByTextArray.join(', '));
|
|
390
|
-
}
|
|
391
|
-
// orders
|
|
392
|
-
if (orders.length !== 0) {
|
|
393
|
-
var ordersTextArray = [];
|
|
394
|
-
for (var _b = 0, orders_2 = orders; _b < orders_2.length; _b++) {
|
|
395
|
-
var order = orders_2[_b];
|
|
396
|
-
var by = order.by, direction = order.direction;
|
|
397
|
-
var _c = getTableDataOfJoinSelectColumn(allTables, by), table = _c.table, alias = _c.alias;
|
|
398
|
-
ordersTextArray.push("".concat(resolveColumn(table, by.substring((alias + '_').length), true, alias), " ").concat((0, dictionary_1.toOrderDirection)(direction)));
|
|
399
|
-
}
|
|
400
|
-
tokens.push('ORDER BY', ordersTextArray.join(', '));
|
|
401
|
-
}
|
|
402
|
-
// pagination
|
|
403
|
-
if (start !== undefined) {
|
|
404
|
-
if (start < 0) {
|
|
405
|
-
return (0, never_catch_1.err)("<join-select>[start] -> invalid");
|
|
406
|
-
}
|
|
407
|
-
tokens.push('OFFSET', start.toString());
|
|
408
|
-
}
|
|
409
|
-
if (step !== undefined) {
|
|
410
|
-
if (step <= 0) {
|
|
411
|
-
return (0, never_catch_1.err)("<join-select>[step] -> invalid");
|
|
412
|
-
}
|
|
413
|
-
tokens.push('LIMIT', step.toString());
|
|
414
|
-
}
|
|
415
|
-
tokens.push(';');
|
|
416
|
-
var sql = tokens.join(' ');
|
|
417
|
-
return (0, never_catch_1.ok)({ sql: sql, params: params });
|
|
418
|
-
};
|
|
419
|
-
return createQueryResult(function (column) {
|
|
420
|
-
var _a = getTableDataOfJoinSelectColumn(allTables, column), alias = _a.alias, columns = _a.table.columns;
|
|
421
|
-
var targetCol = columns[column.substring((alias + '_').length)];
|
|
422
|
-
return [targetCol.type, targetCol.nullable];
|
|
423
|
-
}, createQuery, _returning);
|
|
424
|
-
},
|
|
425
|
-
join: function (joinType, joinTable, joinAlias, on) {
|
|
426
|
-
var _a;
|
|
427
|
-
joinTables.push({ table: joinTable, on: on, joinType: joinType, alias: joinAlias });
|
|
428
|
-
return createJoinSelectEntity(main, joinTables, __assign(__assign({}, contexts), (_a = {}, _a[joinAlias] = (0, context_1.createContext)(joinTable, joinAlias), _a)));
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
};
|
|
432
|
-
exports.createJoinSelectEntity = createJoinSelectEntity;
|
|
433
|
-
// utils
|
|
434
|
-
var ReservedExpressionKeys = [
|
|
435
|
-
'val',
|
|
436
|
-
'=n',
|
|
437
|
-
'!=n',
|
|
438
|
-
'=t',
|
|
439
|
-
'=f',
|
|
440
|
-
'not',
|
|
441
|
-
'+',
|
|
442
|
-
'-',
|
|
443
|
-
'*',
|
|
444
|
-
'/',
|
|
445
|
-
'||',
|
|
446
|
-
'and',
|
|
447
|
-
'or',
|
|
448
|
-
'**',
|
|
449
|
-
'fun',
|
|
450
|
-
'swt',
|
|
451
|
-
'col',
|
|
452
|
-
'raw',
|
|
453
|
-
'=',
|
|
454
|
-
'!=',
|
|
455
|
-
'>',
|
|
456
|
-
'>=',
|
|
457
|
-
'<',
|
|
458
|
-
'<=',
|
|
459
|
-
'lk',
|
|
460
|
-
'@>',
|
|
461
|
-
'<@',
|
|
462
|
-
'?',
|
|
463
|
-
'j-',
|
|
464
|
-
'in',
|
|
465
|
-
'nin',
|
|
466
|
-
'lka',
|
|
467
|
-
'lks',
|
|
468
|
-
'?|',
|
|
469
|
-
'?&',
|
|
470
|
-
'j-a',
|
|
471
|
-
'bt',
|
|
472
|
-
'qry',
|
|
473
|
-
'exists'
|
|
474
|
-
];
|
|
475
|
-
exports.ReservedExpressionKeys = ReservedExpressionKeys;
|
|
476
|
-
var createQueryResult = function (getColumnType, createQuery, returning) {
|
|
477
|
-
var query = undefined;
|
|
478
|
-
return {
|
|
479
|
-
getData: function (params) {
|
|
480
|
-
if (params === void 0) { params = []; }
|
|
481
|
-
if (query === undefined) {
|
|
482
|
-
var createQueryResult_1 = createQuery(params);
|
|
483
|
-
if (createQueryResult_1.ok) {
|
|
484
|
-
query = createQueryResult_1.value;
|
|
485
|
-
}
|
|
486
|
-
else {
|
|
487
|
-
return createQueryResult_1;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return (0, never_catch_1.ok)(query);
|
|
491
|
-
},
|
|
492
|
-
exec: function (client, mode, params) {
|
|
493
|
-
if (params === void 0) { params = []; }
|
|
494
|
-
if (query === undefined) {
|
|
495
|
-
var createQueryResult_2 = createQuery(params);
|
|
496
|
-
if (createQueryResult_2.ok) {
|
|
497
|
-
query = createQueryResult_2.value;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
return Promise.resolve(createQueryResult_2);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return client
|
|
504
|
-
.query(query.sql, query.params)
|
|
505
|
-
.then(function (_a) {
|
|
506
|
-
var rows = _a.rows;
|
|
507
|
-
return resolveResult(getColumnType, returning, rows, mode);
|
|
508
|
-
})
|
|
509
|
-
.catch(function (e) { return (0, never_catch_1.err)(e); });
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
};
|
|
513
|
-
exports.createQueryResult = createQueryResult;
|
|
514
|
-
/*
|
|
515
|
-
* take getColumnType instead of table to support join-select too.
|
|
516
|
-
* this cause hard to call this function directly, but it is only solution I could come up with.
|
|
517
|
-
*/
|
|
518
|
-
var resolveResult = function (getColumnType, columns, rows, mode) {
|
|
519
|
-
// check size in count and get mode
|
|
520
|
-
if (mode[0] === 'count') {
|
|
521
|
-
return rows.length === mode[1] ? (0, never_catch_1.ok)(undefined) : (0, never_catch_1.err)(false);
|
|
522
|
-
}
|
|
523
|
-
if (mode[0] === 'get' && rows.length !== (mode[1] === 'one' ? 1 : mode[1])) {
|
|
524
|
-
return (0, never_catch_1.err)(false);
|
|
525
|
-
}
|
|
526
|
-
// parse result
|
|
527
|
-
rows.forEach(function (_, i) {
|
|
528
|
-
columns.forEach(function (column) {
|
|
529
|
-
if (typeof column !== 'object') {
|
|
530
|
-
rows[i][column] = U_1.U.cast(rows[i][column], getColumnType(column));
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
// return first element for [get, one] mode and all for [get, number] and []
|
|
535
|
-
if (mode[0] === 'get' && mode[1] === 'one') {
|
|
536
|
-
return (0, never_catch_1.ok)(rows[0]);
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
return (0, never_catch_1.ok)(rows);
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
exports.resolveResult = resolveResult;
|
|
543
|
-
/*
|
|
544
|
-
* take getColumnTypeTitleAlias instead of table to support join-select too.
|
|
545
|
-
* this cause hard to call this function directly, but it is only solution I could come up with.
|
|
546
|
-
*/
|
|
547
|
-
var resolveReturning = function (getColumnTypeTitleAlias, columns, paramsStart, ignore) {
|
|
548
|
-
var tokens = [];
|
|
549
|
-
var params = [];
|
|
550
|
-
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
|
|
551
|
-
var column = columns_1[_i];
|
|
552
|
-
if (typeof column === 'object') {
|
|
553
|
-
var resolvedExpResult = resolveExpression(column.exp, paramsStart, ignore);
|
|
554
|
-
if (!resolvedExpResult.ok) {
|
|
555
|
-
return (0, never_catch_1.err)("<returning>[".concat(column.as, "] -> ").concat(resolvedExpResult.error));
|
|
556
|
-
}
|
|
557
|
-
if (resolvedExpResult.value.text === '') {
|
|
558
|
-
return (0, never_catch_1.err)("<returning>[".concat(column.as, "] -> neutral"));
|
|
559
|
-
}
|
|
560
|
-
params.push.apply(params, resolvedExpResult.value.params);
|
|
561
|
-
paramsStart += resolvedExpResult.value.params.length;
|
|
562
|
-
tokens.push("( ".concat(resolvedExpResult.value.text, " ) AS \"").concat(column.as, "\""));
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
var _a = getColumnTypeTitleAlias(column), _type = _a.type, title = _a.title, alias = _a.alias;
|
|
566
|
-
// TODO cast time with/without timezone to custom object
|
|
567
|
-
if (title === undefined) {
|
|
568
|
-
if (alias !== undefined) {
|
|
569
|
-
tokens.push("\"".concat(alias, "\".") + "\"".concat(column.substring((alias + '_').length), "\"") + " AS \"".concat(column, "\""));
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
tokens.push("\"".concat(column, "\""));
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
tokens.push((alias !== undefined ? "\"".concat(alias, "\".") : '') + "\"".concat(title, "\"") + " AS \"".concat(column, "\""));
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
if (tokens.length === 0) {
|
|
581
|
-
return (0, never_catch_1.err)('<returning> -> empty');
|
|
582
|
-
}
|
|
583
|
-
return (0, never_catch_1.ok)(partialQuery(tokens.join(', '), params));
|
|
584
|
-
};
|
|
585
|
-
exports.resolveReturning = resolveReturning;
|
|
586
|
-
/*
|
|
587
|
-
** currently all errors are handled with types and no dynamic check is required.
|
|
588
|
-
** errors return only when ignore is false and an expression needs ignorance.
|
|
589
|
-
** so, some errors written in function, but they will never be returned.
|
|
590
|
-
** e.g.
|
|
591
|
-
** if (e1Result.value.text === '') {
|
|
592
|
-
** return ignore ? ok(partialQuery()) : err(`<${toDescription(expression[0])}> -> neutral`);
|
|
593
|
-
** }
|
|
594
|
-
* if result is neutral then ignore is true, so error in this example will never be returned.
|
|
595
|
-
* but they exist in case new errors with dynamic check added.
|
|
596
|
-
*/
|
|
597
|
-
var resolveExpression = function (expression, paramsStart, ignore) {
|
|
598
|
-
if (ignore === void 0) { ignore = false; }
|
|
599
|
-
// primitive expression
|
|
600
|
-
if (expression === undefined) {
|
|
601
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)('undefined');
|
|
602
|
-
}
|
|
603
|
-
if (expression === null ||
|
|
604
|
-
typeof expression === 'boolean' ||
|
|
605
|
-
expression instanceof decimal_js_1.default ||
|
|
606
|
-
expression instanceof Date ||
|
|
607
|
-
typeof expression === 'number' ||
|
|
608
|
-
typeof expression === 'bigint') {
|
|
609
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(U_1.U.stringify(expression, true))));
|
|
610
|
-
}
|
|
611
|
-
if (typeof expression === 'string') {
|
|
612
|
-
return (0, never_catch_1.ok)(partialQuery("$".concat(paramsStart++), [U_1.U.stringify(expression, false)]));
|
|
613
|
-
}
|
|
614
|
-
if (!(Array.isArray(expression) && ReservedExpressionKeys.includes(expression[0]))) {
|
|
615
|
-
return (0, never_catch_1.ok)(partialQuery("$".concat(paramsStart++, "::jsonb"), [U_1.U.stringify(expression, false)]));
|
|
616
|
-
}
|
|
617
|
-
// wrapped expression
|
|
618
|
-
var tokens = [];
|
|
619
|
-
var params = [];
|
|
620
|
-
var e1Result, e2Result, e3Result;
|
|
621
|
-
switch (expression[0]) {
|
|
622
|
-
case 'val':
|
|
623
|
-
if (expression[1] === undefined) {
|
|
624
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)('val'), "> -> undefined"));
|
|
625
|
-
}
|
|
626
|
-
params.push(U_1.U.stringify(expression[1], false));
|
|
627
|
-
return (0, never_catch_1.ok)(partialQuery("$".concat(paramsStart++), params));
|
|
628
|
-
case '=n':
|
|
629
|
-
case '!=n':
|
|
630
|
-
case '=t':
|
|
631
|
-
case '=f':
|
|
632
|
-
case 'not':
|
|
633
|
-
e1Result = resolveExpression(expression[1], paramsStart, ignore);
|
|
634
|
-
if (!e1Result.ok) {
|
|
635
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), "> -> ").concat(e1Result.error));
|
|
636
|
-
}
|
|
637
|
-
if (e1Result.value.text === '') {
|
|
638
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), "> -> neutral"));
|
|
639
|
-
}
|
|
640
|
-
params.push.apply(params, e1Result.value.params);
|
|
641
|
-
paramsStart += e1Result.value.params.length;
|
|
642
|
-
switch (expression[0]) {
|
|
643
|
-
case '=n':
|
|
644
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " IS NULL"), params));
|
|
645
|
-
case '!=n':
|
|
646
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " IS NOT NULL"), params));
|
|
647
|
-
case '=t':
|
|
648
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text), params));
|
|
649
|
-
case '=f':
|
|
650
|
-
case 'not':
|
|
651
|
-
return (0, never_catch_1.ok)(partialQuery("NOT ".concat(e1Result.value.text), params));
|
|
652
|
-
}
|
|
653
|
-
case '+':
|
|
654
|
-
case '-':
|
|
655
|
-
case '*':
|
|
656
|
-
case '/':
|
|
657
|
-
case '||':
|
|
658
|
-
case 'and':
|
|
659
|
-
case 'or':
|
|
660
|
-
case '**':
|
|
661
|
-
if (expression[1] === undefined) {
|
|
662
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), "> -> undefined"));
|
|
663
|
-
}
|
|
664
|
-
for (var _i = 0, _a = expression[1]; _i < _a.length; _i++) {
|
|
665
|
-
var v1 = _a[_i];
|
|
666
|
-
var v1Result = resolveExpression(v1, paramsStart, ignore);
|
|
667
|
-
if (!v1Result.ok) {
|
|
668
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[").concat(expression[1].indexOf(v1), "] -> ").concat(v1Result.error));
|
|
669
|
-
}
|
|
670
|
-
if (v1Result.value.text === '') {
|
|
671
|
-
if (ignore) {
|
|
672
|
-
continue;
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[").concat(expression[1].indexOf(v1), "] -> neutral"));
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
params.push.apply(params, v1Result.value.params);
|
|
679
|
-
paramsStart += v1Result.value.params.length;
|
|
680
|
-
tokens.push(v1Result.value.text);
|
|
681
|
-
}
|
|
682
|
-
switch (tokens.length) {
|
|
683
|
-
case 0:
|
|
684
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), "> -> no operands given"));
|
|
685
|
-
case 1:
|
|
686
|
-
return (0, never_catch_1.ok)(partialQuery(tokens[0], params));
|
|
687
|
-
default:
|
|
688
|
-
switch (expression[0]) {
|
|
689
|
-
case '+':
|
|
690
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' + '), " )"), params));
|
|
691
|
-
case '-':
|
|
692
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' - '), " )"), params));
|
|
693
|
-
case '*':
|
|
694
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' * '), " )"), params));
|
|
695
|
-
case '/':
|
|
696
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' / '), " )"), params));
|
|
697
|
-
case '||':
|
|
698
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' || '), " )"), params));
|
|
699
|
-
case 'and':
|
|
700
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' AND '), " )"), params));
|
|
701
|
-
case 'or':
|
|
702
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(tokens.join(' OR '), " )"), params));
|
|
703
|
-
case '**':
|
|
704
|
-
var tmp = tokens.pop();
|
|
705
|
-
tokens.splice(0, 0, 'a');
|
|
706
|
-
return (0, never_catch_1.ok)({
|
|
707
|
-
text: tokens.join(', power( ').substring(3) + ', ' + tmp + ' )'.repeat(tokens.length - 1),
|
|
708
|
-
params: params
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
case 'fun':
|
|
713
|
-
if (expression[1] === undefined) {
|
|
714
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[name] -> undefined"));
|
|
715
|
-
}
|
|
716
|
-
if (expression[2] === undefined) {
|
|
717
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[parameters] -> undefined"));
|
|
718
|
-
}
|
|
719
|
-
for (var _b = 0, _c = expression[2]; _b < _c.length; _b++) {
|
|
720
|
-
var v2 = _c[_b];
|
|
721
|
-
var v2Result = resolveExpression(v2, paramsStart, ignore);
|
|
722
|
-
if (!v2Result.ok) {
|
|
723
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[parameters][").concat(expression[2].indexOf(v2), "] -> ").concat(v2Result.error));
|
|
724
|
-
}
|
|
725
|
-
if (v2Result.value.text === '') {
|
|
726
|
-
return ignore
|
|
727
|
-
? (0, never_catch_1.ok)(partialQuery())
|
|
728
|
-
: (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[parameters][").concat(expression[2].indexOf(v2), "] -> neutral"));
|
|
729
|
-
}
|
|
730
|
-
params.push.apply(params, v2Result.value.params);
|
|
731
|
-
paramsStart += v2Result.value.params.length;
|
|
732
|
-
tokens.push(v2Result.value.text);
|
|
733
|
-
}
|
|
734
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(expression[1], "( ").concat(tokens.join(', '), " )").concat(expression[3]), params));
|
|
735
|
-
case 'swt':
|
|
736
|
-
var cases = expression[1];
|
|
737
|
-
var otherwise = expression[2];
|
|
738
|
-
if (cases === undefined) {
|
|
739
|
-
if (!ignore) {
|
|
740
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases] -> undefined"));
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
for (var _d = 0, cases_1 = cases; _d < cases_1.length; _d++) {
|
|
745
|
-
var caseElement = cases_1[_d];
|
|
746
|
-
if (caseElement === undefined) {
|
|
747
|
-
if (ignore) {
|
|
748
|
-
continue;
|
|
749
|
-
}
|
|
750
|
-
else {
|
|
751
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases][").concat(cases.indexOf(caseElement), "] -> undefined"));
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
var whenResult = resolveExpression(caseElement.when, paramsStart, ignore);
|
|
755
|
-
if (!whenResult.ok) {
|
|
756
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases][").concat(cases.indexOf(caseElement), "][when] -> ").concat(whenResult.error));
|
|
757
|
-
}
|
|
758
|
-
if (whenResult.value.text === '') {
|
|
759
|
-
if (ignore) {
|
|
760
|
-
continue;
|
|
761
|
-
}
|
|
762
|
-
else {
|
|
763
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases][").concat(cases.indexOf(caseElement), "][when] -> neutral"));
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
params.push.apply(params, whenResult.value.params);
|
|
767
|
-
paramsStart += whenResult.value.params.length;
|
|
768
|
-
var thenResult = resolveExpression(caseElement.then, paramsStart, ignore);
|
|
769
|
-
if (!thenResult.ok) {
|
|
770
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases][").concat(cases.indexOf(caseElement), "][then] -> ").concat(thenResult.error));
|
|
771
|
-
}
|
|
772
|
-
if (thenResult.value.text === '') {
|
|
773
|
-
if (ignore) {
|
|
774
|
-
continue;
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases][").concat(cases.indexOf(caseElement), "][then] -> neutral"));
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
params.push.apply(params, thenResult.value.params);
|
|
781
|
-
paramsStart += thenResult.value.params.length;
|
|
782
|
-
if (tokens.length === 0) {
|
|
783
|
-
tokens.push('CASE');
|
|
784
|
-
}
|
|
785
|
-
tokens.push("WHEN ".concat(whenResult.value.text, " THEN ").concat(thenResult.value.text));
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
if (tokens.length === 0 && !ignore) {
|
|
789
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[cases] -> empty"));
|
|
790
|
-
}
|
|
791
|
-
if (otherwise === undefined) {
|
|
792
|
-
if (tokens.length === 0) {
|
|
793
|
-
return (0, never_catch_1.ok)(partialQuery());
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
tokens.push('END');
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
else {
|
|
800
|
-
var isOtherwiseNeutral = false;
|
|
801
|
-
var otherwiseResult = resolveExpression(otherwise, paramsStart, ignore);
|
|
802
|
-
if (!otherwiseResult.ok) {
|
|
803
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[otherwise] -> ").concat(otherwiseResult.error));
|
|
804
|
-
}
|
|
805
|
-
if (otherwiseResult.value.text === '') {
|
|
806
|
-
if (ignore) {
|
|
807
|
-
isOtherwiseNeutral = true;
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[otherwise] -> neutral"));
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
params.push.apply(params, otherwiseResult.value.params);
|
|
814
|
-
paramsStart += otherwiseResult.value.params.length;
|
|
815
|
-
if (tokens.length === 0) {
|
|
816
|
-
if (isOtherwiseNeutral) {
|
|
817
|
-
return (0, never_catch_1.ok)(partialQuery());
|
|
818
|
-
}
|
|
819
|
-
else {
|
|
820
|
-
tokens.push(otherwiseResult.value.text);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
else {
|
|
824
|
-
if (!isOtherwiseNeutral) {
|
|
825
|
-
tokens.push('ELSE', otherwiseResult.value.text);
|
|
826
|
-
}
|
|
827
|
-
tokens.push('END');
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
return (0, never_catch_1.ok)(partialQuery(tokens.join(' '), params));
|
|
831
|
-
case 'col':
|
|
832
|
-
case 'raw':
|
|
833
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(expression[1])));
|
|
834
|
-
case 'qry':
|
|
835
|
-
case 'exists':
|
|
836
|
-
var subQueryDataResult = expression[1].getData(params);
|
|
837
|
-
if (!subQueryDataResult.ok) {
|
|
838
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), "> -> ").concat(subQueryDataResult.error));
|
|
839
|
-
}
|
|
840
|
-
paramsStart += subQueryDataResult.value.params.length;
|
|
841
|
-
subQueryDataResult.value.sql = subQueryDataResult.value.sql.substring(0, subQueryDataResult.value.sql.length - 1);
|
|
842
|
-
switch (expression[0]) {
|
|
843
|
-
case 'qry':
|
|
844
|
-
return (0, never_catch_1.ok)(partialQuery("( ".concat(subQueryDataResult.value.sql, " )"), params));
|
|
845
|
-
case 'exists':
|
|
846
|
-
return (0, never_catch_1.ok)(partialQuery("EXISTS ( ".concat(subQueryDataResult.value.sql, " )"), params));
|
|
847
|
-
}
|
|
848
|
-
case '=':
|
|
849
|
-
case '!=':
|
|
850
|
-
case '>':
|
|
851
|
-
case '>=':
|
|
852
|
-
case '<':
|
|
853
|
-
case '<=':
|
|
854
|
-
case 'lk':
|
|
855
|
-
case '@>':
|
|
856
|
-
case '<@':
|
|
857
|
-
case '?':
|
|
858
|
-
case 'j-':
|
|
859
|
-
e1Result = resolveExpression(expression[1], paramsStart, ignore);
|
|
860
|
-
if (!e1Result.ok) {
|
|
861
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> ").concat(e1Result.error));
|
|
862
|
-
}
|
|
863
|
-
if (e1Result.value.text === '') {
|
|
864
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> netural"));
|
|
865
|
-
}
|
|
866
|
-
params.push.apply(params, e1Result.value.params);
|
|
867
|
-
paramsStart += e1Result.value.params.length;
|
|
868
|
-
e2Result = resolveExpression(expression[2], paramsStart, ignore);
|
|
869
|
-
if (!e2Result.ok) {
|
|
870
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> ").concat(e2Result.error));
|
|
871
|
-
}
|
|
872
|
-
if (e2Result.value.text === '') {
|
|
873
|
-
return ignore
|
|
874
|
-
? (0, never_catch_1.ok)(partialQuery())
|
|
875
|
-
: (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> netural"));
|
|
876
|
-
}
|
|
877
|
-
params.push.apply(params, e2Result.value.params);
|
|
878
|
-
paramsStart += e2Result.value.params.length;
|
|
879
|
-
switch (expression[0]) {
|
|
880
|
-
case '=':
|
|
881
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " = ").concat(e2Result.value.text), params));
|
|
882
|
-
case '!=':
|
|
883
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " <> ").concat(e2Result.value.text), params));
|
|
884
|
-
case '>':
|
|
885
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " > ").concat(e2Result.value.text), params));
|
|
886
|
-
case '>=':
|
|
887
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " >= ").concat(e2Result.value.text), params));
|
|
888
|
-
case '<':
|
|
889
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " < ").concat(e2Result.value.text), params));
|
|
890
|
-
case '<=':
|
|
891
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " <= ").concat(e2Result.value.text), params));
|
|
892
|
-
case 'lk':
|
|
893
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " LIKE ").concat(e2Result.value.text), params));
|
|
894
|
-
case '@>':
|
|
895
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " @> ").concat(e2Result.value.text), params));
|
|
896
|
-
case '<@':
|
|
897
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " <@ ").concat(e2Result.value.text), params));
|
|
898
|
-
case '?':
|
|
899
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " ? ").concat(e2Result.value.text), params));
|
|
900
|
-
case 'j-':
|
|
901
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " - ").concat(e2Result.value.text), params));
|
|
902
|
-
}
|
|
903
|
-
case 'in':
|
|
904
|
-
case 'nin':
|
|
905
|
-
case 'lka':
|
|
906
|
-
case 'lks':
|
|
907
|
-
case '?|':
|
|
908
|
-
case '?&':
|
|
909
|
-
case 'j-a':
|
|
910
|
-
e1Result = resolveExpression(expression[1], paramsStart, ignore);
|
|
911
|
-
if (!e1Result.ok) {
|
|
912
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> ").concat(e1Result.error));
|
|
913
|
-
}
|
|
914
|
-
if (e1Result.value.text === '') {
|
|
915
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> netural"));
|
|
916
|
-
}
|
|
917
|
-
params.push.apply(params, e1Result.value.params);
|
|
918
|
-
paramsStart += e1Result.value.params.length;
|
|
919
|
-
if (expression[2] === undefined) {
|
|
920
|
-
return ignore
|
|
921
|
-
? (0, never_catch_1.ok)(partialQuery())
|
|
922
|
-
: (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> undefined"));
|
|
923
|
-
}
|
|
924
|
-
for (var _e = 0, _f = expression[2]; _e < _f.length; _e++) {
|
|
925
|
-
var v2 = _f[_e];
|
|
926
|
-
var v2Result = resolveExpression(v2, paramsStart, ignore);
|
|
927
|
-
if (!v2Result.ok) {
|
|
928
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand][").concat(expression[2].indexOf(v2), "] -> ").concat(v2Result.error));
|
|
929
|
-
}
|
|
930
|
-
if (v2Result.value.text === '') {
|
|
931
|
-
if (ignore) {
|
|
932
|
-
continue;
|
|
933
|
-
}
|
|
934
|
-
else {
|
|
935
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand][").concat(expression[1].indexOf(v2), "] -> neutral"));
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
params.push.apply(params, v2Result.value.params);
|
|
939
|
-
paramsStart += v2Result.value.params.length;
|
|
940
|
-
tokens.push(v2Result.value.text);
|
|
941
|
-
}
|
|
942
|
-
switch (tokens.length) {
|
|
943
|
-
case 0:
|
|
944
|
-
return ignore
|
|
945
|
-
? (0, never_catch_1.ok)(partialQuery())
|
|
946
|
-
: (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> empty"));
|
|
947
|
-
case 1:
|
|
948
|
-
switch (expression[0]) {
|
|
949
|
-
case 'in':
|
|
950
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " = ").concat(tokens[0]), params));
|
|
951
|
-
case 'nin':
|
|
952
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " <> ").concat(tokens[0]), params));
|
|
953
|
-
case 'lka':
|
|
954
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " LIKE ").concat(tokens[0]), params));
|
|
955
|
-
case 'lks':
|
|
956
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " LIKE ").concat(tokens[0]), params));
|
|
957
|
-
case '?|':
|
|
958
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " ? ").concat(tokens[0]), params));
|
|
959
|
-
case '?&':
|
|
960
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " ? ").concat(tokens[0]), params));
|
|
961
|
-
case 'j-a':
|
|
962
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " - ").concat(tokens[0]), params));
|
|
963
|
-
}
|
|
964
|
-
default:
|
|
965
|
-
switch (expression[0]) {
|
|
966
|
-
case 'in':
|
|
967
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " IN ( ").concat(tokens.join(', '), " )"), params));
|
|
968
|
-
case 'nin':
|
|
969
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " NOT IN ( ").concat(tokens.join(', '), " )"), params));
|
|
970
|
-
case 'lka':
|
|
971
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " LIKE ALL( ARRAY[ ").concat(tokens.join(', '), " ] )"), params));
|
|
972
|
-
case 'lks':
|
|
973
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " LIKE SOME( ARRAY[ ").concat(tokens.join(', '), " ] )"), params));
|
|
974
|
-
case '?|':
|
|
975
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " ?| ARRAY[ ").concat(tokens.join(', '), " ]"), params));
|
|
976
|
-
case '?&':
|
|
977
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " ?& ARRAY[ ").concat(tokens.join(', '), " ]"), params));
|
|
978
|
-
case 'j-a':
|
|
979
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " - ARRAY[ ").concat(tokens.join(', '), " ]"), params));
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
case 'bt':
|
|
983
|
-
e1Result = resolveExpression(expression[1], paramsStart, ignore);
|
|
984
|
-
if (!e1Result.ok) {
|
|
985
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> ").concat(e1Result.error));
|
|
986
|
-
}
|
|
987
|
-
if (e1Result.value.text === '') {
|
|
988
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[first operand] -> netural"));
|
|
989
|
-
}
|
|
990
|
-
params.push.apply(params, e1Result.value.params);
|
|
991
|
-
paramsStart += e1Result.value.params.length;
|
|
992
|
-
e2Result = resolveExpression(expression[2], paramsStart, ignore);
|
|
993
|
-
if (!e2Result.ok) {
|
|
994
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> ").concat(e2Result.error));
|
|
995
|
-
}
|
|
996
|
-
if (e2Result.value.text === '') {
|
|
997
|
-
return ignore
|
|
998
|
-
? (0, never_catch_1.ok)(partialQuery())
|
|
999
|
-
: (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[second operand] -> netural"));
|
|
1000
|
-
}
|
|
1001
|
-
params.push.apply(params, e2Result.value.params);
|
|
1002
|
-
paramsStart += e2Result.value.params.length;
|
|
1003
|
-
e3Result = resolveExpression(expression[3], paramsStart, ignore);
|
|
1004
|
-
if (!e3Result.ok) {
|
|
1005
|
-
return (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[third operand] -> ").concat(e3Result.error));
|
|
1006
|
-
}
|
|
1007
|
-
if (e3Result.value.text === '') {
|
|
1008
|
-
return ignore ? (0, never_catch_1.ok)(partialQuery()) : (0, never_catch_1.err)("<".concat((0, dictionary_1.toReservedExpressionKeyDescription)(expression[0]), ">[third operand] -> netural"));
|
|
1009
|
-
}
|
|
1010
|
-
params.push.apply(params, e3Result.value.params);
|
|
1011
|
-
paramsStart += e3Result.value.params.length;
|
|
1012
|
-
return (0, never_catch_1.ok)(partialQuery("".concat(e1Result.value.text, " BETWEEN ").concat(e2Result.value.text, " AND ").concat(e3Result.value.text), params));
|
|
1013
|
-
default:
|
|
1014
|
-
throw 'unexpected error. expect first element to be reserved key.';
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
exports.resolveExpression = resolveExpression;
|
|
1018
|
-
var getTableDataOfJoinSelectColumn = function (tablesData, column) {
|
|
1019
|
-
var splitColumn = column.split('_');
|
|
1020
|
-
if (splitColumn.length < 2) {
|
|
1021
|
-
throw "no separator";
|
|
1022
|
-
}
|
|
1023
|
-
// in case alias or column key have "_". iterate on all of them until a match.
|
|
1024
|
-
var tableAliasUntilIndex = 1;
|
|
1025
|
-
while (true) {
|
|
1026
|
-
var tableAlias = splitColumn.slice(0, tableAliasUntilIndex).join('_');
|
|
1027
|
-
for (var _i = 0, tablesData_1 = tablesData; _i < tablesData_1.length; _i++) {
|
|
1028
|
-
var tableData = tablesData_1[_i];
|
|
1029
|
-
if (tableData.alias === tableAlias &&
|
|
1030
|
-
tableData.table.columns[splitColumn.slice(tableAliasUntilIndex).join('_')] !== undefined) {
|
|
1031
|
-
return tableData;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
if (splitColumn.length > tableAliasUntilIndex + 1) {
|
|
1035
|
-
tableAliasUntilIndex++;
|
|
1036
|
-
}
|
|
1037
|
-
else {
|
|
1038
|
-
throw "column not found";
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
1042
|
-
exports.getTableDataOfJoinSelectColumn = getTableDataOfJoinSelectColumn;
|
|
1043
|
-
var resolveColumn = function (table, column, full, alias) {
|
|
1044
|
-
var _a;
|
|
1045
|
-
if (full === void 0) { full = true; }
|
|
1046
|
-
var prefix;
|
|
1047
|
-
if (full) {
|
|
1048
|
-
if (alias !== undefined) {
|
|
1049
|
-
prefix = "\"".concat(alias, "\".");
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
prefix = "\"".concat(table.schema, "\".\"").concat(table.title, "\".");
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
else {
|
|
1056
|
-
prefix = '';
|
|
1057
|
-
}
|
|
1058
|
-
return prefix + "\"".concat((_a = table.columns[column].title) !== null && _a !== void 0 ? _a : column, "\"");
|
|
1059
|
-
};
|
|
1060
|
-
exports.resolveColumn = resolveColumn;
|
|
1061
|
-
var partialQuery = function (text, params) {
|
|
1062
|
-
if (text === void 0) { text = ''; }
|
|
1063
|
-
if (params === void 0) { params = []; }
|
|
1064
|
-
return ({ text: text, params: params });
|
|
1065
|
-
};
|
|
1066
|
-
exports.partialQuery = partialQuery;
|
|
1067
|
-
//# sourceMappingURL=entity.js.map
|