ronds-metadata 1.3.26 → 1.3.28
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.
|
@@ -68,7 +68,7 @@ declare class DPGraph extends GraphCore<BaseNode, BaseEdge> {
|
|
|
68
68
|
edges: DPEdge[];
|
|
69
69
|
}): void;
|
|
70
70
|
onContextMenu(data: ContextMenuInfo): any;
|
|
71
|
-
onAddCopyCells(nodes:
|
|
71
|
+
onAddCopyCells(nodes: any[], edges: any[]): void;
|
|
72
72
|
onCopyNodes(args: any[]): void;
|
|
73
73
|
updateNodeNameById(id: string, name: string): void;
|
|
74
74
|
clearContextMenuInfo: () => void;
|
|
@@ -16,7 +16,7 @@ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
|
16
16
|
/*
|
|
17
17
|
* @Author: wangxian
|
|
18
18
|
* @Date: 2022-05-24 14:31:01
|
|
19
|
-
* @LastEditTime:
|
|
19
|
+
* @LastEditTime: 2024-01-16 09:05:26
|
|
20
20
|
*/
|
|
21
21
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
22
22
|
import produce from 'immer';
|
|
@@ -30,7 +30,7 @@ import { GraphCore } from '../../framework/graph';
|
|
|
30
30
|
import NodeElement from './comps/NodeElement';
|
|
31
31
|
import { DPEdge } from './comps/shape/edge';
|
|
32
32
|
import { DPNode } from './comps/shape/node';
|
|
33
|
-
import { formatGraphData, copy, formatNodeInfoToNodeMeta, formattedEdgesToEdgeMeta, isClipboardEmpty, cleanClipboard } from './utils';
|
|
33
|
+
import { formatGraphData, copy, formatNodeInfoToNodeMeta, formattedEdgesToEdgeMeta, isClipboardEmpty, cleanClipboard, getCellsInClipboard } from './utils';
|
|
34
34
|
import { deepClone, guid } from '../../utils';
|
|
35
35
|
import { MetadataService } from '../../framework/metadata/MetadataService';
|
|
36
36
|
import { tr } from '../../framework/locale';
|
|
@@ -123,7 +123,7 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
|
|
123
123
|
var targetPort = targetNode.getPort(targetPortId);
|
|
124
124
|
// 如果设置输出port类型,则需要校验类型是否相等
|
|
125
125
|
// 只有类型相等才可以联线
|
|
126
|
-
if ((sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.type) !== '-1' && (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.type) && (targetPort === null || targetPort === void 0 ? void 0 : targetPort.type) && sourcePort.type
|
|
126
|
+
if ((sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.type) !== '-1' && (sourcePort === null || sourcePort === void 0 ? void 0 : sourcePort.type) && (targetPort === null || targetPort === void 0 ? void 0 : targetPort.type) && targetPort.type.indexOf(sourcePort.type) === -1) {
|
|
127
127
|
return false;
|
|
128
128
|
}
|
|
129
129
|
// 判断目标链接桩是否可连接
|
|
@@ -738,7 +738,7 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
|
|
738
738
|
var cells = [];
|
|
739
739
|
var randomId = guid().substring(0, 4);
|
|
740
740
|
nodes.map(function (cell) {
|
|
741
|
-
var _node = cell.
|
|
741
|
+
var _node = cell.data;
|
|
742
742
|
_node = _objectSpread(_objectSpread({}, _node), {}, {
|
|
743
743
|
id: "".concat(_node.id, "_copy_").concat(randomId),
|
|
744
744
|
x: _node.x + 30,
|
|
@@ -749,7 +749,7 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
|
|
749
749
|
_this2.addNode(newNode);
|
|
750
750
|
});
|
|
751
751
|
edges.map(function (cell) {
|
|
752
|
-
var _edge = cell.
|
|
752
|
+
var _edge = cell.data;
|
|
753
753
|
_edge = _objectSpread(_objectSpread({}, _edge), {}, {
|
|
754
754
|
source: "".concat(_edge.source, "_copy_").concat(randomId),
|
|
755
755
|
target: "".concat(_edge.target, "_copy_").concat(randomId)
|
|
@@ -762,7 +762,7 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
|
|
762
762
|
// 回显选中复制的之后的节点
|
|
763
763
|
nodes.map(function (cell) {
|
|
764
764
|
var _this2$graph;
|
|
765
|
-
var _node = cell.
|
|
765
|
+
var _node = cell.data;
|
|
766
766
|
var _cell = (_this2$graph = _this2.graph) === null || _this2$graph === void 0 ? void 0 : _this2$graph.getCellById("".concat(_node.id, "_copy_").concat(randomId));
|
|
767
767
|
cells.push(_cell);
|
|
768
768
|
});
|
|
@@ -787,12 +787,12 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
|
|
787
787
|
if (isClipboardEmpty()) {
|
|
788
788
|
_message.info(tr('剪切板为空,不可粘贴'));
|
|
789
789
|
} else {
|
|
790
|
-
var clipboardCells =
|
|
791
|
-
var selectedNodes = clipboardCells.filter(function (cell) {
|
|
792
|
-
return cell.
|
|
790
|
+
var clipboardCells = getCellsInClipboard();
|
|
791
|
+
var selectedNodes = clipboardCells === null || clipboardCells === void 0 ? void 0 : clipboardCells.filter(function (cell) {
|
|
792
|
+
return (cell === null || cell === void 0 ? void 0 : cell.type) === 'node';
|
|
793
793
|
});
|
|
794
|
-
var selectedEdges = clipboardCells.filter(function (cell) {
|
|
795
|
-
return cell.
|
|
794
|
+
var selectedEdges = clipboardCells === null || clipboardCells === void 0 ? void 0 : clipboardCells.filter(function (cell) {
|
|
795
|
+
return (cell === null || cell === void 0 ? void 0 : cell.shape) === 'DPEdge';
|
|
796
796
|
});
|
|
797
797
|
this.onAddCopyCells(selectedNodes, selectedEdges);
|
|
798
798
|
_message.success(tr('粘贴成功'));
|
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
+
var JsonQL = /*#__PURE__*/function () {
|
|
6
|
+
function JsonQL(schema) {
|
|
7
|
+
_classCallCheck(this, JsonQL);
|
|
8
|
+
this.schema = schema;
|
|
9
|
+
this.errors = [];
|
|
10
|
+
this.fatalError = false;
|
|
11
|
+
this.joinTables = [];
|
|
12
|
+
this.all = false;
|
|
13
|
+
this.select = [];
|
|
14
|
+
this.from = {
|
|
15
|
+
db: '',
|
|
16
|
+
table: ''
|
|
17
|
+
};
|
|
18
|
+
this.join = [];
|
|
19
|
+
this.having = [];
|
|
20
|
+
this.where = [];
|
|
21
|
+
this.limit = [];
|
|
22
|
+
this.columns = [];
|
|
23
|
+
this.values = [];
|
|
24
|
+
this.orderBy = '';
|
|
25
|
+
this.ascOrDesc = '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// █▀▀ █▀▀█ █░░█ █▀▀▄ █▀▄▀█ █▀▀ ▀▀█▀▀ █░░█ █▀▀█ █▀▀▄ █▀▀
|
|
29
|
+
// █░░ █▄▄▀ █░░█ █░░█ █░▀░█ █▀▀ ░░█░░ █▀▀█ █░░█ █░░█ ▀▀█
|
|
30
|
+
// ▀▀▀ ▀░▀▀ ░▀▀▀ ▀▀▀░ ▀░░░▀ ▀▀▀ ░░▀░░ ▀░░▀ ▀▀▀▀ ▀▀▀░ ▀▀▀
|
|
31
|
+
_createClass(JsonQL, [{
|
|
32
|
+
key: "selectQL",
|
|
33
|
+
value: function selectQL(_ref) {
|
|
34
|
+
var db = _ref.db,
|
|
35
|
+
table = _ref.table,
|
|
36
|
+
columns = _ref.columns,
|
|
37
|
+
where = _ref.where,
|
|
38
|
+
having = _ref.having,
|
|
39
|
+
limit = _ref.limit,
|
|
40
|
+
orderBy = _ref.orderBy;
|
|
41
|
+
this.initJsonQL({
|
|
42
|
+
db: db,
|
|
43
|
+
table: table,
|
|
44
|
+
columns: columns,
|
|
45
|
+
where: where,
|
|
46
|
+
having: having,
|
|
47
|
+
limit: limit,
|
|
48
|
+
orderBy: orderBy
|
|
49
|
+
});
|
|
50
|
+
var selectString = this.buildSelect();
|
|
51
|
+
if (this.fatalError) {
|
|
52
|
+
return {
|
|
53
|
+
status: 'error',
|
|
54
|
+
query: selectString,
|
|
55
|
+
errors: this.errors
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
status: 'success',
|
|
60
|
+
query: selectString,
|
|
61
|
+
errors: this.errors
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "createQL",
|
|
66
|
+
value: function createQL(_ref2, data) {
|
|
67
|
+
var db = _ref2.db,
|
|
68
|
+
table = _ref2.table,
|
|
69
|
+
columns = _ref2.columns,
|
|
70
|
+
where = _ref2.where,
|
|
71
|
+
having = _ref2.having,
|
|
72
|
+
limit = _ref2.limit;
|
|
73
|
+
if (!data) {
|
|
74
|
+
this.errors.push('Data must be provided in a createQL');
|
|
75
|
+
this.fatalError = true;
|
|
76
|
+
}
|
|
77
|
+
this.initJsonQL({
|
|
78
|
+
db: db,
|
|
79
|
+
table: table,
|
|
80
|
+
columns: columns,
|
|
81
|
+
where: where,
|
|
82
|
+
having: having,
|
|
83
|
+
limit: limit
|
|
84
|
+
}, data);
|
|
85
|
+
this.pushPrimaryKey(db, table);
|
|
86
|
+
var selectString = this.buildCreate();
|
|
87
|
+
if (this.fatalError) {
|
|
88
|
+
return {
|
|
89
|
+
status: 'error',
|
|
90
|
+
query: selectString,
|
|
91
|
+
errors: this.errors
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
status: 'success',
|
|
96
|
+
query: selectString,
|
|
97
|
+
errors: this.errors
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "updateQL",
|
|
102
|
+
value: function updateQL(_ref3, data) {
|
|
103
|
+
var db = _ref3.db,
|
|
104
|
+
table = _ref3.table,
|
|
105
|
+
columns = _ref3.columns,
|
|
106
|
+
where = _ref3.where,
|
|
107
|
+
having = _ref3.having,
|
|
108
|
+
limit = _ref3.limit,
|
|
109
|
+
affectAll = _ref3.affectAll;
|
|
110
|
+
if (!data) {
|
|
111
|
+
this.errors.push('Data must be provided in a updateQL');
|
|
112
|
+
this.fatalError = true;
|
|
113
|
+
}
|
|
114
|
+
this.initJsonQL({
|
|
115
|
+
db: db,
|
|
116
|
+
table: table,
|
|
117
|
+
columns: columns,
|
|
118
|
+
where: where,
|
|
119
|
+
having: having,
|
|
120
|
+
limit: limit,
|
|
121
|
+
affectAll: affectAll
|
|
122
|
+
}, data);
|
|
123
|
+
var selectString = this.buildUpdate();
|
|
124
|
+
if (this.fatalError) {
|
|
125
|
+
return {
|
|
126
|
+
status: 'error',
|
|
127
|
+
query: selectString,
|
|
128
|
+
errors: this.errors
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
status: 'success',
|
|
133
|
+
query: selectString,
|
|
134
|
+
errors: this.errors
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}, {
|
|
138
|
+
key: "deleteQL",
|
|
139
|
+
value: function deleteQL(_ref4) {
|
|
140
|
+
var db = _ref4.db,
|
|
141
|
+
table = _ref4.table,
|
|
142
|
+
columns = _ref4.columns,
|
|
143
|
+
where = _ref4.where,
|
|
144
|
+
having = _ref4.having,
|
|
145
|
+
limit = _ref4.limit,
|
|
146
|
+
affectAll = _ref4.affectAll;
|
|
147
|
+
this.initJsonQL({
|
|
148
|
+
db: db,
|
|
149
|
+
table: table,
|
|
150
|
+
columns: columns,
|
|
151
|
+
where: where,
|
|
152
|
+
having: having,
|
|
153
|
+
limit: limit,
|
|
154
|
+
affectAll: affectAll
|
|
155
|
+
});
|
|
156
|
+
var selectString = this.buildDelete();
|
|
157
|
+
if (this.fatalError) {
|
|
158
|
+
return {
|
|
159
|
+
status: 'error',
|
|
160
|
+
query: selectString,
|
|
161
|
+
errors: this.errors
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
status: 'success',
|
|
166
|
+
query: selectString,
|
|
167
|
+
errors: this.errors
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// █▀▀ █▀▀▄ ▀▀█▀▀ █▀▀█ █░░█ █▀▀█ █▀▀█ ░▀░ █▀▀▄ ▀▀█▀▀
|
|
172
|
+
// █▀▀ █░░█ ░░█░░ █▄▄▀ █▄▄█ █░░█ █░░█ ▀█▀ █░░█ ░░█░░
|
|
173
|
+
// ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀▀ ▄▄▄█ █▀▀▀ ▀▀▀▀ ▀▀▀ ▀░░▀ ░░▀░░
|
|
174
|
+
}, {
|
|
175
|
+
key: "initJsonQL",
|
|
176
|
+
value: function initJsonQL(_ref5, data) {
|
|
177
|
+
var db = _ref5.db,
|
|
178
|
+
table = _ref5.table,
|
|
179
|
+
columns = _ref5.columns,
|
|
180
|
+
where = _ref5.where,
|
|
181
|
+
having = _ref5.having,
|
|
182
|
+
limit = _ref5.limit,
|
|
183
|
+
orderBy = _ref5.orderBy,
|
|
184
|
+
affectAll = _ref5.affectAll;
|
|
185
|
+
if (this.validBySchema(db, table)) {
|
|
186
|
+
this.from = {
|
|
187
|
+
db: db,
|
|
188
|
+
table: table
|
|
189
|
+
};
|
|
190
|
+
} else {
|
|
191
|
+
this.fatalError = true;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (affectAll) {
|
|
195
|
+
this.affectAll = affectAll;
|
|
196
|
+
}
|
|
197
|
+
if (data) {
|
|
198
|
+
this.parseData(db, table, data);
|
|
199
|
+
}
|
|
200
|
+
if (columns && (columns || []).length > 0) {
|
|
201
|
+
this.pushCols({
|
|
202
|
+
dbName: db,
|
|
203
|
+
dbAlias: db
|
|
204
|
+
}, {
|
|
205
|
+
tableName: table,
|
|
206
|
+
tableAlias: table
|
|
207
|
+
}, columns);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// If there's no selections then get all non-hidden columns from the schema
|
|
211
|
+
if (this.select.length === 0) {
|
|
212
|
+
this.pushSelFromSchema(db, table);
|
|
213
|
+
}
|
|
214
|
+
if (where && (where || []).length > 0) {
|
|
215
|
+
this.pushWhere({
|
|
216
|
+
dbName: db,
|
|
217
|
+
dbAlias: db
|
|
218
|
+
}, {
|
|
219
|
+
tableName: table,
|
|
220
|
+
tableAlias: table
|
|
221
|
+
}, where);
|
|
222
|
+
}
|
|
223
|
+
if (having && (having || []).length > 0) {
|
|
224
|
+
this.pushHaving(having);
|
|
225
|
+
}
|
|
226
|
+
if (orderBy) {
|
|
227
|
+
this.pushOrderBy(db, table, orderBy);
|
|
228
|
+
}
|
|
229
|
+
if (limit) {
|
|
230
|
+
this.limit = limit;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// █▀▀▄ █▀▀█ ▀▀█▀▀ █▀▀█
|
|
235
|
+
// █░░█ █▄▄█ ░░█░░ █▄▄█
|
|
236
|
+
// ▀▀▀░ ▀░░▀ ░░▀░░ ▀░░▀
|
|
237
|
+
}, {
|
|
238
|
+
key: "parseData",
|
|
239
|
+
value: function parseData(db, table, data) {
|
|
240
|
+
var _this = this;
|
|
241
|
+
Object.keys(data).forEach(function (key) {
|
|
242
|
+
if (_this.validJQString(db, table, key)) {
|
|
243
|
+
_this.pushJQString(db, table, key, data[key]);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (!_this.validBySchema(db, table, key)) return;
|
|
247
|
+
if (typeof data[key] === 'number') {
|
|
248
|
+
_this.values.push(data[key]);
|
|
249
|
+
} else if (typeof data[key] === 'string') {
|
|
250
|
+
_this.values.push("'".concat(data[key], "'"));
|
|
251
|
+
} else {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
_this.columns.push(key);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// █▀▀█ █░░█ █▀▀ █░░█ █▀▀ █░░█ █▀▀▄ █▀▀ ▀▀█▀▀ ░▀░ █▀▀█ █▀▀▄ █▀▀
|
|
259
|
+
// █░░█ █░░█ ▀▀█ █▀▀█ █▀▀ █░░█ █░░█ █░░ ░░█░░ ▀█▀ █░░█ █░░█ ▀▀█
|
|
260
|
+
// █▀▀▀ ░▀▀▀ ▀▀▀ ▀░░▀ ▀░░ ░▀▀▀ ▀░░▀ ▀▀▀ ░░▀░░ ▀▀▀ ▀▀▀▀ ▀░░▀ ▀▀▀
|
|
261
|
+
}, {
|
|
262
|
+
key: "pushPrimaryKey",
|
|
263
|
+
value: function pushPrimaryKey(db, table) {
|
|
264
|
+
var _this2 = this;
|
|
265
|
+
var tableSchema = this.schema[db][table];
|
|
266
|
+
Object.keys(tableSchema).forEach(function (key) {
|
|
267
|
+
if (_this2.columns.includes(key)) return;
|
|
268
|
+
if (tableSchema[key].primaryKey && typeof tableSchema[key].primaryKey === 'function') {
|
|
269
|
+
if (tableSchema[key].type === 'json') {
|
|
270
|
+
_this2.errors.push('primaryKey must be either number or string type, check your schema for ' + db + '.' + table);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
_this2.columns.push("".concat(key));
|
|
274
|
+
var primaryKey = tableSchema[key].primaryKey();
|
|
275
|
+
if (tableSchema[key].type === 'string') _this2.values.push("'".concat(primaryKey, "'"));else if (tableSchema[key].type === 'number') _this2.values.push("".concat(primaryKey));else if (!tableSchema[key].type) _this2.values.push("'".concat(primaryKey, "'"));
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}, {
|
|
280
|
+
key: "pushQuery",
|
|
281
|
+
value: function pushQuery(db, table, key, value) {
|
|
282
|
+
// let key = '$jsonForm[?Booking Month].value';
|
|
283
|
+
|
|
284
|
+
var column = this.extractColFromJQString(db, table, key);
|
|
285
|
+
column = "".concat(db, ".").concat(table, ".").concat(column);
|
|
286
|
+
value = "IF(\n ".concat(this.jQSet(db, table, key, value), " IS NOT NULL,\n ").concat(this.jQSet(db, table, key, value), ",\n ").concat(column, "\n )");
|
|
287
|
+
this.columns.push("".concat(column));
|
|
288
|
+
this.values.push(value);
|
|
289
|
+
}
|
|
290
|
+
}, {
|
|
291
|
+
key: "pushOrderBy",
|
|
292
|
+
value: function pushOrderBy(db, table, orderBy) {
|
|
293
|
+
if (this.validJQString(db, table, orderBy.name)) {
|
|
294
|
+
this.orderBy = this.jQExtract(db, table, orderBy.name);
|
|
295
|
+
} else if (this.validBySchema(db, table, orderBy.name)) {
|
|
296
|
+
this.orderBy = orderBy.name;
|
|
297
|
+
}
|
|
298
|
+
if (this.orderBy.length === 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (orderBy.desc && typeof orderBy.desc !== 'boolean') {
|
|
302
|
+
this.errors.push('orderBy.desc must be a Boolean type value.');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.ascOrDesc = orderBy.desc ? 'DESC' : 'ASC';
|
|
306
|
+
}
|
|
307
|
+
}, {
|
|
308
|
+
key: "pushCols",
|
|
309
|
+
value: function pushCols(dbObj, tableObj, columns) {
|
|
310
|
+
if (!this.validBySchema(dbObj.dbName, tableObj.tableName)) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
var nameCols = columns.filter(function (col) {
|
|
314
|
+
return col.name || col.number || col.string || col.count;
|
|
315
|
+
});
|
|
316
|
+
var joinCols = columns.filter(function (col) {
|
|
317
|
+
return col.join;
|
|
318
|
+
});
|
|
319
|
+
var fnCols = columns.filter(function (col) {
|
|
320
|
+
return col.fn;
|
|
321
|
+
});
|
|
322
|
+
if (nameCols.length > 0) {
|
|
323
|
+
this.pushNameCols(dbObj, tableObj, nameCols);
|
|
324
|
+
}
|
|
325
|
+
if (joinCols.length > 0) {
|
|
326
|
+
this.pushJoinCols(dbObj, tableObj, joinCols);
|
|
327
|
+
}
|
|
328
|
+
if (fnCols.length > 0) {
|
|
329
|
+
this.pushFnCols(dbObj, tableObj, fnCols);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}, {
|
|
333
|
+
key: "pushSelFromSchema",
|
|
334
|
+
value: function pushSelFromSchema(db, table) {
|
|
335
|
+
var _this3 = this;
|
|
336
|
+
var fromTable = this.schema[db][table];
|
|
337
|
+
return "".concat(Object.keys(fromTable).filter(function (key) {
|
|
338
|
+
return fromTable[key].hidden !== true;
|
|
339
|
+
}).forEach(function (key) {
|
|
340
|
+
_this3.select.push("".concat(db, ".").concat(table, ".").concat(key));
|
|
341
|
+
}));
|
|
342
|
+
}
|
|
343
|
+
}, {
|
|
344
|
+
key: "pushNameCols",
|
|
345
|
+
value: function pushNameCols(dbObj, tableObj, nameCols) {
|
|
346
|
+
var _this4 = this;
|
|
347
|
+
nameCols.forEach(function (col) {
|
|
348
|
+
var selectStr = '';
|
|
349
|
+
if (col.name && _this4.validJQString(dbObj.dbName, tableObj.tableName, col.name)) {
|
|
350
|
+
selectStr = _this4.jQExtract(dbObj.dbName, tableObj.tableName, col.name);
|
|
351
|
+
} else if (col.name && _this4.validBySchema(dbObj.dbName, tableObj.tableName, col.name)) {
|
|
352
|
+
selectStr = "".concat(dbObj.dbAlias, ".").concat(tableObj.tableAlias, ".").concat(col.name);
|
|
353
|
+
} else if (col.number && typeof col.number === 'number') {
|
|
354
|
+
selectStr = "".concat(col.number);
|
|
355
|
+
} else if (col.number) {
|
|
356
|
+
_this4.errors.push(col.number + ' is not a number');
|
|
357
|
+
} else if (col.string && _this4.validString(col.string)) {
|
|
358
|
+
selectStr = "'".concat(col.string, "'");
|
|
359
|
+
} else if (col.jsonExtract && _this4.validString(col.jsonExtract.search) && _this4.validString(col.jsonExtract.target)) {
|
|
360
|
+
selectStr = "JSON_EXTRACT(JSON_EXTRACT(".concat(selectStr, ", CONCAT('$[', SUBSTR(JSON_SEARCH(").concat(selectStr, ", 'one', '").concat(col.jsonExtract.search, "'), 4, 1), ']')), '$.").concat(col.jsonExtract.target, "')");
|
|
361
|
+
}
|
|
362
|
+
if (col.count) {
|
|
363
|
+
selectStr += _this4.countString(dbObj.dbName, tableObj.tableName, col.count);
|
|
364
|
+
}
|
|
365
|
+
// We can't have an `as` without something before it so also check the selectStr length
|
|
366
|
+
if (col.as && _this4.validString(col.as) && selectStr.length > 0) {
|
|
367
|
+
selectStr += " AS ".concat(col.as);
|
|
368
|
+
}
|
|
369
|
+
if (selectStr.length > 0) {
|
|
370
|
+
_this4.select.push(selectStr);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}, {
|
|
375
|
+
key: "pushJoinCols",
|
|
376
|
+
value: function pushJoinCols(dbObj, tableObj, joinCols) {
|
|
377
|
+
var _this5 = this;
|
|
378
|
+
joinCols.forEach(function (col) {
|
|
379
|
+
if (!_this5.validBySchema(dbObj.dbName, tableObj.tableName, col.join.where[0].name)) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (col.join.where[0].isnot) {
|
|
383
|
+
if (!_this5.validBySchema(col.join.db, col.join.table, col.join.where[0].isnot)) return;
|
|
384
|
+
}
|
|
385
|
+
if (col.join.where[0].is) {
|
|
386
|
+
if (!_this5.validBySchema(col.join.db, col.join.table, col.join.where[0].is)) return;
|
|
387
|
+
}
|
|
388
|
+
var joinStr = '';
|
|
389
|
+
var aliasTableName = _this5.aliasReplicaTableNames(col.join.table);
|
|
390
|
+
var aliasString = '';
|
|
391
|
+
if (col.join.table !== aliasTableName) {
|
|
392
|
+
aliasString = " AS ".concat(aliasTableName);
|
|
393
|
+
}
|
|
394
|
+
if (col.join.where[0].isnot) {
|
|
395
|
+
joinStr = "".concat(col.join.db, ".").concat(col.join.table).concat(aliasString, " ON ").concat(dbObj.dbName, ".").concat(tableObj.tableName, ".").concat(col.join.where[0].name, " != ").concat(col.join.db, ".").concat(aliasTableName, ".").concat(col.join.where[0].isnot);
|
|
396
|
+
}
|
|
397
|
+
if (col.join.where[0].is) {
|
|
398
|
+
joinStr = "".concat(col.join.db, ".").concat(col.join.table).concat(aliasString, " ON ").concat(dbObj.dbName, ".").concat(tableObj.tableName, ".").concat(col.join.where[0].name, " = ").concat(col.join.db, ".").concat(aliasTableName, ".").concat(col.join.where[0].is);
|
|
399
|
+
}
|
|
400
|
+
if (joinStr.length > 0) {
|
|
401
|
+
_this5.join.push(joinStr);
|
|
402
|
+
}
|
|
403
|
+
_this5.pushCols({
|
|
404
|
+
dbName: col.join.db,
|
|
405
|
+
dbAlias: col.join.db
|
|
406
|
+
}, {
|
|
407
|
+
tableName: col.join.table,
|
|
408
|
+
tableAlias: aliasTableName
|
|
409
|
+
}, col.join.columns);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}, {
|
|
413
|
+
key: "pushFnCols",
|
|
414
|
+
value: function pushFnCols(dbObj, tableObj, fnCols) {
|
|
415
|
+
var _this6 = this;
|
|
416
|
+
fnCols.forEach(function (col) {
|
|
417
|
+
var selectStr = '';
|
|
418
|
+
if (!_this6.validBySchema(dbObj.dbName, tableObj.tableName)) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
selectStr = _this6.fnString(dbObj.dbAlias, tableObj.tableAlias, col.fn, col.args);
|
|
422
|
+
if (col.as && _this6.validString(col.as)) {
|
|
423
|
+
selectStr += " AS ".concat(col.as);
|
|
424
|
+
}
|
|
425
|
+
if (selectStr.length > 0) {
|
|
426
|
+
_this6.select.push(selectStr);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}, {
|
|
431
|
+
key: "pushOrArrWhere",
|
|
432
|
+
value: function pushOrArrWhere(dbObj, tableObj, or) {
|
|
433
|
+
var _this7 = this;
|
|
434
|
+
var whereStr = '';
|
|
435
|
+
or.forEach(function (wh, i) {
|
|
436
|
+
if (_this7.validJQString(dbObj.dbName, tableObj.tableName, wh.name)) {
|
|
437
|
+
if (i !== 0) {
|
|
438
|
+
whereStr += ' OR ';
|
|
439
|
+
}
|
|
440
|
+
whereStr += "".concat(_this7.whString(dbObj.dbName, tableObj.tableName, wh));
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (_this7.validBySchema(dbObj.dbName, tableObj.tableName, wh.name)) {
|
|
444
|
+
if (i !== 0) {
|
|
445
|
+
whereStr += ' OR ';
|
|
446
|
+
}
|
|
447
|
+
whereStr += "".concat(_this7.whString(dbObj.dbName, tableObj.tableName, wh));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
if (whereStr.length > 0) {
|
|
452
|
+
this.where.push(whereStr);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
key: "pushOrArrHaving",
|
|
457
|
+
value: function pushOrArrHaving(or) {
|
|
458
|
+
var _this8 = this;
|
|
459
|
+
var havingStr = "(".concat(or.filter(function (ha) {
|
|
460
|
+
return _this8.validString(ha.name) && (_this8.validString(ha.is) || _this8.validString(ha.isnot));
|
|
461
|
+
}).map(function (ha) {
|
|
462
|
+
var value = ha.is && typeof ha.is === 'number' ? "= ".concat(ha.is) : ha.is && typeof ha.is === 'string' ? "= '".concat(ha.is, "'") : ha.isnot && typeof ha.isnot === 'number' ? "!= ".concat(ha.isnot) : ha.isnot && typeof ha.isnot === 'string' ? "!= '".concat(ha.isnot, "'") : '';
|
|
463
|
+
return "".concat(ha.name, " ").concat(value);
|
|
464
|
+
}).join(' OR '), ")");
|
|
465
|
+
if (havingStr.length > 0) {
|
|
466
|
+
this.having.push(havingStr);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}, {
|
|
470
|
+
key: "pushWhere",
|
|
471
|
+
value: function pushWhere(dbObj, tableObj, where) {
|
|
472
|
+
var _this9 = this;
|
|
473
|
+
where.forEach(function (wh) {
|
|
474
|
+
var whereStr = '';
|
|
475
|
+
if ((wh || []).length > 0) {
|
|
476
|
+
_this9.pushOrArrWhere(dbObj, tableObj, wh);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (_this9.validJQString(dbObj.dbName, tableObj.tableName, wh.name)) {
|
|
480
|
+
whereStr = "".concat(_this9.whString(dbObj.dbName, tableObj.tableName, wh));
|
|
481
|
+
if (whereStr.length > 0) {
|
|
482
|
+
_this9.where.push(whereStr);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (_this9.validBySchema(dbObj.dbName, tableObj.tableName, wh.name)) {
|
|
487
|
+
whereStr = "".concat(_this9.whString(dbObj.dbName, tableObj.tableName, wh));
|
|
488
|
+
if (whereStr.length > 0) {
|
|
489
|
+
_this9.where.push(whereStr);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
key: "pushHaving",
|
|
497
|
+
value: function pushHaving(having) {
|
|
498
|
+
var _this10 = this;
|
|
499
|
+
having.forEach(function (ha) {
|
|
500
|
+
// This check here is a bit out of place but we want to keep
|
|
501
|
+
// the old nested OR syntax so there it is.
|
|
502
|
+
if (!ha.name && ha.or && (ha.or || []).length > 0) {
|
|
503
|
+
_this10.pushOrArrHaving(ha.or);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
var havingStr = "".concat(_this10.haString(ha));
|
|
507
|
+
if (havingStr.length > 0) {
|
|
508
|
+
_this10.having.push(havingStr);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// █▀▀ ▀▀█▀▀ █▀▀█ ░▀░ █▀▀▄ █▀▀▀ █▀▀ █░░█ █▀▀▄ █▀▀ ▀▀█▀▀ ░▀░ █▀▀█ █▀▀▄ █▀▀
|
|
514
|
+
// ▀▀█ ░░█░░ █▄▄▀ ▀█▀ █░░█ █░▀█ █▀▀ █░░█ █░░█ █░░ ░░█░░ ▀█▀ █░░█ █░░█ ▀▀█
|
|
515
|
+
// ▀▀▀ ░░▀░░ ▀░▀▀ ▀▀▀ ▀░░▀ ▀▀▀▀ ▀░░ ░▀▀▀ ▀░░▀ ▀▀▀ ░░▀░░ ▀▀▀ ▀▀▀▀ ▀░░▀ ▀▀▀
|
|
516
|
+
}, {
|
|
517
|
+
key: "countString",
|
|
518
|
+
value: function countString(db, table, count) {
|
|
519
|
+
var _this11 = this;
|
|
520
|
+
var whereStr = count.where.map(function (wh) {
|
|
521
|
+
return _this11.whString(count.db, count.table, wh);
|
|
522
|
+
}).join();
|
|
523
|
+
return "(SELECT COUNT(*) FROM ".concat(count.db, ".").concat(count.table, " WHERE ").concat(whereStr, ")");
|
|
524
|
+
}
|
|
525
|
+
}, {
|
|
526
|
+
key: "orWhString",
|
|
527
|
+
value: function orWhString(db, table, orArr) {
|
|
528
|
+
var _this12 = this;
|
|
529
|
+
return "".concat(orArr.filter(function (or) {
|
|
530
|
+
return or.name && (_this12.validBySchema(db, table, or.name) || _this12.validJQString(db, table, or.name));
|
|
531
|
+
}).map(function (or) {
|
|
532
|
+
return _this12.whString(db, table, or);
|
|
533
|
+
}).join(' OR '));
|
|
534
|
+
}
|
|
535
|
+
}, {
|
|
536
|
+
key: "orHaString",
|
|
537
|
+
value: function orHaString(orArr) {
|
|
538
|
+
var _this13 = this;
|
|
539
|
+
return "".concat(orArr.filter(function (or) {
|
|
540
|
+
return or.name && _this13.validString(or.name);
|
|
541
|
+
}).map(function (or) {
|
|
542
|
+
return _this13.haString(or);
|
|
543
|
+
}).join(' OR '));
|
|
544
|
+
}
|
|
545
|
+
}, {
|
|
546
|
+
key: "whString",
|
|
547
|
+
value: function whString(db, table, wh) {
|
|
548
|
+
if (wh.is && !this.validString(wh.is)) return '';
|
|
549
|
+
if (wh.isnot && !this.validString(wh.isnot)) return '';
|
|
550
|
+
if (wh.isbetween && !this.validString(wh.isbetween[0])) return '';
|
|
551
|
+
if (wh.isbetween && !this.validString(wh.isbetween[1])) return '';
|
|
552
|
+
var value = typeof wh.is === 'number' ? "= ".concat(wh.is) : typeof wh.is === 'string' ? "= '".concat(wh.is, "'") : typeof wh.isnot === 'number' ? "!= ".concat(wh.isnot) : typeof wh.isnot === 'string' ? "!= '".concat(wh.isnot, "'") : wh.isbetween ? "BETWEEN ".concat(wh.isbetween.map(function (val) {
|
|
553
|
+
return typeof val === 'string' ? "'".concat(val, "'") : val;
|
|
554
|
+
}).join(' AND ')) : '';
|
|
555
|
+
var name = this.validJQString(db, table, wh.name) ? this.jQExtract(db, table, wh.name) : "".concat(db, ".").concat(table, ".").concat(wh.name);
|
|
556
|
+
return "".concat(name, " ").concat(value);
|
|
557
|
+
}
|
|
558
|
+
}, {
|
|
559
|
+
key: "haString",
|
|
560
|
+
value: function haString(ha) {
|
|
561
|
+
if (ha.name && !this.validString(ha.name)) {
|
|
562
|
+
return '';
|
|
563
|
+
}
|
|
564
|
+
if (ha.isnot && !this.validString(ha.isnot)) {
|
|
565
|
+
return '';
|
|
566
|
+
}
|
|
567
|
+
if (ha.is && !this.validString(ha.is)) {
|
|
568
|
+
return '';
|
|
569
|
+
}
|
|
570
|
+
if ((ha || []).length > 0 && _typeof(ha) === 'object') {
|
|
571
|
+
return this.orHaString(ha);
|
|
572
|
+
}
|
|
573
|
+
var value = typeof ha.is === 'number' ? "= ".concat(ha.is) : typeof ha.is === 'string' ? "= '".concat(ha.is, "'") : typeof ha.isnot === 'number' ? "!= ".concat(ha.isnot) : typeof ha.isnot === 'string' ? "!= '".concat(ha.isnot, "'") : ha.isbetween ? "BETWEEN ".concat(ha.isbetween.map(function (val) {
|
|
574
|
+
return typeof val === 'string' ? "'".concat(val, "'") : val;
|
|
575
|
+
}).join(' AND ')) : '';
|
|
576
|
+
var name = this.validPlainJQString(ha.name) ? this.plainjQExtract(ha.name) : "".concat(ha.name);
|
|
577
|
+
return "".concat(name, " ").concat(value);
|
|
578
|
+
}
|
|
579
|
+
}, {
|
|
580
|
+
key: "fnString",
|
|
581
|
+
value: function fnString(db, table, fn, args) {
|
|
582
|
+
var _this14 = this;
|
|
583
|
+
if (!this.validString(fn)) return '';
|
|
584
|
+
return "".concat(fn, "(").concat(args.map(function (arg) {
|
|
585
|
+
if (_this14.validJQString(db, table, arg.name)) {
|
|
586
|
+
return _this14.jQExtract(db, table, arg.name);
|
|
587
|
+
} else if (arg.name) {
|
|
588
|
+
return "".concat(db, ".").concat(table, ".").concat(arg.name);
|
|
589
|
+
}
|
|
590
|
+
if (arg.number && typeof arg.number === 'number') {
|
|
591
|
+
return "".concat(arg.number);
|
|
592
|
+
} else if (arg.number) {
|
|
593
|
+
_this14.errors(arg.number + ' in fn object is not a number type');
|
|
594
|
+
}
|
|
595
|
+
if (arg.string && _this14.validString(arg.string)) {
|
|
596
|
+
return "'".concat(arg.string, "'");
|
|
597
|
+
}
|
|
598
|
+
if (arg.fn) {
|
|
599
|
+
return _this14.fnString(db, table, arg.fn, arg.args);
|
|
600
|
+
}
|
|
601
|
+
}).join(), ")");
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// █▀▀▄ █░░█ ░▀░ █░░ █▀▀▄ █▀▀ █▀▀█ █▀▀
|
|
605
|
+
// █▀▀▄ █░░█ ▀█▀ █░░ █░░█ █▀▀ █▄▄▀ ▀▀█
|
|
606
|
+
// ▀▀▀░ ░▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀░ ▀▀▀ ▀░▀▀ ▀▀▀
|
|
607
|
+
}, {
|
|
608
|
+
key: "buildSelect",
|
|
609
|
+
value: function buildSelect() {
|
|
610
|
+
var select = '';
|
|
611
|
+
if (this.select.length > 0) {
|
|
612
|
+
select = "SELECT ".concat(this.select.map(function (selStr) {
|
|
613
|
+
return selStr;
|
|
614
|
+
}).join());
|
|
615
|
+
}
|
|
616
|
+
var from = "FROM ".concat(this.from.db, ".").concat(this.from.table);
|
|
617
|
+
var join = '';
|
|
618
|
+
if (this.join.length > 0) {
|
|
619
|
+
join = "".concat(this.join.map(function (jStr) {
|
|
620
|
+
return "LEFT JOIN ".concat(jStr);
|
|
621
|
+
}).join(' '));
|
|
622
|
+
}
|
|
623
|
+
var where = '';
|
|
624
|
+
if (this.where.length > 0) {
|
|
625
|
+
where = "WHERE ".concat(this.where.map(function (whStr) {
|
|
626
|
+
return "(".concat(whStr, ")");
|
|
627
|
+
}).join(' AND '));
|
|
628
|
+
}
|
|
629
|
+
var having = '';
|
|
630
|
+
if (this.having.length > 0) {
|
|
631
|
+
having = "HAVING ".concat(this.having.map(function (haStr) {
|
|
632
|
+
return "(".concat(haStr, ")");
|
|
633
|
+
}).join(' AND '));
|
|
634
|
+
}
|
|
635
|
+
var orderBy = '';
|
|
636
|
+
if (this.orderBy.length > 0) {
|
|
637
|
+
orderBy = "ORDER BY ".concat(this.orderBy);
|
|
638
|
+
}
|
|
639
|
+
var ascOrDesc = '';
|
|
640
|
+
if (this.ascOrDesc.length > 0) {
|
|
641
|
+
ascOrDesc = this.ascOrDesc;
|
|
642
|
+
}
|
|
643
|
+
var limit = '';
|
|
644
|
+
if (this.limit.length > 0) {
|
|
645
|
+
limit = "LIMIT ".concat(this.limit.map(function (num) {
|
|
646
|
+
return num;
|
|
647
|
+
}).join());
|
|
648
|
+
}
|
|
649
|
+
return "".concat(select, " ").concat(from, " ").concat(join, " ").concat(where, " ").concat(having, " ").concat(orderBy, " ").concat(ascOrDesc, " ").concat(limit);
|
|
650
|
+
}
|
|
651
|
+
}, {
|
|
652
|
+
key: "buildCreate",
|
|
653
|
+
value: function buildCreate() {
|
|
654
|
+
var from = "INSERT INTO ".concat(this.from.db, ".").concat(this.from.table);
|
|
655
|
+
var columns = '';
|
|
656
|
+
if (this.columns.length > 0) {
|
|
657
|
+
columns = "(".concat(this.columns.join(), ")");
|
|
658
|
+
}
|
|
659
|
+
var values = '';
|
|
660
|
+
if (this.values.length > 0) {
|
|
661
|
+
values = "VALUES (".concat(this.values.join(), ")");
|
|
662
|
+
}
|
|
663
|
+
return "".concat(from, " ").concat(columns, " ").concat(values);
|
|
664
|
+
}
|
|
665
|
+
}, {
|
|
666
|
+
key: "buildUpdate",
|
|
667
|
+
value: function buildUpdate() {
|
|
668
|
+
var _this15 = this;
|
|
669
|
+
var from = "UPDATE ".concat(this.from.db, ".").concat(this.from.table);
|
|
670
|
+
var set = '';
|
|
671
|
+
if (this.columns.length === this.values.length && this.columns.length > 0 && this.values.length > 0) {
|
|
672
|
+
set = "SET ".concat(this.columns.map(function (col, i) {
|
|
673
|
+
return "".concat(col, " = ").concat(_this15.values[i]);
|
|
674
|
+
}).join());
|
|
675
|
+
}
|
|
676
|
+
var where = '';
|
|
677
|
+
if (this.where.length > 0) {
|
|
678
|
+
where = "WHERE ".concat(this.where.map(function (whStr) {
|
|
679
|
+
return "(".concat(whStr, ")");
|
|
680
|
+
}).join(' AND '));
|
|
681
|
+
} else if (!this.affectAll) {
|
|
682
|
+
this.fatalError = true;
|
|
683
|
+
this.errors.push('No where clause provided. If you want to update all records then add `affectAll: true` to your queryObject');
|
|
684
|
+
}
|
|
685
|
+
var having = '';
|
|
686
|
+
if (this.having.length > 0) {
|
|
687
|
+
having = "HAVING ".concat(this.having.map(function (haStr) {
|
|
688
|
+
return "(".concat(haStr, ")");
|
|
689
|
+
}).join(' AND '));
|
|
690
|
+
}
|
|
691
|
+
return "".concat(from, " ").concat(set, " ").concat(where, " ").concat(having);
|
|
692
|
+
}
|
|
693
|
+
}, {
|
|
694
|
+
key: "buildDelete",
|
|
695
|
+
value: function buildDelete() {
|
|
696
|
+
var from = "DELETE FROM ".concat(this.from.db, ".").concat(this.from.table);
|
|
697
|
+
var where = '';
|
|
698
|
+
if (this.where.length > 0) {
|
|
699
|
+
where = "WHERE ".concat(this.where.map(function (whStr) {
|
|
700
|
+
return "(".concat(whStr, ")");
|
|
701
|
+
}).join(' AND '));
|
|
702
|
+
} else if (!this.affectAll) {
|
|
703
|
+
this.fatalError = true;
|
|
704
|
+
this.errors.push('No where clause provided. If you want to delete all records then add `affectAll: true` to your queryObject');
|
|
705
|
+
}
|
|
706
|
+
return "".concat(from, " ").concat(where);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// █░░█ ▀▀█▀▀ ░▀░ █░░ ░▀░ ▀▀█▀▀ ░▀░ █▀▀ █▀▀
|
|
710
|
+
// █░░█ ░░█░░ ▀█▀ █░░ ▀█▀ ░░█░░ ▀█▀ █▀▀ ▀▀█
|
|
711
|
+
// ░▀▀▀ ░░▀░░ ▀▀▀ ▀▀▀ ▀▀▀ ░░▀░░ ▀▀▀ ▀▀▀ ▀▀▀
|
|
712
|
+
}, {
|
|
713
|
+
key: "aliasReplicaTableNames",
|
|
714
|
+
value: function aliasReplicaTableNames(table) {
|
|
715
|
+
var aliasTableName;
|
|
716
|
+
var numOfReplicas = this.joinTables.filter(function (tableName) {
|
|
717
|
+
return tableName === table;
|
|
718
|
+
}).length;
|
|
719
|
+
if (numOfReplicas > 0) {
|
|
720
|
+
aliasTableName = this.aliasReplicaTableNames(table + Math.floor(Math.random() * Math.floor(1000)));
|
|
721
|
+
return aliasTableName;
|
|
722
|
+
} else {
|
|
723
|
+
this.joinTables.push(table);
|
|
724
|
+
return table;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// ▀█░█▀ █▀▀█ █░░ ░▀░ █▀▀▄ █▀▀█ ▀▀█▀▀ ░▀░ █▀▀█ █▀▀▄
|
|
729
|
+
// ░█▄█░ █▄▄█ █░░ ▀█▀ █░░█ █▄▄█ ░░█░░ ▀█▀ █░░█ █░░█
|
|
730
|
+
// ░░▀░░ ▀░░▀ ▀▀▀ ▀▀▀ ▀▀▀░ ▀░░▀ ░░▀░░ ▀▀▀ ▀▀▀▀ ▀░░▀
|
|
731
|
+
}, {
|
|
732
|
+
key: "validIndex",
|
|
733
|
+
value: function validIndex(index) {
|
|
734
|
+
if (Number(index) === NaN) {
|
|
735
|
+
this.errors.push("The index given to the json selector is not a number, if you're trying to search add a ? to the start of your string");
|
|
736
|
+
this.fatalError = true;
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
}, {
|
|
742
|
+
key: "validBySchema",
|
|
743
|
+
value: function validBySchema(db, table, name) {
|
|
744
|
+
if (!this.schema) {
|
|
745
|
+
this.errors.push('A schema must be provided in order to use JsonQL');
|
|
746
|
+
this.fatalError = true;
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (!db || (db || '').length === 0) {
|
|
750
|
+
this.errors.push('No db name provided');
|
|
751
|
+
this.fatalError = true;
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
if (!this.schema[db]) {
|
|
755
|
+
this.errors.push(db + ' db not found in schema');
|
|
756
|
+
this.fatalError = true;
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
if (table && !(this.schema[db] || {})[table]) {
|
|
760
|
+
this.errors.push(db + '.' + table + ' not found in schema');
|
|
761
|
+
this.fatalError = true;
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
if (name && !((this.schema[db] || {})[table] || {})[name]) {
|
|
765
|
+
this.errors.push(db + '.' + table + '.' + name + ' not found in schema');
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
}, {
|
|
771
|
+
key: "validString",
|
|
772
|
+
value: function validString(string) {
|
|
773
|
+
var regex = /(drop )|;|(update )( truncate)/gi;
|
|
774
|
+
if (regex.test(string)) {
|
|
775
|
+
this.errors.push("The string '" + string + "' is not allowed");
|
|
776
|
+
this.fatalError = true;
|
|
777
|
+
return false;
|
|
778
|
+
} else {
|
|
779
|
+
return true;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// ░░▀ █▀▀█ █▀▀ ▀▀█▀▀ █▀▀█ ░▀░ █▀▀▄ █▀▀▀ █▀▀
|
|
784
|
+
// ░░█ █░░█ ▀▀█ ░░█░░ █▄▄▀ ▀█▀ █░░█ █░▀█ ▀▀█
|
|
785
|
+
// █▄█ ▀▀▀█ ▀▀▀ ░░▀░░ ▀░▀▀ ▀▀▀ ▀░░▀ ▀▀▀▀ ▀▀▀
|
|
786
|
+
}, {
|
|
787
|
+
key: "extractColFromJQString",
|
|
788
|
+
value: function extractColFromJQString(db, table, jQString) {
|
|
789
|
+
var column = jQString.slice(1, jQString.search(/[\.\[]/));
|
|
790
|
+
if (!this.validBySchema(db, table, column)) return;
|
|
791
|
+
return column;
|
|
792
|
+
}
|
|
793
|
+
}, {
|
|
794
|
+
key: "validJQString",
|
|
795
|
+
value: function validJQString(db, table, jQString) {
|
|
796
|
+
if (/^\$/.test(jQString)) {
|
|
797
|
+
// Add a match here and check any string inside that begins with a $, that way we can target more than one column in a jqstring.
|
|
798
|
+
var column = jQString.slice(1, jQString.search(/[\.\[]/));
|
|
799
|
+
if (!this.validBySchema(db, table, column)) return false;
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
}, {
|
|
805
|
+
key: "validPlainJQString",
|
|
806
|
+
value: function validPlainJQString(jQString) {
|
|
807
|
+
if (/^\$/.test(jQString)) {
|
|
808
|
+
// Add a match here and check any string inside that begins with a $, that way we can target more than one column in a jqstring.
|
|
809
|
+
var column = jQString.slice(1, jQString.search(/[\.\[]/));
|
|
810
|
+
if (!this.validString(column)) return false;
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
return false;
|
|
814
|
+
}
|
|
815
|
+
}, {
|
|
816
|
+
key: "jQString",
|
|
817
|
+
value: function jQString(name, string, prevString) {
|
|
818
|
+
var nameReg = /\$\w+/;
|
|
819
|
+
var index = /\[\d\]/;
|
|
820
|
+
var target = /\.\w+/;
|
|
821
|
+
var search = /\[\?[\w\s@#:;{},.!"£$%^&*()/?|`¬\-=+~]*\]/;
|
|
822
|
+
if (nameReg.test(string)) {
|
|
823
|
+
return "CONCAT(\"$\")";
|
|
824
|
+
}
|
|
825
|
+
if (index.test(string)) {
|
|
826
|
+
// 'index';
|
|
827
|
+
if (!this.validString(string)) return;
|
|
828
|
+
return "CONCAT(".concat(prevString, ", \"").concat(string, "\")");
|
|
829
|
+
}
|
|
830
|
+
if (target.test(string)) {
|
|
831
|
+
// 'target';
|
|
832
|
+
if (!this.validString(string)) return;
|
|
833
|
+
return "CONCAT(".concat(prevString, ", \"").concat(string, "\")");
|
|
834
|
+
}
|
|
835
|
+
if (search.test(string)) {
|
|
836
|
+
// 'search';
|
|
837
|
+
string = string.slice(2, -1);
|
|
838
|
+
if (!this.validString(string)) return;
|
|
839
|
+
return "CONCAT(".concat(prevString, ", CONCAT('[',SUBSTR(JSON_SEARCH(JSON_EXTRACT(").concat(name, ", \"$\"),'one','").concat(string, "'), 4,LOCATE(']',JSON_SEARCH(JSON_EXTRACT(").concat(name, ", \"$\"), 'one', '").concat(string, "'))-4),']'))");
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}, {
|
|
843
|
+
key: "jQStringMaker",
|
|
844
|
+
value: function jQStringMaker(name, matches) {
|
|
845
|
+
var _this16 = this;
|
|
846
|
+
var result = matches.reduce(function (arr, match, i) {
|
|
847
|
+
return [].concat(_toConsumableArray(arr), [_this16.jQString(name, match, arr[i - 1])]);
|
|
848
|
+
}, []);
|
|
849
|
+
return result[result.length - 1];
|
|
850
|
+
}
|
|
851
|
+
}, {
|
|
852
|
+
key: "plainjQExtract",
|
|
853
|
+
value: function plainjQExtract(jQStr) {
|
|
854
|
+
var regx = /(\$\w+)|(\[\d\])|(\.\w+)|(\[\?[\w\s@#:;{},.!"£$%^&*()/?|`¬\-=+~]*\])/g;
|
|
855
|
+
var matches = jQStr.match(regx);
|
|
856
|
+
var name = "".concat(matches[0].slice(1));
|
|
857
|
+
return "JSON_UNQUOTE(JSON_EXTRACT(".concat(name, ", ").concat(this.jQStringMaker(name, matches), "))");
|
|
858
|
+
}
|
|
859
|
+
}, {
|
|
860
|
+
key: "jQExtract",
|
|
861
|
+
value: function jQExtract(db, table, jQStr) {
|
|
862
|
+
var regx = /(\$\w+)|(\[\d\])|(\.\w+)|(\[\?[\w\s@#:;{},.!"£$%^&*()/?|`¬\-=+~]*\])/g;
|
|
863
|
+
var matches = jQStr.match(regx);
|
|
864
|
+
var name = "".concat(db, ".").concat(table, ".").concat(matches[0].slice(1));
|
|
865
|
+
return "JSON_UNQUOTE(JSON_EXTRACT(".concat(name, ", ").concat(this.jQStringMaker(name, matches), "))");
|
|
866
|
+
}
|
|
867
|
+
}, {
|
|
868
|
+
key: "jQSet",
|
|
869
|
+
value: function jQSet(db, table, jQStr, value) {
|
|
870
|
+
if (typeof value === 'string') {
|
|
871
|
+
value = "'".concat(value, "'");
|
|
872
|
+
}
|
|
873
|
+
var regx = /(\$\w+)|(\[\d\])|(\.\w+)|(\[\?[\w\s@#:;{},.!"£$%^&*()/?|`¬\-=+~]*\])/g;
|
|
874
|
+
var matches = jQStr.match(regx);
|
|
875
|
+
var name = "".concat(db, ".").concat(table, ".").concat(matches[0].slice(1));
|
|
876
|
+
return "JSON_SET(".concat(name, ", ").concat(this.jQStringMaker(name, matches), ", ").concat(value, ")");
|
|
877
|
+
}
|
|
878
|
+
}]);
|
|
879
|
+
return JsonQL;
|
|
880
|
+
}();
|
|
881
|
+
export default JsonQL;
|