@gingkoo/pandora-metabase 1.0.118 → 1.0.119
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/lib/cjs/common/Portal/index.js +0 -2
- package/lib/cjs/common/SplitView/index.d.ts +0 -4
- package/lib/cjs/common/SplitView/index.js +0 -10
- package/lib/cjs/components/dialog/custom-column/config.js +4 -48
- package/lib/cjs/components/dialog/custom-column/expression-editor.js +3 -14
- package/lib/cjs/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
- package/lib/cjs/components/dialog/custom-column/expressions/suggest.js +2 -43
- package/lib/cjs/components/dialog/custom-column/expressions/tokenizer.js +8 -65
- package/lib/cjs/components/dialog/custom-column/index.js +2 -4
- package/lib/cjs/components/dialog/custom-column/tokenized-expression.js +2 -3
- package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -1
- package/lib/cjs/components/dialog/custom-editor/index.js +2 -7
- package/lib/cjs/components/dialog/diff-viewer/index copy.js +1 -16
- package/lib/cjs/components/dialog/expression/date-format-picker.js +2 -20
- package/lib/cjs/components/dialog/expression/date-format.js +2 -8
- package/lib/cjs/components/dialog/expression/index.d.ts +0 -3
- package/lib/cjs/components/dialog/expression/index.js +2 -83
- package/lib/cjs/components/dialog/formula/index.js +1 -30
- package/lib/cjs/components/dialog/formula/utils.js +2 -10
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
- package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +109 -0
- package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +9 -0
- package/lib/cjs/components/dialog/formula-list/LogicGroup.js +43 -0
- package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -0
- package/lib/cjs/components/dialog/formula-list/index.js +967 -503
- package/lib/cjs/components/dialog/formula-list/index.less +724 -0
- package/lib/cjs/components/dialog/formula-list/utils.d.ts +0 -7
- package/lib/cjs/components/dialog/formula-list/utils.js +117 -113
- package/lib/cjs/components/dialog/select-column/index.d.ts +0 -6
- package/lib/cjs/components/dialog/select-column/index.js +4 -15
- package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-column-multiple/index.js +6 -45
- package/lib/cjs/components/dialog/select-join/index.d.ts +0 -5
- package/lib/cjs/components/dialog/select-join/index.js +0 -6
- package/lib/cjs/components/dialog/select-join-column/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-join-column/index.js +7 -21
- package/lib/cjs/components/dialog/select-join-column-multiple/index.d.ts +0 -8
- package/lib/cjs/components/dialog/select-join-column-multiple/index.js +5 -35
- package/lib/cjs/components/dialog/select-permission-table/index.d.ts +0 -5
- package/lib/cjs/components/dialog/select-permission-table/index.js +0 -6
- package/lib/cjs/components/dialog/select-summarize/index.d.ts +3 -3
- package/lib/cjs/components/dialog/select-summarize/index.js +105 -18
- package/lib/cjs/components/dialog/select-summarize/index.less +23 -0
- package/lib/cjs/components/dialog/select-table/index.d.ts +0 -6
- package/lib/cjs/components/dialog/select-table/index.js +1 -9
- package/lib/cjs/components/metabase/index.js +72 -86
- package/lib/cjs/components/metabase/index.less +7 -7
- package/lib/cjs/components/modules/components/Wrapper.js +1 -1
- package/lib/cjs/components/modules/components/header.js +2 -2
- package/lib/cjs/components/modules/components/meta-icon.d.ts +0 -3
- package/lib/cjs/components/modules/components/meta-icon.js +2 -47
- package/lib/cjs/components/modules/custom-column.js +3 -29
- package/lib/cjs/components/modules/enum/filter-enum.js +9 -88
- package/lib/cjs/components/modules/filter.js +2 -20
- package/lib/cjs/components/modules/index.d.ts +4 -2
- package/lib/cjs/components/modules/index.js +24 -1
- package/lib/cjs/components/modules/join-data.js +13 -291
- package/lib/cjs/components/modules/row-limit.js +0 -1
- package/lib/cjs/components/modules/sort.js +1 -61
- package/lib/cjs/components/modules/summarize/group-by.d.ts +0 -5
- package/lib/cjs/components/modules/summarize/group-by.js +231 -76
- package/lib/cjs/components/modules/summarize/select-index.js +96 -46
- package/lib/cjs/components/modules/table-data.js +11 -64
- package/lib/cjs/components/popup.js +26 -32
- package/lib/cjs/hooks/patch.d.ts +1 -0
- package/lib/cjs/hooks/patch.js +104 -6
- package/lib/cjs/hooks/patch2.js +3 -165
- package/lib/cjs/hooks/use-provider.js +0 -3
- package/lib/cjs/hooks/use-state.js +55 -135
- package/lib/cjs/index.js +0 -15
- package/lib/cjs/locale/en.js +5 -0
- package/lib/cjs/locale/index.js +1 -4
- package/lib/cjs/locale/zh.js +5 -0
- package/lib/cjs/sql-formula.js +0 -1
- package/lib/cjs/store/enum.d.ts +6 -6
- package/lib/cjs/store/enum.js +0 -13
- package/lib/cjs/store/helper.d.ts +2 -1
- package/lib/cjs/store/helper.js +15 -225
- package/lib/cjs/store/types.d.ts +45 -67
- package/lib/cjs/store/types.js +3 -49
- package/lib/cjs/types.d.ts +1 -0
- package/lib/cjs/utils/cookies.js +0 -3
- package/lib/cjs/utils/event.js +1 -1
- package/lib/cjs/utils/helper-dom.d.ts +1 -0
- package/lib/cjs/utils/helper-dom.js +17 -10
- package/lib/cjs/utils/helper.js +1 -24
- package/lib/cjs/utils/keydown.js +4 -7
- package/lib/cjs/utils/platform.d.ts +0 -9
- package/lib/cjs/utils/platform.js +0 -10
- package/lib/cjs/utils/selection.js +0 -6
- package/lib/cjs/utils/storage.d.ts +0 -9
- package/lib/cjs/utils/storage.js +1 -11
- package/lib/cjs/utils/transformSql.d.ts +5 -0
- package/lib/cjs/utils/transformSql.js +42 -113
- package/lib/cjs/utils.d.ts +1 -6
- package/lib/cjs/utils.js +115 -255
- package/lib/es/common/Portal/index.js +0 -2
- package/lib/es/common/SplitView/index.d.ts +0 -4
- package/lib/es/common/SplitView/index.js +0 -10
- package/lib/es/components/dialog/custom-column/config.js +4 -48
- package/lib/es/components/dialog/custom-column/expression-editor.js +3 -14
- package/lib/es/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
- package/lib/es/components/dialog/custom-column/expressions/suggest.js +2 -43
- package/lib/es/components/dialog/custom-column/expressions/tokenizer.js +8 -65
- package/lib/es/components/dialog/custom-column/index.js +2 -4
- package/lib/es/components/dialog/custom-column/tokenized-expression.js +1 -3
- package/lib/es/components/dialog/custom-column/tokenizedI-input.js +1 -1
- package/lib/es/components/dialog/custom-editor/index.js +1 -7
- package/lib/es/components/dialog/diff-viewer/index copy.js +1 -15
- package/lib/es/components/dialog/expression/date-format-picker.js +2 -20
- package/lib/es/components/dialog/expression/date-format.js +2 -8
- package/lib/es/components/dialog/expression/index.d.ts +0 -3
- package/lib/es/components/dialog/expression/index.js +2 -82
- package/lib/es/components/dialog/formula/index.js +0 -30
- package/lib/es/components/dialog/formula/utils.js +2 -10
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
- package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +102 -0
- package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +9 -0
- package/lib/es/components/dialog/formula-list/LogicGroup.js +36 -0
- package/lib/es/components/dialog/formula-list/index.d.ts +3 -0
- package/lib/es/components/dialog/formula-list/index.js +966 -503
- package/lib/es/components/dialog/formula-list/index.less +724 -0
- package/lib/es/components/dialog/formula-list/utils.d.ts +0 -7
- package/lib/es/components/dialog/formula-list/utils.js +117 -113
- package/lib/es/components/dialog/index.js +3 -3
- package/lib/es/components/dialog/select-column/index.d.ts +0 -6
- package/lib/es/components/dialog/select-column/index.js +4 -14
- package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -8
- package/lib/es/components/dialog/select-column-multiple/index.js +7 -47
- package/lib/es/components/dialog/select-join/index.d.ts +0 -5
- package/lib/es/components/dialog/select-join/index.js +0 -5
- package/lib/es/components/dialog/select-join-column/index.d.ts +0 -8
- package/lib/es/components/dialog/select-join-column/index.js +7 -20
- package/lib/es/components/dialog/select-join-column-multiple/index.d.ts +0 -8
- package/lib/es/components/dialog/select-join-column-multiple/index.js +5 -34
- package/lib/es/components/dialog/select-permission-table/index.d.ts +0 -5
- package/lib/es/components/dialog/select-permission-table/index.js +0 -5
- package/lib/es/components/dialog/select-summarize/index.d.ts +3 -3
- package/lib/es/components/dialog/select-summarize/index.js +106 -18
- package/lib/es/components/dialog/select-summarize/index.less +23 -0
- package/lib/es/components/dialog/select-table/index.d.ts +0 -6
- package/lib/es/components/dialog/select-table/index.js +1 -8
- package/lib/es/components/metabase/index.js +72 -87
- package/lib/es/components/metabase/index.less +7 -7
- package/lib/es/components/modules/components/Wrapper.js +1 -1
- package/lib/es/components/modules/components/header.js +2 -2
- package/lib/es/components/modules/components/meta-icon.d.ts +0 -3
- package/lib/es/components/modules/components/meta-icon.js +2 -46
- package/lib/es/components/modules/custom-column.js +3 -29
- package/lib/es/components/modules/enum/filter-enum.js +9 -88
- package/lib/es/components/modules/filter.js +2 -19
- package/lib/es/components/modules/index.d.ts +4 -2
- package/lib/es/components/modules/index.js +24 -1
- package/lib/es/components/modules/join-data.js +13 -291
- package/lib/es/components/modules/row-limit.js +0 -1
- package/lib/es/components/modules/sort.js +1 -61
- package/lib/es/components/modules/summarize/group-by.d.ts +0 -5
- package/lib/es/components/modules/summarize/group-by.js +233 -78
- package/lib/es/components/modules/summarize/select-index.js +96 -46
- package/lib/es/components/modules/table-data.js +11 -64
- package/lib/es/components/popup.js +27 -33
- package/lib/es/hooks/patch.d.ts +1 -0
- package/lib/es/hooks/patch.js +103 -5
- package/lib/es/hooks/patch2.js +2 -164
- package/lib/es/hooks/use-provider.js +0 -3
- package/lib/es/hooks/use-state.js +55 -135
- package/lib/es/index.js +0 -14
- package/lib/es/locale/en.js +5 -0
- package/lib/es/locale/index.js +1 -4
- package/lib/es/locale/zh.js +5 -0
- package/lib/es/sql-formula.js +0 -1
- package/lib/es/store/enum.d.ts +6 -6
- package/lib/es/store/enum.js +0 -13
- package/lib/es/store/helper.d.ts +2 -1
- package/lib/es/store/helper.js +13 -224
- package/lib/es/store/types.d.ts +45 -67
- package/lib/es/store/types.js +3 -49
- package/lib/es/types.d.ts +1 -0
- package/lib/es/types.js +1 -18
- package/lib/es/utils/cookies.js +0 -3
- package/lib/es/utils/event.js +1 -1
- package/lib/es/utils/helper-dom.d.ts +1 -0
- package/lib/es/utils/helper-dom.js +16 -9
- package/lib/es/utils/helper.js +1 -24
- package/lib/es/utils/keydown.js +4 -7
- package/lib/es/utils/platform.d.ts +0 -9
- package/lib/es/utils/platform.js +0 -10
- package/lib/es/utils/selection.js +0 -6
- package/lib/es/utils/storage.d.ts +0 -9
- package/lib/es/utils/storage.js +1 -10
- package/lib/es/utils/transformSql.d.ts +5 -0
- package/lib/es/utils/transformSql.js +42 -112
- package/lib/es/utils.d.ts +1 -6
- package/lib/es/utils.js +116 -255
- package/package.json +1 -1
|
@@ -4,12 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.transformSql = void 0;
|
|
7
|
+
exports.transformSql = exports.handleBaseType2Sql = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
|
|
9
9
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
10
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
|
|
11
11
|
var _excluded = ["children"];
|
|
12
|
-
// @ts-nocheck
|
|
13
12
|
var procEnum = {
|
|
14
13
|
mysql: 'mysql',
|
|
15
14
|
oracle: 'oracle',
|
|
@@ -26,28 +25,17 @@ var MetabaseTypeEnum = {
|
|
|
26
25
|
union: 'union',
|
|
27
26
|
permissionTable: 'permissionTable'
|
|
28
27
|
};
|
|
29
|
-
// 数据基础类型
|
|
30
28
|
var BlockTypeEnum = {
|
|
31
29
|
joinDefault: 'joinDefault',
|
|
32
|
-
// 简单的表达式
|
|
33
30
|
expression: 'expression',
|
|
34
|
-
// 表达式
|
|
35
31
|
operator: 'operator',
|
|
36
|
-
// 操作符
|
|
37
32
|
field: 'field',
|
|
38
|
-
// 字段
|
|
39
33
|
inputNumber: 'inputNumber',
|
|
40
|
-
// 数字输入框
|
|
41
34
|
inputString: 'inputString',
|
|
42
|
-
// 字符串输入框
|
|
43
35
|
constant: 'constant',
|
|
44
|
-
// 常量
|
|
45
36
|
inputStringList: 'inputStringList',
|
|
46
|
-
// 多个字符串输入框
|
|
47
37
|
inputNumberList: 'inputNumberList',
|
|
48
|
-
// 多个数字输入框
|
|
49
38
|
unknown: 'unknown',
|
|
50
|
-
// 未知
|
|
51
39
|
notExists: 'notExists',
|
|
52
40
|
exists: 'exists',
|
|
53
41
|
FORMULA: 'FORMULA',
|
|
@@ -84,11 +72,11 @@ var _recursionArr2 = function _recursionArr(arr) {
|
|
|
84
72
|
}
|
|
85
73
|
return obj;
|
|
86
74
|
};
|
|
87
|
-
var
|
|
75
|
+
var _handleBaseType2Sql7 = exports.handleBaseType2Sql = function handleBaseType2Sql(list) {
|
|
88
76
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
89
77
|
var sql = '';
|
|
90
78
|
var constants = [];
|
|
91
|
-
var sql_items = [];
|
|
79
|
+
var sql_items = [];
|
|
92
80
|
if (!Array.isArray(list)) {
|
|
93
81
|
return {
|
|
94
82
|
sql: sql,
|
|
@@ -130,19 +118,15 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
130
118
|
constants.push(item.val);
|
|
131
119
|
}
|
|
132
120
|
if (type === BlockTypeEnum.inputStringList) {
|
|
133
|
-
// 这个如果存在 list 数组中,那么 list 数组种 只能有他,因为他太特殊了,现在就表达式在用
|
|
134
121
|
if (Array.isArray(item.val) && item.val.length) {
|
|
135
122
|
item.val.forEach(function (v) {
|
|
136
|
-
// 这里虽然是字符串 但是不加 ''了 因为他太特殊了 不通用
|
|
137
123
|
sql_items.push("".concat(v));
|
|
138
124
|
});
|
|
139
125
|
}
|
|
140
126
|
}
|
|
141
127
|
if (type === BlockTypeEnum.inputNumberList) {
|
|
142
|
-
// 这个如果存在 list 数组中,那么 list 数组种 只能有他,因为他太特殊了,现在就表达式在用
|
|
143
128
|
if (Array.isArray(item.val) && item.val.length) {
|
|
144
129
|
item.val.forEach(function (v) {
|
|
145
|
-
// 这里虽然是字符串 但是不加 ''了 因为他太特殊了 不通用
|
|
146
130
|
sql_items.push("".concat(v));
|
|
147
131
|
});
|
|
148
132
|
}
|
|
@@ -150,21 +134,19 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
150
134
|
if (type === BlockTypeEnum.joinDefault) {
|
|
151
135
|
var lhs = item.lhs,
|
|
152
136
|
rhs = item.rhs;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
joinDefaultRightConstants = _handleBaseType2Sql3.constants;
|
|
137
|
+
var _handleBaseType2Sql = _handleBaseType2Sql7(lhs, db),
|
|
138
|
+
leftSql = _handleBaseType2Sql.sql,
|
|
139
|
+
leftSqlItems = _handleBaseType2Sql.sql_items,
|
|
140
|
+
joinDefaultLeftConstants = _handleBaseType2Sql.constants;
|
|
141
|
+
var _handleBaseType2Sql2 = _handleBaseType2Sql7(rhs, db),
|
|
142
|
+
rightSql = _handleBaseType2Sql2.sql,
|
|
143
|
+
rightSqlItems = _handleBaseType2Sql2.sql_items,
|
|
144
|
+
joinDefaultRightConstants = _handleBaseType2Sql2.constants;
|
|
162
145
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(joinDefaultLeftConstants));
|
|
163
146
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(joinDefaultRightConstants));
|
|
164
147
|
var left_condition = leftSql;
|
|
165
148
|
var right_condition = rightSql;
|
|
166
149
|
if (leftSqlItems.length > 1) {
|
|
167
|
-
// 多个肯定是字段
|
|
168
150
|
if (db === procEnum.mysql) {
|
|
169
151
|
left_condition = "CONCAT(".concat(leftSqlItems.join(','), ")");
|
|
170
152
|
}
|
|
@@ -176,7 +158,6 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
176
158
|
}
|
|
177
159
|
}
|
|
178
160
|
if (rightSqlItems.length > 1) {
|
|
179
|
-
// 多个肯定是字段
|
|
180
161
|
if (db === procEnum.mysql) {
|
|
181
162
|
right_condition = "CONCAT(".concat(rightSqlItems.join(','), ")");
|
|
182
163
|
}
|
|
@@ -195,20 +176,19 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
195
176
|
condition = item.condition,
|
|
196
177
|
database_type = item.database_type,
|
|
197
178
|
formula = item.formula;
|
|
198
|
-
var
|
|
199
|
-
_leftSql =
|
|
200
|
-
_leftSqlItems =
|
|
201
|
-
_joinDefaultLeftConstants =
|
|
202
|
-
var
|
|
203
|
-
_rightSql =
|
|
204
|
-
_rightSqlItems =
|
|
205
|
-
_joinDefaultRightConstants =
|
|
179
|
+
var _handleBaseType2Sql3 = _handleBaseType2Sql7(_lhs, db),
|
|
180
|
+
_leftSql = _handleBaseType2Sql3.sql,
|
|
181
|
+
_leftSqlItems = _handleBaseType2Sql3.sql_items,
|
|
182
|
+
_joinDefaultLeftConstants = _handleBaseType2Sql3.constants;
|
|
183
|
+
var _handleBaseType2Sql4 = _handleBaseType2Sql7(_rhs, db),
|
|
184
|
+
_rightSql = _handleBaseType2Sql4.sql,
|
|
185
|
+
_rightSqlItems = _handleBaseType2Sql4.sql_items,
|
|
186
|
+
_joinDefaultRightConstants = _handleBaseType2Sql4.constants;
|
|
206
187
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(_joinDefaultLeftConstants));
|
|
207
188
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(_joinDefaultRightConstants));
|
|
208
189
|
var _left_condition = _leftSql;
|
|
209
190
|
var _right_condition = '';
|
|
210
191
|
if (_leftSqlItems.length > 1) {
|
|
211
|
-
// 多个肯定是字段
|
|
212
192
|
if (db === procEnum.mysql) {
|
|
213
193
|
_left_condition = "CONCAT(".concat(_leftSqlItems.join(','), ")");
|
|
214
194
|
}
|
|
@@ -220,14 +200,12 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
220
200
|
}
|
|
221
201
|
}
|
|
222
202
|
if (formula && formula.type && formula.params) {
|
|
223
|
-
// 目前只有一个 SUBSTR, 也不想再加函数了,函数不在这里加
|
|
224
203
|
var formulaType = formula.type;
|
|
225
204
|
if (db === procEnum.sqlserver && formulaType === 'SUBSTR') {
|
|
226
205
|
formulaType = 'SUBSTRING';
|
|
227
206
|
}
|
|
228
207
|
_left_condition = "".concat(formulaType, "(").concat(formula.params.map(function (it, i) {
|
|
229
208
|
if (!i) {
|
|
230
|
-
// 字段
|
|
231
209
|
return _left_condition;
|
|
232
210
|
} else {
|
|
233
211
|
return it;
|
|
@@ -248,7 +226,6 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
248
226
|
if (group === SQL_GROUP_TYPE.STRING) {
|
|
249
227
|
var condition_1 = (_rightSqlItems === null || _rightSqlItems === void 0 ? void 0 : _rightSqlItems[0]) || '';
|
|
250
228
|
switch (condition) {
|
|
251
|
-
// string
|
|
252
229
|
case '等于':
|
|
253
230
|
_right_condition = "= ".concat(_rightSql);
|
|
254
231
|
break;
|
|
@@ -256,7 +233,6 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
256
233
|
_right_condition = "!= ".concat(_rightSql);
|
|
257
234
|
break;
|
|
258
235
|
case '包含':
|
|
259
|
-
// 去掉引号
|
|
260
236
|
_right_condition = "LIKE '%".concat(condition_1, "%'");
|
|
261
237
|
break;
|
|
262
238
|
case '不包含':
|
|
@@ -284,7 +260,6 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
284
260
|
condition_1 = (_condition_ = condition_1) === null || _condition_ === void 0 || (_condition_ = _condition_.split(',')) === null || _condition_ === void 0 || (_condition_ = _condition_.map(function (v) {
|
|
285
261
|
var _v;
|
|
286
262
|
v = (_v = v) === null || _v === void 0 ? void 0 : _v.trim();
|
|
287
|
-
// 如果已经加了引号
|
|
288
263
|
if (v && (/^'.*'$/.test(v) || /^".*"$/.test(v))) {
|
|
289
264
|
return "".concat(v);
|
|
290
265
|
} else {
|
|
@@ -324,7 +299,6 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
324
299
|
var _condition_3 = (_rightSqlItems === null || _rightSqlItems === void 0 ? void 0 : _rightSqlItems[0]) || '';
|
|
325
300
|
var condition_2 = (_rightSqlItems === null || _rightSqlItems === void 0 ? void 0 : _rightSqlItems[1]) || '';
|
|
326
301
|
switch (condition) {
|
|
327
|
-
// number
|
|
328
302
|
case '等于':
|
|
329
303
|
_right_condition = "= ".concat(_condition_3);
|
|
330
304
|
break;
|
|
@@ -435,15 +409,12 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
435
409
|
var _condition_4 = (_rightSqlItems === null || _rightSqlItems === void 0 ? void 0 : _rightSqlItems[0]) || '';
|
|
436
410
|
var _condition_5 = (_rightSqlItems === null || _rightSqlItems === void 0 ? void 0 : _rightSqlItems[1]) || '';
|
|
437
411
|
if (/^[\d- :]+$/.test(_condition_4)) {
|
|
438
|
-
// 日期
|
|
439
412
|
_condition_4 = "'".concat(transformDate(_condition_4), "'");
|
|
440
413
|
}
|
|
441
414
|
if (/^[\d- :]+$/.test(_condition_5)) {
|
|
442
|
-
// 日期
|
|
443
415
|
_condition_5 = "'".concat(transformDate(_condition_5), "'");
|
|
444
416
|
}
|
|
445
417
|
switch (condition) {
|
|
446
|
-
// date
|
|
447
418
|
case '等于':
|
|
448
419
|
_right_condition = "= ".concat(_condition_4);
|
|
449
420
|
break;
|
|
@@ -479,16 +450,16 @@ var _handleBaseType2Sql8 = function _handleBaseType2Sql(list) {
|
|
|
479
450
|
}
|
|
480
451
|
}
|
|
481
452
|
if (type === BlockTypeEnum.FORMULA) {
|
|
482
|
-
var
|
|
483
|
-
argSql =
|
|
484
|
-
formulaConstants =
|
|
453
|
+
var _handleBaseType2Sql5 = _handleBaseType2Sql7(item.args, db),
|
|
454
|
+
argSql = _handleBaseType2Sql5.sql,
|
|
455
|
+
formulaConstants = _handleBaseType2Sql5.constants;
|
|
485
456
|
sql += " ".concat(item.name, "(").concat(argSql, ")");
|
|
486
457
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(formulaConstants));
|
|
487
458
|
}
|
|
488
459
|
if (type === BlockTypeEnum.collection) {
|
|
489
|
-
var
|
|
490
|
-
collectionSql =
|
|
491
|
-
collectionConstants =
|
|
460
|
+
var _handleBaseType2Sql6 = _handleBaseType2Sql7(item.list, db),
|
|
461
|
+
collectionSql = _handleBaseType2Sql6.sql,
|
|
462
|
+
collectionConstants = _handleBaseType2Sql6.constants;
|
|
492
463
|
sql += " ".concat(collectionSql);
|
|
493
464
|
constants.push.apply(constants, (0, _toConsumableArray2["default"])(collectionConstants));
|
|
494
465
|
}
|
|
@@ -512,9 +483,9 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
512
483
|
if (isSubquery) {
|
|
513
484
|
subQuery = subquery;
|
|
514
485
|
}
|
|
515
|
-
var
|
|
516
|
-
sql =
|
|
517
|
-
joinConstants =
|
|
486
|
+
var _handleBaseType2Sql8 = _handleBaseType2Sql7(expressions, db),
|
|
487
|
+
sql = _handleBaseType2Sql8.sql,
|
|
488
|
+
joinConstants = _handleBaseType2Sql8.constants;
|
|
518
489
|
var joinCondition = "on ".concat(sql);
|
|
519
490
|
constants = joinConstants;
|
|
520
491
|
return {
|
|
@@ -534,7 +505,6 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
534
505
|
return {
|
|
535
506
|
field_sql: "".concat(tableAlias ? "".concat(tableAlias, ".").concat(o.name) : o.name, " as ").concat(fieldAlias),
|
|
536
507
|
read_name: o.name,
|
|
537
|
-
// 原字段名
|
|
538
508
|
name: fieldAlias,
|
|
539
509
|
name_zh: o.name_zh,
|
|
540
510
|
id: o.id
|
|
@@ -547,7 +517,6 @@ var _handleJoinData = function _handleJoinData(joinData) {
|
|
|
547
517
|
constants: constants
|
|
548
518
|
};
|
|
549
519
|
};
|
|
550
|
-
// 处理数据格式 - (这里才是真正处理成后端需要的格式 前面两步都是准备工作)
|
|
551
520
|
var _handleNesting = function handleNesting(data) {
|
|
552
521
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
553
522
|
var hasInnerSql = Boolean(data.children);
|
|
@@ -569,7 +538,6 @@ var _handleNesting = function handleNesting(data) {
|
|
|
569
538
|
obj.datasourceId = tableData.table.datasourceId;
|
|
570
539
|
obj.datasourceName = tableData.table.datasourceName;
|
|
571
540
|
if (tableData.isSubquery && Array.isArray(tableData.subquery)) {
|
|
572
|
-
// 主表是子查询
|
|
573
541
|
obj.tableSubQuery = tableData.subquery;
|
|
574
542
|
}
|
|
575
543
|
if (!summarize || !summarize.group.length && !summarize.by.length) {
|
|
@@ -581,14 +549,10 @@ var _handleNesting = function handleNesting(data) {
|
|
|
581
549
|
var fieldAlias = v.fieldAlias || v.name;
|
|
582
550
|
return {
|
|
583
551
|
field_sql: "".concat(tableAlias ? "".concat(tableAlias, ".").concat(v.name) : v.name, " as ").concat(fieldAlias),
|
|
584
|
-
// 生成 sql 放 select 后面的
|
|
585
552
|
read_name: v.name,
|
|
586
|
-
// 原字段名
|
|
587
553
|
name: fieldAlias,
|
|
588
|
-
// 输出字段名
|
|
589
554
|
name_zh: v.name_zh,
|
|
590
|
-
|
|
591
|
-
id: v.id // 字段原 DATA_ID
|
|
555
|
+
id: v.id
|
|
592
556
|
};
|
|
593
557
|
});
|
|
594
558
|
}
|
|
@@ -604,9 +568,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
604
568
|
var customColumnsConstants = [];
|
|
605
569
|
var handleCustomColumn = function handleCustomColumn(data) {
|
|
606
570
|
return data.map(function (it) {
|
|
607
|
-
var
|
|
608
|
-
field_sql =
|
|
609
|
-
constants =
|
|
571
|
+
var _handleBaseType2Sql9 = _handleBaseType2Sql7(it.formulaList, db),
|
|
572
|
+
field_sql = _handleBaseType2Sql9.sql,
|
|
573
|
+
constants = _handleBaseType2Sql9.constants;
|
|
610
574
|
customColumnsConstants.push.apply(customColumnsConstants, (0, _toConsumableArray2["default"])(constants));
|
|
611
575
|
return {
|
|
612
576
|
field_sql: "".concat(field_sql, " as ").concat(it.name),
|
|
@@ -621,9 +585,9 @@ var _handleNesting = function handleNesting(data) {
|
|
|
621
585
|
obj.customColumnsConstants = customColumnsConstants;
|
|
622
586
|
}
|
|
623
587
|
if (filterData && filterData.filter.length) {
|
|
624
|
-
var
|
|
625
|
-
sql =
|
|
626
|
-
constants =
|
|
588
|
+
var _handleBaseType2Sql0 = _handleBaseType2Sql7(filterData.filter, db),
|
|
589
|
+
sql = _handleBaseType2Sql0.sql,
|
|
590
|
+
constants = _handleBaseType2Sql0.constants;
|
|
627
591
|
obj.filters = 'WHERE ' + sql;
|
|
628
592
|
obj.filtersConstants = constants;
|
|
629
593
|
}
|
|
@@ -638,10 +602,8 @@ var _handleNesting = function handleNesting(data) {
|
|
|
638
602
|
queryColumns.push({
|
|
639
603
|
field_sql: "".concat(v.sql, " as ").concat(v.fieldAlias),
|
|
640
604
|
read_name: '',
|
|
641
|
-
// 原字段名
|
|
642
605
|
name: v.fieldAlias,
|
|
643
606
|
name_zh: v.fieldAlias,
|
|
644
|
-
// v.quotes,
|
|
645
607
|
id: ''
|
|
646
608
|
});
|
|
647
609
|
return v.sql;
|
|
@@ -649,16 +611,16 @@ var _handleNesting = function handleNesting(data) {
|
|
|
649
611
|
}
|
|
650
612
|
if (summarize.by.length) {
|
|
651
613
|
obj.groupBy.groupColumns = summarize.by.map(function (v) {
|
|
614
|
+
var _v$atoms;
|
|
615
|
+
var fieldSql = (_v$atoms = v.atoms) !== null && _v$atoms !== void 0 && _v$atoms.length ? _handleBaseType2Sql7(v.atoms, db).sql.trim() || v.sql : v.sql || "".concat(v.alias, ".").concat(v.realName || v.name);
|
|
652
616
|
queryColumns.push({
|
|
653
|
-
field_sql: "".concat(
|
|
617
|
+
field_sql: "".concat(fieldSql, " as ").concat(v.fieldAlias),
|
|
654
618
|
read_name: '',
|
|
655
|
-
// 原字段名
|
|
656
619
|
name: v.fieldAlias,
|
|
657
620
|
name_zh: v.fieldAlias,
|
|
658
|
-
// v.name_zh,
|
|
659
621
|
id: v.id
|
|
660
622
|
});
|
|
661
|
-
return
|
|
623
|
+
return fieldSql;
|
|
662
624
|
});
|
|
663
625
|
}
|
|
664
626
|
obj.queryColumns = queryColumns;
|
|
@@ -668,8 +630,8 @@ var _handleNesting = function handleNesting(data) {
|
|
|
668
630
|
}
|
|
669
631
|
if (sortData && sortData.sort.length) {
|
|
670
632
|
obj.orderInfos = "ORDER BY ".concat(sortData.sort.map(function (v) {
|
|
671
|
-
var
|
|
672
|
-
sql =
|
|
633
|
+
var _handleBaseType2Sql1 = _handleBaseType2Sql7(v.expression, db),
|
|
634
|
+
sql = _handleBaseType2Sql1.sql;
|
|
673
635
|
return "".concat(sql, " ").concat(v.sort);
|
|
674
636
|
}).join(', '));
|
|
675
637
|
}
|
|
@@ -678,18 +640,15 @@ var _handleNesting = function handleNesting(data) {
|
|
|
678
640
|
}
|
|
679
641
|
return obj;
|
|
680
642
|
};
|
|
681
|
-
// 反转顺序 - (将原本嵌套的顺序完全反转 最内层变成最外层)别问为什么 问就是接口需要
|
|
682
643
|
var reverseData = function reverseData(data) {
|
|
683
644
|
var arr = [];
|
|
684
645
|
_flatArr2(data, arr);
|
|
685
646
|
return _recursionArr2(arr.reverse());
|
|
686
647
|
};
|
|
687
|
-
// 分层 - (将原本平铺的格式转成 嵌套的格式)
|
|
688
648
|
var _layeredData = function layeredData(list) {
|
|
689
649
|
var res = {};
|
|
690
650
|
for (var i = 0; i < list.length; i++) {
|
|
691
651
|
var meta = list[i];
|
|
692
|
-
// @ts-ignore
|
|
693
652
|
if (meta.type === MetabaseTypeEnum.joinData) {
|
|
694
653
|
if (res[meta.type]) {
|
|
695
654
|
res[meta.type].push(meta);
|
|
@@ -697,15 +656,12 @@ var _layeredData = function layeredData(list) {
|
|
|
697
656
|
res[meta.type] = [meta];
|
|
698
657
|
}
|
|
699
658
|
} else {
|
|
700
|
-
// @ts-ignore
|
|
701
659
|
res[meta.type] = meta;
|
|
702
660
|
}
|
|
703
661
|
if (meta.type === MetabaseTypeEnum.summarize) {
|
|
704
662
|
var nextMeta = list[i + 1];
|
|
705
663
|
var nextNextMeta = list[i + 2];
|
|
706
664
|
var nextNextNextMeta = list[i + 3];
|
|
707
|
-
// 将sort 和 rowLimit 归到上一层 (虽然他们两在 summarize 后面)
|
|
708
|
-
// 处理完 sort 和 rowLimit 之后 如果数组后面还有元素则进入下一层循环
|
|
709
665
|
if (nextMeta) {
|
|
710
666
|
if (nextMeta.type === MetabaseTypeEnum.rowLimit) {
|
|
711
667
|
res[nextMeta.type] = nextMeta;
|
|
@@ -737,7 +693,6 @@ var handleSqlStruct = function handleSqlStruct(list) {
|
|
|
737
693
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
738
694
|
return _handleNesting(reverseData(_layeredData(list)), db);
|
|
739
695
|
};
|
|
740
|
-
// 处理 union
|
|
741
696
|
var handleSqlUnion = function handleSqlUnion(metas) {
|
|
742
697
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
743
698
|
var noFields = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -753,7 +708,6 @@ var handleSqlUnion = function handleSqlUnion(metas) {
|
|
|
753
708
|
fields = _sqlStruct2text.fields;
|
|
754
709
|
var union_fields = [fields];
|
|
755
710
|
if (unionMetas.length) {
|
|
756
|
-
// 用到了 union
|
|
757
711
|
unionMetas.forEach(function (it) {
|
|
758
712
|
if (Array.isArray(it.subquery) && it.subquery.length) {
|
|
759
713
|
var u_data = handleSqlStruct(it.subquery, db);
|
|
@@ -771,11 +725,6 @@ var handleSqlUnion = function handleSqlUnion(metas) {
|
|
|
771
725
|
union_fields: union_fields
|
|
772
726
|
};
|
|
773
727
|
};
|
|
774
|
-
/**
|
|
775
|
-
* 拼 sql
|
|
776
|
-
* @param {meta[]} data
|
|
777
|
-
* @param {boolean} indent 0 是第一次进来 非 0 是第N次进来
|
|
778
|
-
*/
|
|
779
728
|
var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
780
729
|
var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
781
730
|
var db = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : procEnum.mysql;
|
|
@@ -795,19 +744,14 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
795
744
|
groupBy = data.groupBy;
|
|
796
745
|
sql += "SELECT ";
|
|
797
746
|
var firstEntry = !indent;
|
|
798
|
-
// -------- 处理 fields --------
|
|
799
|
-
// 情况一、一层 带聚合 字段是 聚合字段
|
|
800
|
-
// 情况二、一层 不带聚合 字段是 主表和关联表的字段
|
|
801
|
-
// 情况三、二层 带聚合 第一层 聚合字段 + 关联表字段 第二层 聚合字段 第三层 聚合字段
|
|
802
747
|
if (noFields) {
|
|
803
748
|
sql += '1 ';
|
|
804
749
|
} else {
|
|
805
|
-
var flag = false;
|
|
750
|
+
var flag = false;
|
|
806
751
|
if (limit && db === procEnum.sqlserver) {
|
|
807
752
|
sql += "TOP(".concat(limit, ") ");
|
|
808
753
|
}
|
|
809
754
|
if (hasInnerSql) {
|
|
810
|
-
// 情况三 innerSqlStruct.queryColumns 是内层 聚合输出的字段,这种字段虽说是内层的,但是其实外层也需要
|
|
811
755
|
if (innerSqlStruct.queryColumns && innerSqlStruct.queryColumns.length) {
|
|
812
756
|
sql += innerSqlStruct.queryColumns.map(function (v) {
|
|
813
757
|
return "".concat(alias, ".").concat(v.name, " as ").concat(v.name);
|
|
@@ -816,9 +760,6 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
816
760
|
}
|
|
817
761
|
} else {
|
|
818
762
|
if (Array.isArray(queryColumns) && queryColumns.length) {
|
|
819
|
-
// 情况一 queryColumns 是聚合字段
|
|
820
|
-
// 情况二 queryColumns 是主表字段
|
|
821
|
-
// 情况三 queryColumns 是聚合字段
|
|
822
763
|
flag = true;
|
|
823
764
|
sql += queryColumns.map(function (v) {
|
|
824
765
|
return v.field_sql;
|
|
@@ -826,8 +767,6 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
826
767
|
}
|
|
827
768
|
}
|
|
828
769
|
if (firstEntry && joinTables && !groupBy) {
|
|
829
|
-
// 情况二 joinTables 是关联表字段
|
|
830
|
-
// 情况三 joinTables 是关联表字段
|
|
831
770
|
joinTables.forEach(function (it) {
|
|
832
771
|
if (Array.isArray(it.queryColumns) && it.queryColumns.length) {
|
|
833
772
|
if (flag) {
|
|
@@ -849,31 +788,26 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
849
788
|
}).join(', ') + ' ';
|
|
850
789
|
}
|
|
851
790
|
}
|
|
852
|
-
// -------- 处理 main table --------
|
|
853
791
|
sql += 'FROM ';
|
|
854
792
|
var as = db === procEnum.oracle ? '' : 'AS ';
|
|
855
793
|
if (hasInnerSql) {
|
|
856
794
|
sql += "(".concat(_sqlStruct2text3(innerSqlStruct, indent + 1, db).sql, ") ").concat(as).concat(alias, " ");
|
|
857
795
|
} else {
|
|
858
796
|
if (tableSubQuery) {
|
|
859
|
-
// 子查询
|
|
860
797
|
sql += "(".concat(handleSqlUnion(tableSubQuery, db).sql, ") ").concat(as).concat(alias, " ");
|
|
861
798
|
} else {
|
|
862
799
|
sql += "".concat(tableName, " ").concat(as).concat(alias, " ");
|
|
863
800
|
}
|
|
864
801
|
}
|
|
865
|
-
// -------- 处理 left join --------
|
|
866
802
|
if (joinTables) {
|
|
867
803
|
joinTables.forEach(function (it) {
|
|
868
804
|
if (it.subQuery) {
|
|
869
|
-
// 子查询
|
|
870
805
|
sql += "".concat(it.joinType, " (").concat(handleSqlUnion(it.subQuery, db).sql, ") ").concat(as).concat(it.alias, " ").concat(it.joinCondition, " ");
|
|
871
806
|
} else {
|
|
872
807
|
sql += "".concat(it.joinType, " ").concat(it.tableName, " ").concat(as).concat(it.alias, " ").concat(it.joinCondition, " ");
|
|
873
808
|
}
|
|
874
809
|
});
|
|
875
810
|
}
|
|
876
|
-
// -------- 处理 where --------
|
|
877
811
|
if (filters) {
|
|
878
812
|
sql += "".concat(filters, " ");
|
|
879
813
|
if (limit && db === procEnum.oracle) {
|
|
@@ -884,21 +818,17 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
884
818
|
}
|
|
885
819
|
}
|
|
886
820
|
}
|
|
887
|
-
// -------- 处理 group by --------
|
|
888
821
|
if (Array.isArray(groupBy === null || groupBy === void 0 ? void 0 : groupBy.groupColumns) && groupBy.groupColumns.length) {
|
|
889
822
|
sql += "GROUP BY ".concat(groupBy.groupColumns.map(function (it) {
|
|
890
823
|
return it;
|
|
891
824
|
}).join(', '), " ");
|
|
892
825
|
}
|
|
893
|
-
// -------- 处理 orderby --------
|
|
894
826
|
if (orderInfos) {
|
|
895
827
|
sql += "".concat(orderInfos, " ");
|
|
896
828
|
}
|
|
897
|
-
// -------- 处理 limit --------
|
|
898
829
|
if (limit && db === procEnum.mysql) {
|
|
899
830
|
sql += "LIMIT ".concat(limit, " ");
|
|
900
831
|
}
|
|
901
|
-
// -------- 获取 字段列表 --------
|
|
902
832
|
var fields = [];
|
|
903
833
|
if (firstEntry && !noFields) {
|
|
904
834
|
function addFields(data) {
|
|
@@ -947,7 +877,6 @@ var _sqlStruct2text3 = function sqlStruct2text(data) {
|
|
|
947
877
|
};
|
|
948
878
|
var transformSql = exports.transformSql = function transformSql(metas) {
|
|
949
879
|
var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
|
|
950
|
-
// let new_metas = upgradeLegacyData(metas);
|
|
951
880
|
var _handleSqlUnion = handleSqlUnion(metas, db, true),
|
|
952
881
|
sql = _handleSqlUnion.sql,
|
|
953
882
|
fields = _handleSqlUnion.fields,
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -26,17 +26,12 @@ export declare function isValidSQLAlias(str: string): boolean;
|
|
|
26
26
|
export declare const changeTableAlias: (list: MetaListType[] | [], curObj: Pick<MetaData_TableType, "tableUuid" | "alias">) => MetaListType[];
|
|
27
27
|
export declare const changeFieldAlias: (list: MetaListType[], curObj: Pick<MetaData_ColumnsType, "fieldUuid" | "fieldAlias">) => MetaListType[];
|
|
28
28
|
export declare function splitByUnion(data: any): any[];
|
|
29
|
+
export declare const normalizeLegacySummarizeForSave: (metas?: MetaListType[]) => MetaListType[];
|
|
29
30
|
export declare const getObjTem: (arr: any[]) => any;
|
|
30
31
|
export declare const patchData: (metas: MetaListType[], constantList?: any, formulaTemplates?: any) => MetaListType[];
|
|
31
32
|
export declare function reassembleByUnion(target?: any[]): any[];
|
|
32
33
|
export declare const buildSqlQuery: (data: MetaListType[] | undefined, type: string) => string;
|
|
33
34
|
export declare const isError: (item: AtomsItem | AtomsItem[], data: DataType[]) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* 在嵌套结构 root 中查找是否存在一个对象,使得 target 是该对象的子集
|
|
36
|
-
* @param root 可能包含任意层数组/对象的根数据
|
|
37
|
-
* @param target 目标对象(可能只包含部分字段)
|
|
38
|
-
* @returns 是否存在
|
|
39
|
-
*/
|
|
40
35
|
export declare function containsSubset(root: unknown, target: Record<string, unknown>): boolean;
|
|
41
36
|
export declare const isExistsError: (meta: any[], errorList: any[]) => boolean;
|
|
42
37
|
export declare const changeCopyField: (items: AtomsItem[], data: any[]) => AtomsItem[];
|