data-finder-ts 0.1.0 → 0.1.3
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/chunk-3SSWFES4.js +448 -0
- package/dist/chunk-3SSWFES4.js.map +1 -0
- package/dist/chunk-5K2Z3YDY.js +393 -0
- package/dist/chunk-5K2Z3YDY.js.map +1 -0
- package/dist/chunk-6QTCGJWX.js +98 -0
- package/dist/chunk-6QTCGJWX.js.map +1 -0
- package/dist/chunk-DFYZVBII.js +652 -0
- package/dist/chunk-DFYZVBII.js.map +1 -0
- package/dist/chunk-EYXBYV2X.js +90 -0
- package/dist/chunk-EYXBYV2X.js.map +1 -0
- package/dist/chunk-FLEIUDZZ.js +14 -0
- package/dist/chunk-FLEIUDZZ.js.map +1 -0
- package/dist/chunk-V647VNMY.js +135 -0
- package/dist/chunk-V647VNMY.js.map +1 -0
- package/dist/datafinder/attribute.cjs +269 -0
- package/dist/datafinder/attribute.cjs.map +1 -0
- package/dist/datafinder/attribute.d.cts +45 -0
- package/dist/datafinder/attribute.d.ts +45 -0
- package/dist/datafinder/attribute.js +8 -0
- package/dist/datafinder/attribute.js.map +1 -0
- package/dist/datafinder/finder-registry.cjs +39 -0
- package/dist/datafinder/finder-registry.cjs.map +1 -0
- package/dist/datafinder/finder-registry.d.cts +4 -0
- package/dist/datafinder/finder-registry.d.ts +4 -0
- package/dist/datafinder/finder-registry.js +9 -0
- package/dist/datafinder/finder-registry.js.map +1 -0
- package/dist/datafinder/runner.cjs +1346 -0
- package/dist/datafinder/runner.cjs.map +1 -0
- package/dist/datafinder/runner.d.cts +33 -0
- package/dist/datafinder/runner.d.ts +33 -0
- package/dist/datafinder/runner.js +20 -0
- package/dist/datafinder/runner.js.map +1 -0
- package/dist/datafinder/sql-generator.cjs +1261 -0
- package/dist/datafinder/sql-generator.cjs.map +1 -0
- package/dist/datafinder/sql-generator.d.cts +17 -0
- package/dist/datafinder/sql-generator.d.ts +17 -0
- package/dist/datafinder/sql-generator.js +17 -0
- package/dist/datafinder/sql-generator.js.map +1 -0
- package/dist/datafinder/typed-attributes.cjs +751 -0
- package/dist/datafinder/typed-attributes.cjs.map +1 -0
- package/dist/datafinder/typed-attributes.d.cts +135 -0
- package/dist/datafinder/typed-attributes.d.ts +135 -0
- package/dist/datafinder/typed-attributes.js +25 -0
- package/dist/datafinder/typed-attributes.js.map +1 -0
- package/dist/index.cjs +1822 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/model/milestoning.cjs +145 -0
- package/dist/model/milestoning.cjs.map +1 -0
- package/dist/model/milestoning.d.cts +40 -0
- package/dist/model/milestoning.d.ts +40 -0
- package/dist/model/milestoning.js +18 -0
- package/dist/model/milestoning.js.map +1 -0
- package/dist/model/relational.cjs +514 -0
- package/dist/model/relational.cjs.map +1 -0
- package/dist/model/relational.d.cts +246 -0
- package/dist/model/relational.d.ts +246 -0
- package/dist/model/relational.js +91 -0
- package/dist/model/relational.js.map +1 -0
- package/package.json +3 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1822 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AggregateOperation: () => AggregateOperation,
|
|
24
|
+
AggregateOperator: () => AggregateOperator,
|
|
25
|
+
Attribute: () => Attribute,
|
|
26
|
+
BiTemporalColumns: () => BiTemporalColumns,
|
|
27
|
+
BinaryOperation: () => BinaryOperation,
|
|
28
|
+
BooleanAttribute: () => BooleanAttribute,
|
|
29
|
+
BooleanConstantOperation: () => BooleanConstantOperation,
|
|
30
|
+
BusinessDateAndProcessingTemporalColumns: () => BusinessDateAndProcessingTemporalColumns,
|
|
31
|
+
Column: () => Column,
|
|
32
|
+
ColumnWithJoin: () => ColumnWithJoin,
|
|
33
|
+
ComparisonOperation: () => ComparisonOperation,
|
|
34
|
+
ComparisonOperator: () => ComparisonOperator,
|
|
35
|
+
ConstantOperation: () => ConstantOperation,
|
|
36
|
+
CountAllOperation: () => CountAllOperation,
|
|
37
|
+
DataCatalog: () => DataCatalog,
|
|
38
|
+
DataStore: () => DataStore,
|
|
39
|
+
Database: () => Database,
|
|
40
|
+
DateArithmeticOperation: () => DateArithmeticOperation,
|
|
41
|
+
DateAttribute: () => DateAttribute,
|
|
42
|
+
DateConstantOperation: () => DateConstantOperation,
|
|
43
|
+
DateDiffOperation: () => DateDiffOperation,
|
|
44
|
+
DateExtractOperation: () => DateExtractOperation,
|
|
45
|
+
DatePart: () => DatePart,
|
|
46
|
+
DateTimeAttribute: () => DateTimeAttribute,
|
|
47
|
+
DateTimeConstantOperation: () => DateTimeConstantOperation,
|
|
48
|
+
DecimalAttribute: () => DecimalAttribute,
|
|
49
|
+
DecimalConstantOperation: () => DecimalConstantOperation,
|
|
50
|
+
DoubleAttribute: () => DoubleAttribute,
|
|
51
|
+
ExistsOperation: () => ExistsOperation,
|
|
52
|
+
FinderResult: () => FinderResult,
|
|
53
|
+
FloatAttribute: () => FloatAttribute,
|
|
54
|
+
FloatConstantOperation: () => FloatConstantOperation,
|
|
55
|
+
ForeignKey: () => ForeignKey,
|
|
56
|
+
IntegerAttribute: () => IntegerAttribute,
|
|
57
|
+
IntegerConstantOperation: () => IntegerConstantOperation,
|
|
58
|
+
IsNotNullOperation: () => IsNotNullOperation,
|
|
59
|
+
IsNullOperation: () => IsNullOperation,
|
|
60
|
+
JoinOperation: () => JoinOperation,
|
|
61
|
+
JoinTreeNodeOperation: () => JoinTreeNodeOperation,
|
|
62
|
+
LogicalOperation: () => LogicalOperation,
|
|
63
|
+
LogicalOperator: () => LogicalOperator,
|
|
64
|
+
MilestonedTable: () => MilestonedTable,
|
|
65
|
+
MilestoningColumns: () => MilestoningColumns,
|
|
66
|
+
NoOperation: () => NoOperation,
|
|
67
|
+
NotExistsOperation: () => NotExistsOperation,
|
|
68
|
+
NumericAttribute: () => NumericAttribute,
|
|
69
|
+
Operation: () => Operation,
|
|
70
|
+
ProcessingTemporalColumns: () => ProcessingTemporalColumns,
|
|
71
|
+
RelatedFinder: () => RelatedFinder,
|
|
72
|
+
RelationalOperationElement: () => RelationalOperationElement,
|
|
73
|
+
ScalarFunction: () => ScalarFunction,
|
|
74
|
+
ScalarFunctionOperation: () => ScalarFunctionOperation,
|
|
75
|
+
Schema: () => Schema,
|
|
76
|
+
SingleBusinessDateColumn: () => SingleBusinessDateColumn,
|
|
77
|
+
SortDirection: () => SortDirection,
|
|
78
|
+
SortOperation: () => SortOperation,
|
|
79
|
+
StringAttribute: () => StringAttribute,
|
|
80
|
+
StringConstantOperation: () => StringConstantOperation,
|
|
81
|
+
Table: () => Table,
|
|
82
|
+
UnaryOperation: () => UnaryOperation,
|
|
83
|
+
WindowFunction: () => WindowFunction,
|
|
84
|
+
WindowFunctionOperation: () => WindowFunctionOperation,
|
|
85
|
+
WindowSpecification: () => WindowSpecification,
|
|
86
|
+
clearRunner: () => clearRunner,
|
|
87
|
+
convertInputsAndSelect: () => convertInputsAndSelect,
|
|
88
|
+
getRelatedFinderClass: () => getRelatedFinderClass,
|
|
89
|
+
getRunner: () => getRunner,
|
|
90
|
+
registerRelatedFinderClass: () => registerRelatedFinderClass,
|
|
91
|
+
registerRunner: () => registerRunner,
|
|
92
|
+
selectSqlToString: () => selectSqlToString,
|
|
93
|
+
toSql: () => toSql
|
|
94
|
+
});
|
|
95
|
+
module.exports = __toCommonJS(src_exports);
|
|
96
|
+
|
|
97
|
+
// src/model/relational.ts
|
|
98
|
+
var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
|
|
99
|
+
ComparisonOperator2["EQUAL"] = "EQUAL";
|
|
100
|
+
ComparisonOperator2["NOT_EQUAL"] = "NOT_EQUAL";
|
|
101
|
+
ComparisonOperator2["LESS_THAN"] = "LESS_THAN";
|
|
102
|
+
ComparisonOperator2["GREATER_THAN"] = "GREATER_THAN";
|
|
103
|
+
ComparisonOperator2["LESS_THAN_OR_EQUAL_TO"] = "LESS_THAN_OR_EQUAL_TO";
|
|
104
|
+
ComparisonOperator2["GREATER_THAN_OR_EQUAL_TO"] = "GREATER_THAN_OR_EQUAL_TO";
|
|
105
|
+
ComparisonOperator2["LIKE"] = "LIKE";
|
|
106
|
+
ComparisonOperator2["NOT_LIKE"] = "NOT_LIKE";
|
|
107
|
+
return ComparisonOperator2;
|
|
108
|
+
})(ComparisonOperator || {});
|
|
109
|
+
var LogicalOperator = /* @__PURE__ */ ((LogicalOperator2) => {
|
|
110
|
+
LogicalOperator2["AND"] = "AND";
|
|
111
|
+
LogicalOperator2["OR"] = "OR";
|
|
112
|
+
return LogicalOperator2;
|
|
113
|
+
})(LogicalOperator || {});
|
|
114
|
+
var AggregateOperator = /* @__PURE__ */ ((AggregateOperator2) => {
|
|
115
|
+
AggregateOperator2["COUNT"] = "COUNT";
|
|
116
|
+
AggregateOperator2["SUM"] = "SUM";
|
|
117
|
+
AggregateOperator2["MIN"] = "MIN";
|
|
118
|
+
AggregateOperator2["MAX"] = "MAX";
|
|
119
|
+
AggregateOperator2["AVERAGE"] = "AVERAGE";
|
|
120
|
+
return AggregateOperator2;
|
|
121
|
+
})(AggregateOperator || {});
|
|
122
|
+
var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
|
|
123
|
+
ScalarFunction2["ABS"] = "ABS";
|
|
124
|
+
ScalarFunction2["CEILING"] = "CEILING";
|
|
125
|
+
ScalarFunction2["FLOOR"] = "FLOOR";
|
|
126
|
+
ScalarFunction2["MOD"] = "MOD";
|
|
127
|
+
ScalarFunction2["POWER"] = "POWER";
|
|
128
|
+
ScalarFunction2["SQRT"] = "SQRT";
|
|
129
|
+
ScalarFunction2["ROUND"] = "ROUND";
|
|
130
|
+
ScalarFunction2["UPPER"] = "UPPER";
|
|
131
|
+
ScalarFunction2["LOWER"] = "LOWER";
|
|
132
|
+
ScalarFunction2["TRIM"] = "TRIM";
|
|
133
|
+
ScalarFunction2["LTRIM"] = "LTRIM";
|
|
134
|
+
ScalarFunction2["RTRIM"] = "RTRIM";
|
|
135
|
+
ScalarFunction2["LENGTH"] = "LENGTH";
|
|
136
|
+
ScalarFunction2["REVERSE"] = "REVERSE";
|
|
137
|
+
ScalarFunction2["LEFT"] = "LEFT";
|
|
138
|
+
ScalarFunction2["RIGHT"] = "RIGHT";
|
|
139
|
+
ScalarFunction2["REPEAT"] = "REPEAT";
|
|
140
|
+
ScalarFunction2["REPLACE"] = "REPLACE";
|
|
141
|
+
ScalarFunction2["SUBSTRING"] = "SUBSTRING";
|
|
142
|
+
return ScalarFunction2;
|
|
143
|
+
})(ScalarFunction || {});
|
|
144
|
+
var DatePart = /* @__PURE__ */ ((DatePart2) => {
|
|
145
|
+
DatePart2["YEAR"] = "YEAR";
|
|
146
|
+
DatePart2["MONTH"] = "MONTH";
|
|
147
|
+
DatePart2["DAY"] = "DAY";
|
|
148
|
+
DatePart2["HOUR"] = "HOUR";
|
|
149
|
+
DatePart2["MINUTE"] = "MINUTE";
|
|
150
|
+
DatePart2["SECOND"] = "SECOND";
|
|
151
|
+
DatePart2["QUARTER"] = "QUARTER";
|
|
152
|
+
DatePart2["WEEK"] = "WEEK";
|
|
153
|
+
DatePart2["DOW"] = "DOW";
|
|
154
|
+
return DatePart2;
|
|
155
|
+
})(DatePart || {});
|
|
156
|
+
var SortDirection = /* @__PURE__ */ ((SortDirection2) => {
|
|
157
|
+
SortDirection2["ASC"] = "ASC";
|
|
158
|
+
SortDirection2["DESC"] = "DESC";
|
|
159
|
+
return SortDirection2;
|
|
160
|
+
})(SortDirection || {});
|
|
161
|
+
var RelationalOperationElement = class {
|
|
162
|
+
};
|
|
163
|
+
var Operation = class extends RelationalOperationElement {
|
|
164
|
+
andOp(other) {
|
|
165
|
+
return new LogicalOperation(this, "AND" /* AND */, other);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var NoOperation = class extends Operation {
|
|
169
|
+
andOp(other) {
|
|
170
|
+
return other;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var ConstantOperation = class extends RelationalOperationElement {
|
|
174
|
+
};
|
|
175
|
+
var IntegerConstantOperation = class extends ConstantOperation {
|
|
176
|
+
constructor(value) {
|
|
177
|
+
super();
|
|
178
|
+
this.value = value;
|
|
179
|
+
}
|
|
180
|
+
value;
|
|
181
|
+
};
|
|
182
|
+
var FloatConstantOperation = class extends ConstantOperation {
|
|
183
|
+
constructor(value) {
|
|
184
|
+
super();
|
|
185
|
+
this.value = value;
|
|
186
|
+
}
|
|
187
|
+
value;
|
|
188
|
+
};
|
|
189
|
+
var StringConstantOperation = class extends ConstantOperation {
|
|
190
|
+
constructor(value) {
|
|
191
|
+
super();
|
|
192
|
+
this.value = value;
|
|
193
|
+
}
|
|
194
|
+
value;
|
|
195
|
+
};
|
|
196
|
+
var DateConstantOperation = class extends ConstantOperation {
|
|
197
|
+
constructor(value) {
|
|
198
|
+
super();
|
|
199
|
+
this.value = value;
|
|
200
|
+
}
|
|
201
|
+
value;
|
|
202
|
+
};
|
|
203
|
+
var DateTimeConstantOperation = class extends ConstantOperation {
|
|
204
|
+
constructor(value) {
|
|
205
|
+
super();
|
|
206
|
+
this.value = value;
|
|
207
|
+
}
|
|
208
|
+
value;
|
|
209
|
+
};
|
|
210
|
+
var DecimalConstantOperation = class extends ConstantOperation {
|
|
211
|
+
constructor(value) {
|
|
212
|
+
super();
|
|
213
|
+
this.value = value;
|
|
214
|
+
}
|
|
215
|
+
value;
|
|
216
|
+
};
|
|
217
|
+
var BooleanConstantOperation = class extends ConstantOperation {
|
|
218
|
+
constructor(value) {
|
|
219
|
+
super();
|
|
220
|
+
this.value = value;
|
|
221
|
+
}
|
|
222
|
+
value;
|
|
223
|
+
};
|
|
224
|
+
var UnaryOperation = class extends Operation {
|
|
225
|
+
constructor(element) {
|
|
226
|
+
super();
|
|
227
|
+
this.element = element;
|
|
228
|
+
}
|
|
229
|
+
element;
|
|
230
|
+
};
|
|
231
|
+
var BinaryOperation = class extends Operation {
|
|
232
|
+
constructor(left, right) {
|
|
233
|
+
super();
|
|
234
|
+
this.left = left;
|
|
235
|
+
this.right = right;
|
|
236
|
+
}
|
|
237
|
+
left;
|
|
238
|
+
right;
|
|
239
|
+
};
|
|
240
|
+
var IsNullOperation = class extends UnaryOperation {
|
|
241
|
+
};
|
|
242
|
+
var IsNotNullOperation = class extends UnaryOperation {
|
|
243
|
+
};
|
|
244
|
+
var ComparisonOperation = class extends BinaryOperation {
|
|
245
|
+
constructor(left, operator, right) {
|
|
246
|
+
super(left, right);
|
|
247
|
+
this.operator = operator;
|
|
248
|
+
}
|
|
249
|
+
operator;
|
|
250
|
+
};
|
|
251
|
+
var LogicalOperation = class extends BinaryOperation {
|
|
252
|
+
constructor(left, operator, right) {
|
|
253
|
+
super(left, right);
|
|
254
|
+
this.operator = operator;
|
|
255
|
+
}
|
|
256
|
+
operator;
|
|
257
|
+
};
|
|
258
|
+
var WindowSpecification = class {
|
|
259
|
+
constructor(partitionBy = [], orderBy = []) {
|
|
260
|
+
this.partitionBy = partitionBy;
|
|
261
|
+
this.orderBy = orderBy;
|
|
262
|
+
}
|
|
263
|
+
partitionBy;
|
|
264
|
+
orderBy;
|
|
265
|
+
};
|
|
266
|
+
var AggregateOperation = class _AggregateOperation extends UnaryOperation {
|
|
267
|
+
constructor(element, operator, displayName, window) {
|
|
268
|
+
super(element);
|
|
269
|
+
this.operator = operator;
|
|
270
|
+
this.displayName = displayName;
|
|
271
|
+
this.window = window;
|
|
272
|
+
}
|
|
273
|
+
operator;
|
|
274
|
+
displayName;
|
|
275
|
+
window;
|
|
276
|
+
over(partitionBy, orderBy) {
|
|
277
|
+
return new _AggregateOperation(
|
|
278
|
+
this.element,
|
|
279
|
+
this.operator,
|
|
280
|
+
this.displayName,
|
|
281
|
+
new WindowSpecification(partitionBy ?? [], orderBy ?? [])
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var WindowFunction = /* @__PURE__ */ ((WindowFunction2) => {
|
|
286
|
+
WindowFunction2["ROW_NUMBER"] = "ROW_NUMBER";
|
|
287
|
+
WindowFunction2["RANK"] = "RANK";
|
|
288
|
+
WindowFunction2["DENSE_RANK"] = "DENSE_RANK";
|
|
289
|
+
WindowFunction2["NTILE"] = "NTILE";
|
|
290
|
+
WindowFunction2["LAG"] = "LAG";
|
|
291
|
+
WindowFunction2["LEAD"] = "LEAD";
|
|
292
|
+
WindowFunction2["FIRST_VALUE"] = "FIRST_VALUE";
|
|
293
|
+
WindowFunction2["LAST_VALUE"] = "LAST_VALUE";
|
|
294
|
+
WindowFunction2["CUME_DIST"] = "CUME_DIST";
|
|
295
|
+
WindowFunction2["PERCENT_RANK"] = "PERCENT_RANK";
|
|
296
|
+
return WindowFunction2;
|
|
297
|
+
})(WindowFunction || {});
|
|
298
|
+
var WindowFunctionOperation = class _WindowFunctionOperation extends UnaryOperation {
|
|
299
|
+
constructor(element, func, displayName, secondArg, extraArgs = [], window) {
|
|
300
|
+
super(element);
|
|
301
|
+
this.func = func;
|
|
302
|
+
this.displayName = displayName;
|
|
303
|
+
this.secondArg = secondArg;
|
|
304
|
+
this.extraArgs = extraArgs;
|
|
305
|
+
this.window = window;
|
|
306
|
+
}
|
|
307
|
+
func;
|
|
308
|
+
displayName;
|
|
309
|
+
secondArg;
|
|
310
|
+
extraArgs;
|
|
311
|
+
window;
|
|
312
|
+
over(partitionBy, orderBy) {
|
|
313
|
+
return new _WindowFunctionOperation(
|
|
314
|
+
this.element,
|
|
315
|
+
this.func,
|
|
316
|
+
this.displayName,
|
|
317
|
+
this.secondArg,
|
|
318
|
+
[...this.extraArgs],
|
|
319
|
+
new WindowSpecification(partitionBy ?? [], orderBy ?? [])
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
var ScalarFunctionOperation = class extends UnaryOperation {
|
|
324
|
+
constructor(element, func, displayName, secondArg, extraArgs = []) {
|
|
325
|
+
super(element);
|
|
326
|
+
this.func = func;
|
|
327
|
+
this.displayName = displayName;
|
|
328
|
+
this.secondArg = secondArg;
|
|
329
|
+
this.extraArgs = extraArgs;
|
|
330
|
+
}
|
|
331
|
+
func;
|
|
332
|
+
displayName;
|
|
333
|
+
secondArg;
|
|
334
|
+
extraArgs;
|
|
335
|
+
};
|
|
336
|
+
var DateExtractOperation = class extends UnaryOperation {
|
|
337
|
+
constructor(element, part, displayName) {
|
|
338
|
+
super(element);
|
|
339
|
+
this.part = part;
|
|
340
|
+
this.displayName = displayName;
|
|
341
|
+
}
|
|
342
|
+
part;
|
|
343
|
+
displayName;
|
|
344
|
+
};
|
|
345
|
+
var DateArithmeticOperation = class extends UnaryOperation {
|
|
346
|
+
constructor(element, n, unit, isAdd = true, displayName) {
|
|
347
|
+
super(element);
|
|
348
|
+
this.n = n;
|
|
349
|
+
this.unit = unit;
|
|
350
|
+
this.isAdd = isAdd;
|
|
351
|
+
this.displayName = displayName;
|
|
352
|
+
}
|
|
353
|
+
n;
|
|
354
|
+
unit;
|
|
355
|
+
isAdd;
|
|
356
|
+
displayName;
|
|
357
|
+
};
|
|
358
|
+
var DateDiffOperation = class extends UnaryOperation {
|
|
359
|
+
constructor(element, other, unit, displayName) {
|
|
360
|
+
super(element);
|
|
361
|
+
this.other = other;
|
|
362
|
+
this.unit = unit;
|
|
363
|
+
this.displayName = displayName;
|
|
364
|
+
}
|
|
365
|
+
other;
|
|
366
|
+
unit;
|
|
367
|
+
displayName;
|
|
368
|
+
};
|
|
369
|
+
var Column = class extends RelationalOperationElement {
|
|
370
|
+
constructor(name, type, owner, primaryKey = false) {
|
|
371
|
+
super();
|
|
372
|
+
this.name = name;
|
|
373
|
+
this.type = type;
|
|
374
|
+
this.owner = owner;
|
|
375
|
+
this.primaryKey = primaryKey;
|
|
376
|
+
}
|
|
377
|
+
name;
|
|
378
|
+
type;
|
|
379
|
+
owner;
|
|
380
|
+
primaryKey;
|
|
381
|
+
table;
|
|
382
|
+
};
|
|
383
|
+
var ForeignKey = class {
|
|
384
|
+
constructor(column, references) {
|
|
385
|
+
this.column = column;
|
|
386
|
+
this.references = references;
|
|
387
|
+
}
|
|
388
|
+
column;
|
|
389
|
+
references;
|
|
390
|
+
};
|
|
391
|
+
var DataStore = class {
|
|
392
|
+
constructor(name) {
|
|
393
|
+
this.name = name;
|
|
394
|
+
}
|
|
395
|
+
name;
|
|
396
|
+
schemas = [];
|
|
397
|
+
};
|
|
398
|
+
var Database = class extends DataStore {
|
|
399
|
+
constructor(name, location) {
|
|
400
|
+
super(name);
|
|
401
|
+
this.location = location;
|
|
402
|
+
}
|
|
403
|
+
location;
|
|
404
|
+
namespace(schemaName) {
|
|
405
|
+
return schemaName;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
var DataCatalog = class extends DataStore {
|
|
409
|
+
constructor(name) {
|
|
410
|
+
super(name);
|
|
411
|
+
}
|
|
412
|
+
namespace(schemaName) {
|
|
413
|
+
return `${this.name}.${schemaName}`;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var Schema = class {
|
|
417
|
+
constructor(name, datastore) {
|
|
418
|
+
this.name = name;
|
|
419
|
+
this.datastore = datastore;
|
|
420
|
+
datastore?.schemas.push(this);
|
|
421
|
+
}
|
|
422
|
+
name;
|
|
423
|
+
datastore;
|
|
424
|
+
tables = [];
|
|
425
|
+
};
|
|
426
|
+
var Table = class {
|
|
427
|
+
constructor(name, columns, schema) {
|
|
428
|
+
this.name = name;
|
|
429
|
+
this.schema = schema;
|
|
430
|
+
for (const col of columns) {
|
|
431
|
+
if (this._columnsByName.has(col.name)) {
|
|
432
|
+
throw new Error(`Duplicate column name '${col.name}' in table '${name}'`);
|
|
433
|
+
}
|
|
434
|
+
this._columnsByName.set(col.name, col);
|
|
435
|
+
col.table = this;
|
|
436
|
+
}
|
|
437
|
+
schema?.tables.push(this);
|
|
438
|
+
}
|
|
439
|
+
name;
|
|
440
|
+
schema;
|
|
441
|
+
_columnsByName = /* @__PURE__ */ new Map();
|
|
442
|
+
foreignKeys = [];
|
|
443
|
+
get columns() {
|
|
444
|
+
return Array.from(this._columnsByName.values());
|
|
445
|
+
}
|
|
446
|
+
get qualifiedName() {
|
|
447
|
+
if (!this.schema) return this.name;
|
|
448
|
+
if (!this.schema.datastore) return `${this.schema.name}.${this.name}`;
|
|
449
|
+
return `${this.schema.datastore.namespace(this.schema.name)}.${this.name}`;
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
var JoinOperation = class {
|
|
453
|
+
constructor(name, target, left, right, filter) {
|
|
454
|
+
this.name = name;
|
|
455
|
+
this.target = target;
|
|
456
|
+
this.left = left;
|
|
457
|
+
this.right = right;
|
|
458
|
+
this.filter = filter;
|
|
459
|
+
}
|
|
460
|
+
name;
|
|
461
|
+
target;
|
|
462
|
+
left;
|
|
463
|
+
right;
|
|
464
|
+
filter;
|
|
465
|
+
};
|
|
466
|
+
var JoinTreeNodeOperation = class {
|
|
467
|
+
constructor(join, parent) {
|
|
468
|
+
this.join = join;
|
|
469
|
+
this.parent = parent;
|
|
470
|
+
}
|
|
471
|
+
join;
|
|
472
|
+
parent;
|
|
473
|
+
};
|
|
474
|
+
var ColumnWithJoin = class extends RelationalOperationElement {
|
|
475
|
+
constructor(column, parent) {
|
|
476
|
+
super();
|
|
477
|
+
this.column = column;
|
|
478
|
+
this.parent = parent;
|
|
479
|
+
}
|
|
480
|
+
column;
|
|
481
|
+
parent;
|
|
482
|
+
};
|
|
483
|
+
var SortOperation = class {
|
|
484
|
+
constructor(column, direction) {
|
|
485
|
+
this.column = column;
|
|
486
|
+
this.direction = direction;
|
|
487
|
+
}
|
|
488
|
+
column;
|
|
489
|
+
direction;
|
|
490
|
+
};
|
|
491
|
+
var CountAllOperation = class extends RelationalOperationElement {
|
|
492
|
+
constructor(table) {
|
|
493
|
+
super();
|
|
494
|
+
this.table = table;
|
|
495
|
+
}
|
|
496
|
+
table;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// src/datafinder/attribute.ts
|
|
500
|
+
var Attribute = class {
|
|
501
|
+
_displayName;
|
|
502
|
+
_column;
|
|
503
|
+
_owner;
|
|
504
|
+
_parent;
|
|
505
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
506
|
+
this._displayName = displayName;
|
|
507
|
+
this._column = new Column(columnName, columnDbType, owner);
|
|
508
|
+
this._owner = owner;
|
|
509
|
+
this._parent = parent;
|
|
510
|
+
}
|
|
511
|
+
column() {
|
|
512
|
+
return this._column;
|
|
513
|
+
}
|
|
514
|
+
owner() {
|
|
515
|
+
return this._owner;
|
|
516
|
+
}
|
|
517
|
+
parent() {
|
|
518
|
+
return this._parent;
|
|
519
|
+
}
|
|
520
|
+
displayName() {
|
|
521
|
+
return this._displayName;
|
|
522
|
+
}
|
|
523
|
+
cwj() {
|
|
524
|
+
return new ColumnWithJoin(this._column, this._parent);
|
|
525
|
+
}
|
|
526
|
+
count() {
|
|
527
|
+
return new AggregateOperation(
|
|
528
|
+
new ColumnWithJoin(this._column, this._parent),
|
|
529
|
+
"COUNT" /* COUNT */,
|
|
530
|
+
this._displayName + " Count"
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
ascending() {
|
|
534
|
+
return new SortOperation(new ColumnWithJoin(this._column, this._parent), "ASC" /* ASC */);
|
|
535
|
+
}
|
|
536
|
+
descending() {
|
|
537
|
+
return new SortOperation(new ColumnWithJoin(this._column, this._parent), "DESC" /* DESC */);
|
|
538
|
+
}
|
|
539
|
+
isNull() {
|
|
540
|
+
return new IsNullOperation(new ColumnWithJoin(this._column, this._parent));
|
|
541
|
+
}
|
|
542
|
+
isNotNull() {
|
|
543
|
+
return new IsNotNullOperation(new ColumnWithJoin(this._column, this._parent));
|
|
544
|
+
}
|
|
545
|
+
_windowSpec(partitionBy, orderBy) {
|
|
546
|
+
const pb = partitionBy === void 0 ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];
|
|
547
|
+
const ob = orderBy === void 0 ? [] : Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
548
|
+
return new WindowSpecification(pb, ob);
|
|
549
|
+
}
|
|
550
|
+
rank(opts = {}) {
|
|
551
|
+
const { method = "min", pct = false, partitionBy, orderBy } = opts;
|
|
552
|
+
let func;
|
|
553
|
+
let name;
|
|
554
|
+
if (pct) {
|
|
555
|
+
if (method === "max") {
|
|
556
|
+
func = "CUME_DIST" /* CUME_DIST */;
|
|
557
|
+
name = "Cume Dist";
|
|
558
|
+
} else {
|
|
559
|
+
func = "PERCENT_RANK" /* PERCENT_RANK */;
|
|
560
|
+
name = "Percent Rank";
|
|
561
|
+
}
|
|
562
|
+
} else if (method === "first") {
|
|
563
|
+
func = "ROW_NUMBER" /* ROW_NUMBER */;
|
|
564
|
+
name = "Row Number";
|
|
565
|
+
} else if (method === "dense") {
|
|
566
|
+
func = "DENSE_RANK" /* DENSE_RANK */;
|
|
567
|
+
name = "Dense Rank";
|
|
568
|
+
} else {
|
|
569
|
+
func = "RANK" /* RANK */;
|
|
570
|
+
name = "Rank";
|
|
571
|
+
}
|
|
572
|
+
return new WindowFunctionOperation(null, func, name, void 0, [], this._windowSpec(partitionBy, orderBy));
|
|
573
|
+
}
|
|
574
|
+
qcut(buckets, opts = {}) {
|
|
575
|
+
return new WindowFunctionOperation(
|
|
576
|
+
null,
|
|
577
|
+
"NTILE" /* NTILE */,
|
|
578
|
+
"Quantile",
|
|
579
|
+
buckets,
|
|
580
|
+
[],
|
|
581
|
+
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
shift(periods = 1, opts = {}) {
|
|
585
|
+
const extraArgs = opts.fillValue !== void 0 ? [opts.fillValue] : [];
|
|
586
|
+
const func = periods >= 0 ? "LAG" /* LAG */ : "LEAD" /* LEAD */;
|
|
587
|
+
const label = periods >= 0 ? "Lag" : "Lead";
|
|
588
|
+
return new WindowFunctionOperation(
|
|
589
|
+
new ColumnWithJoin(this._column, this._parent),
|
|
590
|
+
func,
|
|
591
|
+
label + " " + this._displayName,
|
|
592
|
+
Math.abs(periods),
|
|
593
|
+
extraArgs,
|
|
594
|
+
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
first(opts = {}) {
|
|
598
|
+
return new WindowFunctionOperation(
|
|
599
|
+
new ColumnWithJoin(this._column, this._parent),
|
|
600
|
+
"FIRST_VALUE" /* FIRST_VALUE */,
|
|
601
|
+
"First " + this._displayName,
|
|
602
|
+
void 0,
|
|
603
|
+
[],
|
|
604
|
+
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
last(opts = {}) {
|
|
608
|
+
return new WindowFunctionOperation(
|
|
609
|
+
new ColumnWithJoin(this._column, this._parent),
|
|
610
|
+
"LAST_VALUE" /* LAST_VALUE */,
|
|
611
|
+
"Last " + this._displayName,
|
|
612
|
+
void 0,
|
|
613
|
+
[],
|
|
614
|
+
this._windowSpec(opts.partitionBy, opts.orderBy)
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/datafinder/finder-registry.ts
|
|
620
|
+
var _registry = /* @__PURE__ */ new Map();
|
|
621
|
+
function registerRelatedFinderClass(name, cls) {
|
|
622
|
+
_registry.set(name, cls);
|
|
623
|
+
}
|
|
624
|
+
function getRelatedFinderClass(name) {
|
|
625
|
+
return _registry.get(name);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/datafinder/typed-attributes.ts
|
|
629
|
+
var StringAttribute = class extends Attribute {
|
|
630
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
631
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
632
|
+
}
|
|
633
|
+
upper() {
|
|
634
|
+
return new ScalarFunctionOperation(this.cwj(), "UPPER" /* UPPER */, "Upper " + this.displayName());
|
|
635
|
+
}
|
|
636
|
+
lower() {
|
|
637
|
+
return new ScalarFunctionOperation(this.cwj(), "LOWER" /* LOWER */, "Lower " + this.displayName());
|
|
638
|
+
}
|
|
639
|
+
strip() {
|
|
640
|
+
return new ScalarFunctionOperation(this.cwj(), "TRIM" /* TRIM */, "Strip " + this.displayName());
|
|
641
|
+
}
|
|
642
|
+
lstrip() {
|
|
643
|
+
return new ScalarFunctionOperation(this.cwj(), "LTRIM" /* LTRIM */, "LStrip " + this.displayName());
|
|
644
|
+
}
|
|
645
|
+
rstrip() {
|
|
646
|
+
return new ScalarFunctionOperation(this.cwj(), "RTRIM" /* RTRIM */, "RStrip " + this.displayName());
|
|
647
|
+
}
|
|
648
|
+
length() {
|
|
649
|
+
return new ScalarFunctionOperation(this.cwj(), "LENGTH" /* LENGTH */, "Length " + this.displayName());
|
|
650
|
+
}
|
|
651
|
+
reverse() {
|
|
652
|
+
return new ScalarFunctionOperation(this.cwj(), "REVERSE" /* REVERSE */, "Reverse " + this.displayName());
|
|
653
|
+
}
|
|
654
|
+
left(n) {
|
|
655
|
+
return new ScalarFunctionOperation(this.cwj(), "LEFT" /* LEFT */, "Left " + this.displayName(), n);
|
|
656
|
+
}
|
|
657
|
+
right(n) {
|
|
658
|
+
return new ScalarFunctionOperation(this.cwj(), "RIGHT" /* RIGHT */, "Right " + this.displayName(), n);
|
|
659
|
+
}
|
|
660
|
+
repeat(n) {
|
|
661
|
+
return new ScalarFunctionOperation(this.cwj(), "REPEAT" /* REPEAT */, "Repeat " + this.displayName(), n);
|
|
662
|
+
}
|
|
663
|
+
replace(fromStr, toStr) {
|
|
664
|
+
return new ScalarFunctionOperation(this.cwj(), "REPLACE" /* REPLACE */, "Replace " + this.displayName(), void 0, [fromStr, toStr]);
|
|
665
|
+
}
|
|
666
|
+
substring(start, length) {
|
|
667
|
+
const args = length !== void 0 ? [start + 1, length] : [start + 1];
|
|
668
|
+
return new ScalarFunctionOperation(this.cwj(), "SUBSTRING" /* SUBSTRING */, "Substring " + this.displayName(), void 0, args);
|
|
669
|
+
}
|
|
670
|
+
eq(value) {
|
|
671
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new StringConstantOperation(value));
|
|
672
|
+
}
|
|
673
|
+
ne(value) {
|
|
674
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new StringConstantOperation(value));
|
|
675
|
+
}
|
|
676
|
+
contains(value) {
|
|
677
|
+
return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`%${value}%`));
|
|
678
|
+
}
|
|
679
|
+
startsWith(prefix) {
|
|
680
|
+
return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`${prefix}%`));
|
|
681
|
+
}
|
|
682
|
+
endsWith(suffix) {
|
|
683
|
+
return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`%${suffix}`));
|
|
684
|
+
}
|
|
685
|
+
notContains(value) {
|
|
686
|
+
return new ComparisonOperation(this.cwj(), "NOT_LIKE" /* NOT_LIKE */, new StringConstantOperation(`%${value}%`));
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
var NumericAttribute = class extends Attribute {
|
|
690
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
691
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
692
|
+
}
|
|
693
|
+
sum() {
|
|
694
|
+
return new AggregateOperation(this.cwj(), "SUM" /* SUM */, this.displayName() + " Sum");
|
|
695
|
+
}
|
|
696
|
+
min() {
|
|
697
|
+
return new AggregateOperation(this.cwj(), "MIN" /* MIN */, this.displayName() + " Min");
|
|
698
|
+
}
|
|
699
|
+
max() {
|
|
700
|
+
return new AggregateOperation(this.cwj(), "MAX" /* MAX */, this.displayName() + " Max");
|
|
701
|
+
}
|
|
702
|
+
average() {
|
|
703
|
+
return new AggregateOperation(this.cwj(), "AVERAGE" /* AVERAGE */, this.displayName() + " Average");
|
|
704
|
+
}
|
|
705
|
+
abs() {
|
|
706
|
+
return new ScalarFunctionOperation(this.cwj(), "ABS" /* ABS */, "Abs " + this.displayName());
|
|
707
|
+
}
|
|
708
|
+
ceil() {
|
|
709
|
+
return new ScalarFunctionOperation(this.cwj(), "CEILING" /* CEILING */, "Ceil " + this.displayName());
|
|
710
|
+
}
|
|
711
|
+
floor() {
|
|
712
|
+
return new ScalarFunctionOperation(this.cwj(), "FLOOR" /* FLOOR */, "Floor " + this.displayName());
|
|
713
|
+
}
|
|
714
|
+
sqrt() {
|
|
715
|
+
return new ScalarFunctionOperation(this.cwj(), "SQRT" /* SQRT */, "Sqrt " + this.displayName());
|
|
716
|
+
}
|
|
717
|
+
mod(n) {
|
|
718
|
+
return new ScalarFunctionOperation(this.cwj(), "MOD" /* MOD */, "Mod " + this.displayName(), n);
|
|
719
|
+
}
|
|
720
|
+
power(n) {
|
|
721
|
+
return new ScalarFunctionOperation(this.cwj(), "POWER" /* POWER */, "Power " + this.displayName(), n);
|
|
722
|
+
}
|
|
723
|
+
round(d) {
|
|
724
|
+
return new ScalarFunctionOperation(this.cwj(), "ROUND" /* ROUND */, "Round " + this.displayName(), d);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
var DoubleAttribute = class extends NumericAttribute {
|
|
728
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
729
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
730
|
+
}
|
|
731
|
+
eq(value) {
|
|
732
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new FloatConstantOperation(value));
|
|
733
|
+
}
|
|
734
|
+
ne(value) {
|
|
735
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new FloatConstantOperation(value));
|
|
736
|
+
}
|
|
737
|
+
gt(value) {
|
|
738
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new FloatConstantOperation(value));
|
|
739
|
+
}
|
|
740
|
+
lt(value) {
|
|
741
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new FloatConstantOperation(value));
|
|
742
|
+
}
|
|
743
|
+
gte(value) {
|
|
744
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new FloatConstantOperation(value));
|
|
745
|
+
}
|
|
746
|
+
lte(value) {
|
|
747
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new FloatConstantOperation(value));
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
var FloatAttribute = DoubleAttribute;
|
|
751
|
+
var DecimalAttribute = class extends NumericAttribute {
|
|
752
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
753
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
754
|
+
}
|
|
755
|
+
eq(value) {
|
|
756
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DecimalConstantOperation(value));
|
|
757
|
+
}
|
|
758
|
+
ne(value) {
|
|
759
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DecimalConstantOperation(value));
|
|
760
|
+
}
|
|
761
|
+
gt(value) {
|
|
762
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DecimalConstantOperation(value));
|
|
763
|
+
}
|
|
764
|
+
lt(value) {
|
|
765
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DecimalConstantOperation(value));
|
|
766
|
+
}
|
|
767
|
+
gte(value) {
|
|
768
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DecimalConstantOperation(value));
|
|
769
|
+
}
|
|
770
|
+
lte(value) {
|
|
771
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DecimalConstantOperation(value));
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
var IntegerAttribute = class extends NumericAttribute {
|
|
775
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
776
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
777
|
+
}
|
|
778
|
+
eq(value) {
|
|
779
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new IntegerConstantOperation(value));
|
|
780
|
+
}
|
|
781
|
+
ne(value) {
|
|
782
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new IntegerConstantOperation(value));
|
|
783
|
+
}
|
|
784
|
+
gt(value) {
|
|
785
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new IntegerConstantOperation(value));
|
|
786
|
+
}
|
|
787
|
+
lt(value) {
|
|
788
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new IntegerConstantOperation(value));
|
|
789
|
+
}
|
|
790
|
+
gte(value) {
|
|
791
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new IntegerConstantOperation(value));
|
|
792
|
+
}
|
|
793
|
+
lte(value) {
|
|
794
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new IntegerConstantOperation(value));
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
var BooleanAttribute = class extends Attribute {
|
|
798
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
799
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
800
|
+
}
|
|
801
|
+
eq(value) {
|
|
802
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(value));
|
|
803
|
+
}
|
|
804
|
+
isTrue() {
|
|
805
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(true));
|
|
806
|
+
}
|
|
807
|
+
isFalse() {
|
|
808
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(false));
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
function parseDate(value) {
|
|
812
|
+
if (value instanceof Date) return value;
|
|
813
|
+
const d = new Date(value);
|
|
814
|
+
if (isNaN(d.getTime())) throw new Error(`Cannot parse date: ${value}`);
|
|
815
|
+
return d;
|
|
816
|
+
}
|
|
817
|
+
var DateAttribute = class extends Attribute {
|
|
818
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
819
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
820
|
+
}
|
|
821
|
+
eq(value) {
|
|
822
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DateConstantOperation(parseDate(value)));
|
|
823
|
+
}
|
|
824
|
+
ne(value) {
|
|
825
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DateConstantOperation(parseDate(value)));
|
|
826
|
+
}
|
|
827
|
+
gt(value) {
|
|
828
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DateConstantOperation(parseDate(value)));
|
|
829
|
+
}
|
|
830
|
+
lt(value) {
|
|
831
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DateConstantOperation(parseDate(value)));
|
|
832
|
+
}
|
|
833
|
+
gte(value) {
|
|
834
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DateConstantOperation(parseDate(value)));
|
|
835
|
+
}
|
|
836
|
+
lte(value) {
|
|
837
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DateConstantOperation(parseDate(value)));
|
|
838
|
+
}
|
|
839
|
+
year() {
|
|
840
|
+
return new DateExtractOperation(this.cwj(), "YEAR" /* YEAR */, "Year " + this.displayName());
|
|
841
|
+
}
|
|
842
|
+
month() {
|
|
843
|
+
return new DateExtractOperation(this.cwj(), "MONTH" /* MONTH */, "Month " + this.displayName());
|
|
844
|
+
}
|
|
845
|
+
day() {
|
|
846
|
+
return new DateExtractOperation(this.cwj(), "DAY" /* DAY */, "Day " + this.displayName());
|
|
847
|
+
}
|
|
848
|
+
quarter() {
|
|
849
|
+
return new DateExtractOperation(this.cwj(), "QUARTER" /* QUARTER */, "Quarter " + this.displayName());
|
|
850
|
+
}
|
|
851
|
+
week() {
|
|
852
|
+
return new DateExtractOperation(this.cwj(), "WEEK" /* WEEK */, "Week " + this.displayName());
|
|
853
|
+
}
|
|
854
|
+
dayOfWeek() {
|
|
855
|
+
return new DateExtractOperation(this.cwj(), "DOW" /* DOW */, "Day Of Week " + this.displayName());
|
|
856
|
+
}
|
|
857
|
+
addDays(n) {
|
|
858
|
+
return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, true, "Add Days " + this.displayName());
|
|
859
|
+
}
|
|
860
|
+
addMonths(n) {
|
|
861
|
+
return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, true, "Add Months " + this.displayName());
|
|
862
|
+
}
|
|
863
|
+
addYears(n) {
|
|
864
|
+
return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, true, "Add Years " + this.displayName());
|
|
865
|
+
}
|
|
866
|
+
subtractDays(n) {
|
|
867
|
+
return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, false, "Subtract Days " + this.displayName());
|
|
868
|
+
}
|
|
869
|
+
subtractMonths(n) {
|
|
870
|
+
return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, false, "Subtract Months " + this.displayName());
|
|
871
|
+
}
|
|
872
|
+
subtractYears(n) {
|
|
873
|
+
return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, false, "Subtract Years " + this.displayName());
|
|
874
|
+
}
|
|
875
|
+
diffDays(other) {
|
|
876
|
+
return new DateDiffOperation(this.cwj(), other, "DAY" /* DAY */, "Diff Days " + this.displayName());
|
|
877
|
+
}
|
|
878
|
+
diffMonths(other) {
|
|
879
|
+
return new DateDiffOperation(this.cwj(), other, "MONTH" /* MONTH */, "Diff Months " + this.displayName());
|
|
880
|
+
}
|
|
881
|
+
diffYears(other) {
|
|
882
|
+
return new DateDiffOperation(this.cwj(), other, "YEAR" /* YEAR */, "Diff Years " + this.displayName());
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
var DateTimeAttribute = class extends Attribute {
|
|
886
|
+
constructor(displayName, columnName, columnDbType, owner, parent) {
|
|
887
|
+
super(displayName, columnName, columnDbType, owner, parent);
|
|
888
|
+
}
|
|
889
|
+
eq(value) {
|
|
890
|
+
return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DateTimeConstantOperation(parseDate(value)));
|
|
891
|
+
}
|
|
892
|
+
ne(value) {
|
|
893
|
+
return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DateTimeConstantOperation(parseDate(value)));
|
|
894
|
+
}
|
|
895
|
+
gt(value) {
|
|
896
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DateTimeConstantOperation(parseDate(value)));
|
|
897
|
+
}
|
|
898
|
+
lt(value) {
|
|
899
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DateTimeConstantOperation(parseDate(value)));
|
|
900
|
+
}
|
|
901
|
+
gte(value) {
|
|
902
|
+
return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DateTimeConstantOperation(parseDate(value)));
|
|
903
|
+
}
|
|
904
|
+
lte(value) {
|
|
905
|
+
return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DateTimeConstantOperation(parseDate(value)));
|
|
906
|
+
}
|
|
907
|
+
year() {
|
|
908
|
+
return new DateExtractOperation(this.cwj(), "YEAR" /* YEAR */, "Year " + this.displayName());
|
|
909
|
+
}
|
|
910
|
+
month() {
|
|
911
|
+
return new DateExtractOperation(this.cwj(), "MONTH" /* MONTH */, "Month " + this.displayName());
|
|
912
|
+
}
|
|
913
|
+
day() {
|
|
914
|
+
return new DateExtractOperation(this.cwj(), "DAY" /* DAY */, "Day " + this.displayName());
|
|
915
|
+
}
|
|
916
|
+
hour() {
|
|
917
|
+
return new DateExtractOperation(this.cwj(), "HOUR" /* HOUR */, "Hour " + this.displayName());
|
|
918
|
+
}
|
|
919
|
+
minute() {
|
|
920
|
+
return new DateExtractOperation(this.cwj(), "MINUTE" /* MINUTE */, "Minute " + this.displayName());
|
|
921
|
+
}
|
|
922
|
+
second() {
|
|
923
|
+
return new DateExtractOperation(this.cwj(), "SECOND" /* SECOND */, "Second " + this.displayName());
|
|
924
|
+
}
|
|
925
|
+
quarter() {
|
|
926
|
+
return new DateExtractOperation(this.cwj(), "QUARTER" /* QUARTER */, "Quarter " + this.displayName());
|
|
927
|
+
}
|
|
928
|
+
week() {
|
|
929
|
+
return new DateExtractOperation(this.cwj(), "WEEK" /* WEEK */, "Week " + this.displayName());
|
|
930
|
+
}
|
|
931
|
+
dayOfWeek() {
|
|
932
|
+
return new DateExtractOperation(this.cwj(), "DOW" /* DOW */, "Day Of Week " + this.displayName());
|
|
933
|
+
}
|
|
934
|
+
addDays(n) {
|
|
935
|
+
return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, true, "Add Days " + this.displayName());
|
|
936
|
+
}
|
|
937
|
+
addMonths(n) {
|
|
938
|
+
return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, true, "Add Months " + this.displayName());
|
|
939
|
+
}
|
|
940
|
+
addYears(n) {
|
|
941
|
+
return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, true, "Add Years " + this.displayName());
|
|
942
|
+
}
|
|
943
|
+
addHours(n) {
|
|
944
|
+
return new DateArithmeticOperation(this.cwj(), n, "HOUR" /* HOUR */, true, "Add Hours " + this.displayName());
|
|
945
|
+
}
|
|
946
|
+
addMinutes(n) {
|
|
947
|
+
return new DateArithmeticOperation(this.cwj(), n, "MINUTE" /* MINUTE */, true, "Add Minutes " + this.displayName());
|
|
948
|
+
}
|
|
949
|
+
addSeconds(n) {
|
|
950
|
+
return new DateArithmeticOperation(this.cwj(), n, "SECOND" /* SECOND */, true, "Add Seconds " + this.displayName());
|
|
951
|
+
}
|
|
952
|
+
subtractDays(n) {
|
|
953
|
+
return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, false, "Subtract Days " + this.displayName());
|
|
954
|
+
}
|
|
955
|
+
subtractMonths(n) {
|
|
956
|
+
return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, false, "Subtract Months " + this.displayName());
|
|
957
|
+
}
|
|
958
|
+
subtractYears(n) {
|
|
959
|
+
return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, false, "Subtract Years " + this.displayName());
|
|
960
|
+
}
|
|
961
|
+
subtractHours(n) {
|
|
962
|
+
return new DateArithmeticOperation(this.cwj(), n, "HOUR" /* HOUR */, false, "Subtract Hours " + this.displayName());
|
|
963
|
+
}
|
|
964
|
+
subtractMinutes(n) {
|
|
965
|
+
return new DateArithmeticOperation(this.cwj(), n, "MINUTE" /* MINUTE */, false, "Subtract Minutes " + this.displayName());
|
|
966
|
+
}
|
|
967
|
+
subtractSeconds(n) {
|
|
968
|
+
return new DateArithmeticOperation(this.cwj(), n, "SECOND" /* SECOND */, false, "Subtract Seconds " + this.displayName());
|
|
969
|
+
}
|
|
970
|
+
diffDays(other) {
|
|
971
|
+
return new DateDiffOperation(this.cwj(), other, "DAY" /* DAY */, "Diff Days " + this.displayName());
|
|
972
|
+
}
|
|
973
|
+
diffMonths(other) {
|
|
974
|
+
return new DateDiffOperation(this.cwj(), other, "MONTH" /* MONTH */, "Diff Months " + this.displayName());
|
|
975
|
+
}
|
|
976
|
+
diffYears(other) {
|
|
977
|
+
return new DateDiffOperation(this.cwj(), other, "YEAR" /* YEAR */, "Diff Years " + this.displayName());
|
|
978
|
+
}
|
|
979
|
+
diffHours(other) {
|
|
980
|
+
return new DateDiffOperation(this.cwj(), other, "HOUR" /* HOUR */, "Diff Hours " + this.displayName());
|
|
981
|
+
}
|
|
982
|
+
diffMinutes(other) {
|
|
983
|
+
return new DateDiffOperation(this.cwj(), other, "MINUTE" /* MINUTE */, "Diff Minutes " + this.displayName());
|
|
984
|
+
}
|
|
985
|
+
diffSeconds(other) {
|
|
986
|
+
return new DateDiffOperation(this.cwj(), other, "SECOND" /* SECOND */, "Diff Seconds " + this.displayName());
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
// src/model/milestoning.ts
|
|
991
|
+
var MilestoningColumns = class {
|
|
992
|
+
};
|
|
993
|
+
var ProcessingTemporalColumns = class extends MilestoningColumns {
|
|
994
|
+
constructor(startAtColumn, endAtColumn, infiniteDatetime) {
|
|
995
|
+
super();
|
|
996
|
+
this.startAtColumn = startAtColumn;
|
|
997
|
+
this.endAtColumn = endAtColumn;
|
|
998
|
+
this.infiniteDatetime = infiniteDatetime;
|
|
999
|
+
}
|
|
1000
|
+
startAtColumn;
|
|
1001
|
+
endAtColumn;
|
|
1002
|
+
infiniteDatetime;
|
|
1003
|
+
columns() {
|
|
1004
|
+
return [this.startAtColumn, this.endAtColumn];
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
var SingleBusinessDateColumn = class extends MilestoningColumns {
|
|
1008
|
+
constructor(businessDateColumn) {
|
|
1009
|
+
super();
|
|
1010
|
+
this.businessDateColumn = businessDateColumn;
|
|
1011
|
+
}
|
|
1012
|
+
businessDateColumn;
|
|
1013
|
+
columns() {
|
|
1014
|
+
return [this.businessDateColumn];
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
var BusinessDateAndProcessingTemporalColumns = class extends MilestoningColumns {
|
|
1018
|
+
constructor(businessDateColumn, startAtColumn, endAtColumn, infiniteDatetime) {
|
|
1019
|
+
super();
|
|
1020
|
+
this.businessDateColumn = businessDateColumn;
|
|
1021
|
+
this.startAtColumn = startAtColumn;
|
|
1022
|
+
this.endAtColumn = endAtColumn;
|
|
1023
|
+
this.infiniteDatetime = infiniteDatetime;
|
|
1024
|
+
}
|
|
1025
|
+
businessDateColumn;
|
|
1026
|
+
startAtColumn;
|
|
1027
|
+
endAtColumn;
|
|
1028
|
+
infiniteDatetime;
|
|
1029
|
+
columns() {
|
|
1030
|
+
return [this.businessDateColumn, this.startAtColumn, this.endAtColumn];
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
var BiTemporalColumns = class extends MilestoningColumns {
|
|
1034
|
+
constructor(businessDateFromColumn, businessDateToColumn, startAtColumn, endAtColumn, infiniteDatetime) {
|
|
1035
|
+
super();
|
|
1036
|
+
this.businessDateFromColumn = businessDateFromColumn;
|
|
1037
|
+
this.businessDateToColumn = businessDateToColumn;
|
|
1038
|
+
this.startAtColumn = startAtColumn;
|
|
1039
|
+
this.endAtColumn = endAtColumn;
|
|
1040
|
+
this.infiniteDatetime = infiniteDatetime;
|
|
1041
|
+
}
|
|
1042
|
+
businessDateFromColumn;
|
|
1043
|
+
businessDateToColumn;
|
|
1044
|
+
startAtColumn;
|
|
1045
|
+
endAtColumn;
|
|
1046
|
+
infiniteDatetime;
|
|
1047
|
+
columns() {
|
|
1048
|
+
return [
|
|
1049
|
+
this.businessDateFromColumn,
|
|
1050
|
+
this.businessDateToColumn,
|
|
1051
|
+
this.startAtColumn,
|
|
1052
|
+
this.endAtColumn
|
|
1053
|
+
];
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
var MilestonedTable = class extends Table {
|
|
1057
|
+
constructor(name, columns, milestoningColumns, schema) {
|
|
1058
|
+
super(name, columns, schema);
|
|
1059
|
+
this.milestoningColumns = milestoningColumns;
|
|
1060
|
+
for (const col of milestoningColumns.columns()) {
|
|
1061
|
+
col.table = this;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
milestoningColumns;
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
// src/datafinder/finder.ts
|
|
1068
|
+
var ExistsOperation = class extends RelationalOperationElement {
|
|
1069
|
+
constructor(node) {
|
|
1070
|
+
super();
|
|
1071
|
+
this.node = node;
|
|
1072
|
+
}
|
|
1073
|
+
node;
|
|
1074
|
+
andOp(other) {
|
|
1075
|
+
return new LogicalOperation(this, "AND" /* AND */, other);
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
var NotExistsOperation = class extends RelationalOperationElement {
|
|
1079
|
+
constructor(node) {
|
|
1080
|
+
super();
|
|
1081
|
+
this.node = node;
|
|
1082
|
+
}
|
|
1083
|
+
node;
|
|
1084
|
+
andOp(other) {
|
|
1085
|
+
return new LogicalOperation(this, "AND" /* AND */, other);
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
var RelatedFinder = class {
|
|
1089
|
+
constructor(_node) {
|
|
1090
|
+
this._node = _node;
|
|
1091
|
+
}
|
|
1092
|
+
_node;
|
|
1093
|
+
exists() {
|
|
1094
|
+
return new ExistsOperation(this._node);
|
|
1095
|
+
}
|
|
1096
|
+
notExists() {
|
|
1097
|
+
return new NotExistsOperation(this._node);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
// src/datafinder/sql-generator.ts
|
|
1102
|
+
var Alias = class {
|
|
1103
|
+
constructor(element, name) {
|
|
1104
|
+
this.element = element;
|
|
1105
|
+
this.name = name;
|
|
1106
|
+
}
|
|
1107
|
+
element;
|
|
1108
|
+
name;
|
|
1109
|
+
};
|
|
1110
|
+
var TableAlias = class {
|
|
1111
|
+
constructor(table, alias) {
|
|
1112
|
+
this.table = table;
|
|
1113
|
+
this.alias = alias;
|
|
1114
|
+
}
|
|
1115
|
+
table;
|
|
1116
|
+
alias;
|
|
1117
|
+
};
|
|
1118
|
+
var TableAliasColumn = class extends RelationalOperationElement {
|
|
1119
|
+
constructor(column, tableAlias) {
|
|
1120
|
+
super();
|
|
1121
|
+
this.column = column;
|
|
1122
|
+
this.tableAlias = tableAlias;
|
|
1123
|
+
}
|
|
1124
|
+
column;
|
|
1125
|
+
tableAlias;
|
|
1126
|
+
};
|
|
1127
|
+
var Join = class {
|
|
1128
|
+
constructor(source, target, filterOp) {
|
|
1129
|
+
this.source = source;
|
|
1130
|
+
this.target = target;
|
|
1131
|
+
this.filterOp = filterOp;
|
|
1132
|
+
}
|
|
1133
|
+
source;
|
|
1134
|
+
target;
|
|
1135
|
+
filterOp;
|
|
1136
|
+
};
|
|
1137
|
+
var SelectOperation = class {
|
|
1138
|
+
constructor(display, filter, orderBy = [], groupBy = [], limit, table) {
|
|
1139
|
+
this.display = display;
|
|
1140
|
+
this.filter = filter;
|
|
1141
|
+
this.orderBy = orderBy;
|
|
1142
|
+
this.groupBy = groupBy;
|
|
1143
|
+
this.limit = limit;
|
|
1144
|
+
this.table = table;
|
|
1145
|
+
}
|
|
1146
|
+
display;
|
|
1147
|
+
filter;
|
|
1148
|
+
orderBy;
|
|
1149
|
+
groupBy;
|
|
1150
|
+
limit;
|
|
1151
|
+
table;
|
|
1152
|
+
};
|
|
1153
|
+
function sqlFormatDatetime(value) {
|
|
1154
|
+
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
1155
|
+
return `'${value.getUTCFullYear()}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())} ${pad(value.getUTCHours())}:${pad(value.getUTCMinutes())}:${pad(value.getUTCSeconds())}'`;
|
|
1156
|
+
}
|
|
1157
|
+
function sqlFormatDate(value) {
|
|
1158
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
1159
|
+
return `'${value.getUTCFullYear()}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())}'`;
|
|
1160
|
+
}
|
|
1161
|
+
var LOGICAL_OPERATOR_STR = {
|
|
1162
|
+
["AND" /* AND */]: " AND ",
|
|
1163
|
+
["OR" /* OR */]: " OR "
|
|
1164
|
+
};
|
|
1165
|
+
var COMPARISON_OPERATOR_STR = {
|
|
1166
|
+
["EQUAL" /* EQUAL */]: " = ",
|
|
1167
|
+
["NOT_EQUAL" /* NOT_EQUAL */]: " <> ",
|
|
1168
|
+
["LESS_THAN" /* LESS_THAN */]: " < ",
|
|
1169
|
+
["GREATER_THAN" /* GREATER_THAN */]: " > ",
|
|
1170
|
+
["LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */]: " <= ",
|
|
1171
|
+
["GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */]: " >= ",
|
|
1172
|
+
["LIKE" /* LIKE */]: " LIKE ",
|
|
1173
|
+
["NOT_LIKE" /* NOT_LIKE */]: " NOT LIKE "
|
|
1174
|
+
};
|
|
1175
|
+
var AGGREGATE_SQL_NAMES = {
|
|
1176
|
+
["AVERAGE" /* AVERAGE */]: "AVG"
|
|
1177
|
+
};
|
|
1178
|
+
var WINDOW_SQL_NAMES = {
|
|
1179
|
+
["ROW_NUMBER" /* ROW_NUMBER */]: "ROW_NUMBER",
|
|
1180
|
+
["RANK" /* RANK */]: "RANK",
|
|
1181
|
+
["DENSE_RANK" /* DENSE_RANK */]: "DENSE_RANK",
|
|
1182
|
+
["NTILE" /* NTILE */]: "NTILE",
|
|
1183
|
+
["LAG" /* LAG */]: "LAG",
|
|
1184
|
+
["LEAD" /* LEAD */]: "LEAD",
|
|
1185
|
+
["FIRST_VALUE" /* FIRST_VALUE */]: "FIRST_VALUE",
|
|
1186
|
+
["LAST_VALUE" /* LAST_VALUE */]: "LAST_VALUE",
|
|
1187
|
+
["CUME_DIST" /* CUME_DIST */]: "CUME_DIST",
|
|
1188
|
+
["PERCENT_RANK" /* PERCENT_RANK */]: "PERCENT_RANK"
|
|
1189
|
+
};
|
|
1190
|
+
var SCALAR_SQL_NAMES = {
|
|
1191
|
+
["ABS" /* ABS */]: "ABS",
|
|
1192
|
+
["CEILING" /* CEILING */]: "CEILING",
|
|
1193
|
+
["FLOOR" /* FLOOR */]: "FLOOR",
|
|
1194
|
+
["MOD" /* MOD */]: "MOD",
|
|
1195
|
+
["POWER" /* POWER */]: "POWER",
|
|
1196
|
+
["SQRT" /* SQRT */]: "SQRT",
|
|
1197
|
+
["ROUND" /* ROUND */]: "ROUND",
|
|
1198
|
+
["UPPER" /* UPPER */]: "UPPER",
|
|
1199
|
+
["LOWER" /* LOWER */]: "LOWER",
|
|
1200
|
+
["TRIM" /* TRIM */]: "TRIM",
|
|
1201
|
+
["LTRIM" /* LTRIM */]: "LTRIM",
|
|
1202
|
+
["RTRIM" /* RTRIM */]: "RTRIM",
|
|
1203
|
+
["LENGTH" /* LENGTH */]: "LENGTH",
|
|
1204
|
+
["REVERSE" /* REVERSE */]: "REVERSE",
|
|
1205
|
+
["LEFT" /* LEFT */]: "LEFT",
|
|
1206
|
+
["RIGHT" /* RIGHT */]: "RIGHT",
|
|
1207
|
+
["REPEAT" /* REPEAT */]: "REPEAT",
|
|
1208
|
+
["REPLACE" /* REPLACE */]: "REPLACE",
|
|
1209
|
+
["SUBSTRING" /* SUBSTRING */]: "SUBSTRING"
|
|
1210
|
+
};
|
|
1211
|
+
function constantValueString(op) {
|
|
1212
|
+
if (op instanceof StringConstantOperation) return "'" + op.value + "'";
|
|
1213
|
+
if (op instanceof DateConstantOperation) return sqlFormatDate(op.value);
|
|
1214
|
+
if (op instanceof DateTimeConstantOperation) return sqlFormatDatetime(op.value);
|
|
1215
|
+
if (op instanceof IntegerConstantOperation) return String(op.value);
|
|
1216
|
+
if (op instanceof FloatConstantOperation) return String(op.value);
|
|
1217
|
+
if (op instanceof BooleanConstantOperation) return op.value ? "TRUE" : "FALSE";
|
|
1218
|
+
if (op instanceof DecimalConstantOperation) return String(op.value);
|
|
1219
|
+
throw new Error("Unknown constant operation");
|
|
1220
|
+
}
|
|
1221
|
+
function windowSpecToString(window) {
|
|
1222
|
+
const parts = [];
|
|
1223
|
+
if (window.partitionBy.length > 0) {
|
|
1224
|
+
parts.push("PARTITION BY " + window.partitionBy.map((p) => sqlOperationToString(p)).join(", "));
|
|
1225
|
+
}
|
|
1226
|
+
if (window.orderBy.length > 0) {
|
|
1227
|
+
parts.push("ORDER BY " + window.orderBy.map(
|
|
1228
|
+
(s) => sqlOperationToString(s.column) + (s.direction === "ASC" /* ASC */ ? " ASC" : " DESC")
|
|
1229
|
+
).join(", "));
|
|
1230
|
+
}
|
|
1231
|
+
return "OVER (" + parts.join(" ") + ")";
|
|
1232
|
+
}
|
|
1233
|
+
function sqlOperationToString(operation) {
|
|
1234
|
+
if (operation instanceof TableAliasColumn) {
|
|
1235
|
+
return operation.tableAlias.alias + "." + operation.column.name;
|
|
1236
|
+
}
|
|
1237
|
+
if (operation instanceof WindowFunctionOperation) {
|
|
1238
|
+
const fn = WINDOW_SQL_NAMES[operation.func];
|
|
1239
|
+
const parts = [];
|
|
1240
|
+
if (operation.element !== null && operation.element !== void 0) {
|
|
1241
|
+
parts.push(sqlOperationToString(operation.element));
|
|
1242
|
+
}
|
|
1243
|
+
if (operation.secondArg !== void 0) parts.push(String(operation.secondArg));
|
|
1244
|
+
for (const arg of operation.extraArgs) {
|
|
1245
|
+
parts.push(typeof arg === "string" ? "'" + arg + "'" : String(arg));
|
|
1246
|
+
}
|
|
1247
|
+
const sql = fn + "(" + parts.join(", ") + ")";
|
|
1248
|
+
return sql + (operation.window !== void 0 ? " " + windowSpecToString(operation.window) : " OVER ()");
|
|
1249
|
+
}
|
|
1250
|
+
if (operation instanceof AggregateOperation) {
|
|
1251
|
+
const fn = AGGREGATE_SQL_NAMES[operation.operator] ?? operation.operator;
|
|
1252
|
+
let sql = fn + "(" + sqlOperationToString(operation.element) + ")";
|
|
1253
|
+
if (operation.window !== void 0) {
|
|
1254
|
+
sql += " " + windowSpecToString(operation.window);
|
|
1255
|
+
}
|
|
1256
|
+
return sql;
|
|
1257
|
+
}
|
|
1258
|
+
if (operation instanceof ScalarFunctionOperation) {
|
|
1259
|
+
const fn = SCALAR_SQL_NAMES[operation.func];
|
|
1260
|
+
const parts = [sqlOperationToString(operation.element)];
|
|
1261
|
+
if (operation.secondArg !== void 0) parts.push(String(operation.secondArg));
|
|
1262
|
+
for (const arg of operation.extraArgs) {
|
|
1263
|
+
parts.push(typeof arg === "string" ? "'" + arg + "'" : String(arg));
|
|
1264
|
+
}
|
|
1265
|
+
return fn + "(" + parts.join(", ") + ")";
|
|
1266
|
+
}
|
|
1267
|
+
if (operation instanceof DateExtractOperation) {
|
|
1268
|
+
return "EXTRACT(" + operation.part + " FROM " + sqlOperationToString(operation.element) + ")";
|
|
1269
|
+
}
|
|
1270
|
+
if (operation instanceof DateArithmeticOperation) {
|
|
1271
|
+
const op = operation.isAdd ? "+" : "-";
|
|
1272
|
+
return sqlOperationToString(operation.element) + " " + op + " INTERVAL " + operation.n + " " + operation.unit;
|
|
1273
|
+
}
|
|
1274
|
+
if (operation instanceof DateDiffOperation) {
|
|
1275
|
+
const otherSql = sqlFormatDatetime(operation.other);
|
|
1276
|
+
return "DATE_DIFF('" + operation.unit.toLowerCase() + "', " + sqlOperationToString(operation.element) + ", " + otherSql + ")";
|
|
1277
|
+
}
|
|
1278
|
+
if (operation instanceof CountAllOperation) return "COUNT(*)";
|
|
1279
|
+
if (operation instanceof Alias) {
|
|
1280
|
+
return sqlOperationToString(operation.element) + ' AS "' + operation.name + '"';
|
|
1281
|
+
}
|
|
1282
|
+
throw new TypeError("Unknown operation in sqlOperationToString: " + operation.constructor.name);
|
|
1283
|
+
}
|
|
1284
|
+
function findColumn(operation) {
|
|
1285
|
+
if (operation instanceof UnaryOperation) return findColumn(operation.element);
|
|
1286
|
+
if (operation instanceof ColumnWithJoin) return operation;
|
|
1287
|
+
throw new TypeError("Cannot find ColumnWithJoin in: " + operation.constructor.name);
|
|
1288
|
+
}
|
|
1289
|
+
function openEndClause(endAttr, value, infiniteDatetime) {
|
|
1290
|
+
const gtOp = endAttr instanceof DateTimeAttribute ? endAttr.gt(value) : endAttr.gt(value);
|
|
1291
|
+
if (infiniteDatetime === void 0) {
|
|
1292
|
+
const colRef = new ColumnWithJoin(endAttr.column(), endAttr.parent());
|
|
1293
|
+
return new LogicalOperation(gtOp, "OR" /* OR */, new IsNullOperation(colRef));
|
|
1294
|
+
}
|
|
1295
|
+
return gtOp;
|
|
1296
|
+
}
|
|
1297
|
+
function buildMilestoningFilterOperation(businessDate, processingDatetime, table, joinNode) {
|
|
1298
|
+
const mc = table.milestoningColumns;
|
|
1299
|
+
const ops = [];
|
|
1300
|
+
if (mc instanceof BiTemporalColumns) {
|
|
1301
|
+
if (businessDate !== null) {
|
|
1302
|
+
const dateFrom = new DateAttribute("business_date_from", mc.businessDateFromColumn.name, mc.businessDateFromColumn.type, mc.businessDateFromColumn.table.qualifiedName, joinNode);
|
|
1303
|
+
const dateTo = new DateAttribute("business_date_to", mc.businessDateToColumn.name, mc.businessDateToColumn.type, mc.businessDateToColumn.table.qualifiedName, joinNode);
|
|
1304
|
+
ops.push(new LogicalOperation(dateFrom.lte(businessDate), "AND" /* AND */, openEndClause(dateTo, businessDate, mc.infiniteDatetime)));
|
|
1305
|
+
}
|
|
1306
|
+
if (processingDatetime !== null) {
|
|
1307
|
+
const startAt = new DateTimeAttribute("start_at", mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table.qualifiedName, joinNode);
|
|
1308
|
+
const endAt = new DateTimeAttribute("end_at", mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table.qualifiedName, joinNode);
|
|
1309
|
+
ops.push(new LogicalOperation(startAt.lte(processingDatetime), "AND" /* AND */, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));
|
|
1310
|
+
}
|
|
1311
|
+
} else if (mc instanceof BusinessDateAndProcessingTemporalColumns) {
|
|
1312
|
+
if (businessDate !== null) {
|
|
1313
|
+
const businessAtt = new DateAttribute("business_date", mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table.qualifiedName, joinNode);
|
|
1314
|
+
ops.push(businessAtt.eq(businessDate));
|
|
1315
|
+
}
|
|
1316
|
+
if (processingDatetime !== null) {
|
|
1317
|
+
const startAt = new DateTimeAttribute("start_at", mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table.qualifiedName, joinNode);
|
|
1318
|
+
const endAt = new DateTimeAttribute("end_at", mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table.qualifiedName, joinNode);
|
|
1319
|
+
ops.push(new LogicalOperation(startAt.lte(processingDatetime), "AND" /* AND */, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));
|
|
1320
|
+
}
|
|
1321
|
+
} else if (mc instanceof ProcessingTemporalColumns && processingDatetime !== null) {
|
|
1322
|
+
const startAt = new DateTimeAttribute("start_at", mc.startAtColumn.name, mc.startAtColumn.type, mc.startAtColumn.table.qualifiedName, joinNode);
|
|
1323
|
+
const endAt = new DateTimeAttribute("end_at", mc.endAtColumn.name, mc.endAtColumn.type, mc.endAtColumn.table.qualifiedName, joinNode);
|
|
1324
|
+
ops.push(new LogicalOperation(startAt.lte(processingDatetime), "AND" /* AND */, openEndClause(endAt, processingDatetime, mc.infiniteDatetime)));
|
|
1325
|
+
} else if (mc instanceof SingleBusinessDateColumn && businessDate !== null) {
|
|
1326
|
+
const businessAtt = new DateAttribute("business_date", mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table.qualifiedName, joinNode);
|
|
1327
|
+
ops.push(businessAtt.eq(businessDate));
|
|
1328
|
+
}
|
|
1329
|
+
if (ops.length === 0) return null;
|
|
1330
|
+
if (ops.length === 1) return ops[0];
|
|
1331
|
+
return new LogicalOperation(ops[0], "AND" /* AND */, ops[1]);
|
|
1332
|
+
}
|
|
1333
|
+
function buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit) {
|
|
1334
|
+
let filter = op;
|
|
1335
|
+
if (table instanceof MilestonedTable) {
|
|
1336
|
+
const milestonedOp = buildMilestoningFilterOperation(businessDate, processingDatetime, table);
|
|
1337
|
+
if (milestonedOp !== null) {
|
|
1338
|
+
filter = filter instanceof NoOperation ? milestonedOp : new LogicalOperation(filter, "AND" /* AND */, milestonedOp);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const requiredJoins = [];
|
|
1342
|
+
const requiredJoinIds = /* @__PURE__ */ new Set();
|
|
1343
|
+
for (const col of columns) {
|
|
1344
|
+
if (col instanceof CountAllOperation) continue;
|
|
1345
|
+
let node;
|
|
1346
|
+
if (col instanceof Attribute) {
|
|
1347
|
+
node = col.parent();
|
|
1348
|
+
} else {
|
|
1349
|
+
node = findColumn(col).parent;
|
|
1350
|
+
}
|
|
1351
|
+
if (node !== void 0 && !requiredJoinIds.has(node)) {
|
|
1352
|
+
requiredJoinIds.add(node);
|
|
1353
|
+
requiredJoins.push(node);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
for (const node of requiredJoins) {
|
|
1357
|
+
if (node.join.target instanceof MilestonedTable) {
|
|
1358
|
+
const milestonedOp = buildMilestoningFilterOperation(businessDate, processingDatetime, node.join.target, node);
|
|
1359
|
+
if (milestonedOp !== null) {
|
|
1360
|
+
node.join.filter = milestonedOp;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return new SelectOperation(columns, filter, orderBy, groupBy, limit, table);
|
|
1365
|
+
}
|
|
1366
|
+
var SQLQueryGenerator = class {
|
|
1367
|
+
_select = [];
|
|
1368
|
+
_from = /* @__PURE__ */ new Set();
|
|
1369
|
+
_join = [];
|
|
1370
|
+
_groupByParts = [];
|
|
1371
|
+
_orderByParts = [];
|
|
1372
|
+
_where = "";
|
|
1373
|
+
_limit;
|
|
1374
|
+
_tableAliasIncr = 0;
|
|
1375
|
+
_tableAliasesByTable = /* @__PURE__ */ new Map();
|
|
1376
|
+
_addedJoinIds = /* @__PURE__ */ new Set();
|
|
1377
|
+
_rootTable;
|
|
1378
|
+
generate(select) {
|
|
1379
|
+
this._rootTable = select.table;
|
|
1380
|
+
if (this._rootTable !== void 0) {
|
|
1381
|
+
this._from.add(this._tableAliasForTable(this._rootTable.qualifiedName, this._rootTable.qualifiedName));
|
|
1382
|
+
}
|
|
1383
|
+
this.processSelect(select.display);
|
|
1384
|
+
this._where = this.buildFilter(select.filter);
|
|
1385
|
+
const groupByJoins = /* @__PURE__ */ new Map();
|
|
1386
|
+
for (const expr of select.groupBy) {
|
|
1387
|
+
this._collectRequiredJoins(expr, groupByJoins);
|
|
1388
|
+
}
|
|
1389
|
+
for (const node of groupByJoins.values()) {
|
|
1390
|
+
this._addJoin(node);
|
|
1391
|
+
}
|
|
1392
|
+
this._groupByParts = select.groupBy.map((a) => this._attrToColString(a));
|
|
1393
|
+
this._orderByParts = select.orderBy.map(
|
|
1394
|
+
(s) => this.buildFilter(s.column) + (s.direction === "ASC" /* ASC */ ? " ASC" : " DESC")
|
|
1395
|
+
);
|
|
1396
|
+
this._limit = select.limit;
|
|
1397
|
+
}
|
|
1398
|
+
_attrToColString(attr) {
|
|
1399
|
+
const node = attr.parent();
|
|
1400
|
+
const ta = this._tableAliasForTable(attr.owner(), node ?? attr.owner());
|
|
1401
|
+
return ta.alias + "." + attr.column().name;
|
|
1402
|
+
}
|
|
1403
|
+
_collectRequiredJoins(op, out) {
|
|
1404
|
+
if (op === null || op === void 0) return;
|
|
1405
|
+
if (op instanceof Attribute) {
|
|
1406
|
+
const p = op.parent();
|
|
1407
|
+
if (p !== void 0) out.set(p, p);
|
|
1408
|
+
} else if (op instanceof ColumnWithJoin) {
|
|
1409
|
+
if (op.parent !== void 0) out.set(op.parent, op.parent);
|
|
1410
|
+
} else if (op instanceof AggregateOperation) {
|
|
1411
|
+
this._collectRequiredJoins(op.element, out);
|
|
1412
|
+
if (op.window) this._collectRequiredJoins(op.window, out);
|
|
1413
|
+
} else if (op instanceof WindowFunctionOperation) {
|
|
1414
|
+
if (op.element) this._collectRequiredJoins(op.element, out);
|
|
1415
|
+
if (op.window) this._collectRequiredJoinsFromWindowSpec(op.window, out);
|
|
1416
|
+
} else if (op instanceof ScalarFunctionOperation || op instanceof DateExtractOperation || op instanceof DateArithmeticOperation || op instanceof DateDiffOperation) {
|
|
1417
|
+
this._collectRequiredJoins(op.element, out);
|
|
1418
|
+
} else if (op instanceof SortOperation) {
|
|
1419
|
+
this._collectRequiredJoins(op.column, out);
|
|
1420
|
+
} else if (op instanceof LogicalOperation || op instanceof ComparisonOperation) {
|
|
1421
|
+
this._collectRequiredJoins(op.left, out);
|
|
1422
|
+
this._collectRequiredJoins(op.right, out);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
_collectRequiredJoinsFromWindowSpec(window, out) {
|
|
1426
|
+
for (const p of window.partitionBy) {
|
|
1427
|
+
this._collectRequiredJoins(p, out);
|
|
1428
|
+
}
|
|
1429
|
+
for (const s of window.orderBy) {
|
|
1430
|
+
this._collectRequiredJoins(s.column, out);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
_rewriteWindowSpec(window) {
|
|
1434
|
+
const partitionBy = window.partitionBy.map((p) => this._rewriteOperation(p));
|
|
1435
|
+
const orderBy = window.orderBy.map((s) => new SortOperation(this._rewriteOperation(s.column), s.direction));
|
|
1436
|
+
return new WindowSpecification(partitionBy, orderBy);
|
|
1437
|
+
}
|
|
1438
|
+
_rewriteOperation(op) {
|
|
1439
|
+
if (op instanceof Attribute) {
|
|
1440
|
+
const ta = this._tableAliasForTable(op.owner(), op.parent() ?? op.owner());
|
|
1441
|
+
return new TableAliasColumn(op.column(), ta);
|
|
1442
|
+
}
|
|
1443
|
+
if (op instanceof ColumnWithJoin) {
|
|
1444
|
+
const ta = op.parent !== void 0 ? this._tableAliasForTable(op.column.owner, op.parent) : this._tableAliasForTable(op.column.owner, op.column.owner);
|
|
1445
|
+
return new TableAliasColumn(op.column, ta);
|
|
1446
|
+
}
|
|
1447
|
+
if (op instanceof Column) {
|
|
1448
|
+
const ta = this._tableAliasForTable(op.owner, op.owner);
|
|
1449
|
+
return new TableAliasColumn(op, ta);
|
|
1450
|
+
}
|
|
1451
|
+
if (op instanceof AggregateOperation) {
|
|
1452
|
+
return new AggregateOperation(
|
|
1453
|
+
this._rewriteOperation(op.element),
|
|
1454
|
+
op.operator,
|
|
1455
|
+
op.displayName,
|
|
1456
|
+
op.window ? this._rewriteWindowSpec(op.window) : void 0
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
if (op instanceof WindowFunctionOperation) {
|
|
1460
|
+
const el = op.element ? this._rewriteOperation(op.element) : null;
|
|
1461
|
+
return new WindowFunctionOperation(
|
|
1462
|
+
el,
|
|
1463
|
+
op.func,
|
|
1464
|
+
op.displayName,
|
|
1465
|
+
op.secondArg,
|
|
1466
|
+
[...op.extraArgs],
|
|
1467
|
+
op.window ? this._rewriteWindowSpec(op.window) : void 0
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
if (op instanceof ScalarFunctionOperation) {
|
|
1471
|
+
return new ScalarFunctionOperation(this._rewriteOperation(op.element), op.func, op.displayName, op.secondArg, op.extraArgs);
|
|
1472
|
+
}
|
|
1473
|
+
if (op instanceof DateExtractOperation) {
|
|
1474
|
+
return new DateExtractOperation(this._rewriteOperation(op.element), op.part, op.displayName);
|
|
1475
|
+
}
|
|
1476
|
+
if (op instanceof DateArithmeticOperation) {
|
|
1477
|
+
return new DateArithmeticOperation(this._rewriteOperation(op.element), op.n, op.unit, op.isAdd, op.displayName);
|
|
1478
|
+
}
|
|
1479
|
+
if (op instanceof DateDiffOperation) {
|
|
1480
|
+
return new DateDiffOperation(this._rewriteOperation(op.element), op.other, op.unit, op.displayName);
|
|
1481
|
+
}
|
|
1482
|
+
return op;
|
|
1483
|
+
}
|
|
1484
|
+
processSelect(cols) {
|
|
1485
|
+
const requiredJoins = /* @__PURE__ */ new Map();
|
|
1486
|
+
for (const col of cols) {
|
|
1487
|
+
this._collectRequiredJoins(col, requiredJoins);
|
|
1488
|
+
}
|
|
1489
|
+
for (const node of requiredJoins.values()) {
|
|
1490
|
+
this._addJoin(node);
|
|
1491
|
+
}
|
|
1492
|
+
for (const col of cols) {
|
|
1493
|
+
if (col instanceof Attribute) {
|
|
1494
|
+
const node = col.parent();
|
|
1495
|
+
let ta;
|
|
1496
|
+
if (node !== void 0) {
|
|
1497
|
+
ta = this._tableAliasForTable(col.owner(), node);
|
|
1498
|
+
} else {
|
|
1499
|
+
ta = this._tableAliasForTable(col.owner(), col.owner());
|
|
1500
|
+
this._from.add(ta);
|
|
1501
|
+
}
|
|
1502
|
+
this._select.push(new Alias(new TableAliasColumn(col.column(), ta), col.displayName()));
|
|
1503
|
+
} else if (col instanceof WindowFunctionOperation) {
|
|
1504
|
+
const rewritten = this._rewriteOperation(col);
|
|
1505
|
+
let alias;
|
|
1506
|
+
if (col.displayName) {
|
|
1507
|
+
alias = col.displayName;
|
|
1508
|
+
} else if (["ROW_NUMBER" /* ROW_NUMBER */, "RANK" /* RANK */, "DENSE_RANK" /* DENSE_RANK */].includes(col.func)) {
|
|
1509
|
+
alias = col.func.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
1510
|
+
} else if (col.element) {
|
|
1511
|
+
alias = col.func + " " + findColumn(col).column.name;
|
|
1512
|
+
} else {
|
|
1513
|
+
alias = col.func;
|
|
1514
|
+
}
|
|
1515
|
+
this._select.push(new Alias(rewritten, alias));
|
|
1516
|
+
} else if (col instanceof AggregateOperation) {
|
|
1517
|
+
const colNested = findColumn(col);
|
|
1518
|
+
const node = colNested.parent;
|
|
1519
|
+
let ta;
|
|
1520
|
+
if (node !== void 0) {
|
|
1521
|
+
ta = this._tableAliasForTable(colNested.column.owner, node);
|
|
1522
|
+
} else {
|
|
1523
|
+
ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
|
|
1524
|
+
this._from.add(ta);
|
|
1525
|
+
}
|
|
1526
|
+
const alias = col.displayName ?? col.operator + " " + colNested.column.name;
|
|
1527
|
+
const rewrittenAgg = new AggregateOperation(
|
|
1528
|
+
new TableAliasColumn(colNested.column, ta),
|
|
1529
|
+
col.operator,
|
|
1530
|
+
void 0,
|
|
1531
|
+
col.window ? this._rewriteWindowSpec(col.window) : void 0
|
|
1532
|
+
);
|
|
1533
|
+
this._select.push(new Alias(rewrittenAgg, alias));
|
|
1534
|
+
} else if (col instanceof ScalarFunctionOperation) {
|
|
1535
|
+
const colNested = findColumn(col);
|
|
1536
|
+
const node = colNested.parent;
|
|
1537
|
+
let ta;
|
|
1538
|
+
if (node !== void 0) {
|
|
1539
|
+
ta = this._tableAliasForTable(colNested.column.owner, node);
|
|
1540
|
+
} else {
|
|
1541
|
+
ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
|
|
1542
|
+
this._from.add(ta);
|
|
1543
|
+
}
|
|
1544
|
+
const alias = col.displayName ?? col.func + " " + colNested.column.name;
|
|
1545
|
+
this._select.push(new Alias(
|
|
1546
|
+
new ScalarFunctionOperation(new TableAliasColumn(colNested.column, ta), col.func, void 0, col.secondArg, col.extraArgs),
|
|
1547
|
+
alias
|
|
1548
|
+
));
|
|
1549
|
+
} else if (col instanceof DateExtractOperation || col instanceof DateArithmeticOperation || col instanceof DateDiffOperation) {
|
|
1550
|
+
const colNested = findColumn(col);
|
|
1551
|
+
const node = colNested.parent;
|
|
1552
|
+
let ta;
|
|
1553
|
+
if (node !== void 0) {
|
|
1554
|
+
ta = this._tableAliasForTable(colNested.column.owner, node);
|
|
1555
|
+
} else {
|
|
1556
|
+
ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
|
|
1557
|
+
this._from.add(ta);
|
|
1558
|
+
}
|
|
1559
|
+
const alias = col.displayName ?? colNested.column.name;
|
|
1560
|
+
let aliasedOp;
|
|
1561
|
+
if (col instanceof DateExtractOperation) {
|
|
1562
|
+
aliasedOp = new DateExtractOperation(new TableAliasColumn(colNested.column, ta), col.part);
|
|
1563
|
+
} else if (col instanceof DateArithmeticOperation) {
|
|
1564
|
+
aliasedOp = new DateArithmeticOperation(new TableAliasColumn(colNested.column, ta), col.n, col.unit, col.isAdd);
|
|
1565
|
+
} else {
|
|
1566
|
+
aliasedOp = new DateDiffOperation(new TableAliasColumn(colNested.column, ta), col.other, col.unit);
|
|
1567
|
+
}
|
|
1568
|
+
this._select.push(new Alias(aliasedOp, alias));
|
|
1569
|
+
} else if (col instanceof CountAllOperation) {
|
|
1570
|
+
const ta = this._tableAliasForTable(col.table, col.table);
|
|
1571
|
+
this._from.add(ta);
|
|
1572
|
+
this._select.push(new Alias(col, "Count"));
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
_addJoin(node) {
|
|
1577
|
+
if (this._addedJoinIds.has(node)) return;
|
|
1578
|
+
if (node.parent !== void 0) this._addJoin(node.parent);
|
|
1579
|
+
this._addedJoinIds.add(node);
|
|
1580
|
+
const join = node.join;
|
|
1581
|
+
const left = join.left;
|
|
1582
|
+
const srcTa = this._tableAliasForTable(left.owner, node.parent ?? left.owner);
|
|
1583
|
+
if (node.parent === void 0) this._from.add(srcTa);
|
|
1584
|
+
const sc = new TableAliasColumn(left, srcTa);
|
|
1585
|
+
const right = join.right;
|
|
1586
|
+
const tc = new TableAliasColumn(right, this._tableAliasForTable(right.owner, node));
|
|
1587
|
+
this._join.push(new Join(sc, tc, join.filter));
|
|
1588
|
+
}
|
|
1589
|
+
buildFilter(op) {
|
|
1590
|
+
if (op instanceof NoOperation) return "";
|
|
1591
|
+
if (op instanceof ExistsOperation) {
|
|
1592
|
+
const col = op.node.join.right;
|
|
1593
|
+
return this.buildFilter(new ColumnWithJoin(col, op.node)) + " IS NOT NULL";
|
|
1594
|
+
}
|
|
1595
|
+
if (op instanceof NotExistsOperation) {
|
|
1596
|
+
const col = op.node.join.right;
|
|
1597
|
+
return this.buildFilter(new ColumnWithJoin(col, op.node)) + " IS NULL";
|
|
1598
|
+
}
|
|
1599
|
+
if (op instanceof IsNotNullOperation) return this.buildFilter(op.element) + " IS NOT NULL";
|
|
1600
|
+
if (op instanceof IsNullOperation) return this.buildFilter(op.element) + " IS NULL";
|
|
1601
|
+
if (op instanceof LogicalOperation) {
|
|
1602
|
+
let left = this.buildFilter(op.left);
|
|
1603
|
+
let right = this.buildFilter(op.right);
|
|
1604
|
+
if (op.left instanceof LogicalOperation) left = "(" + left + ")";
|
|
1605
|
+
if (op.right instanceof LogicalOperation) right = "(" + right + ")";
|
|
1606
|
+
return left + LOGICAL_OPERATOR_STR[op.operator] + right;
|
|
1607
|
+
}
|
|
1608
|
+
if (op instanceof ComparisonOperation) {
|
|
1609
|
+
return this.buildFilter(op.left) + COMPARISON_OPERATOR_STR[op.operator] + this.buildFilter(op.right);
|
|
1610
|
+
}
|
|
1611
|
+
if (op instanceof ConstantOperation) return constantValueString(op);
|
|
1612
|
+
if (op instanceof ColumnWithJoin) {
|
|
1613
|
+
const node = op.parent;
|
|
1614
|
+
let ta;
|
|
1615
|
+
if (node !== void 0) {
|
|
1616
|
+
ta = this._tableAliasForTable(op.column.owner, node);
|
|
1617
|
+
this._addJoin(node);
|
|
1618
|
+
} else {
|
|
1619
|
+
ta = this._tableAliasForTable(op.column.owner, op.column.owner);
|
|
1620
|
+
}
|
|
1621
|
+
return ta.alias + "." + op.column.name;
|
|
1622
|
+
}
|
|
1623
|
+
if (op instanceof Column) {
|
|
1624
|
+
const ta = this._tableAliasForTable(op.owner, op.owner);
|
|
1625
|
+
return ta.alias + "." + op.name;
|
|
1626
|
+
}
|
|
1627
|
+
throw new Error("Unknown operation in buildFilter: " + op.constructor.name);
|
|
1628
|
+
}
|
|
1629
|
+
_tableAliasForTable(table, key) {
|
|
1630
|
+
if (this._tableAliasesByTable.has(key)) {
|
|
1631
|
+
return this._tableAliasesByTable.get(key);
|
|
1632
|
+
}
|
|
1633
|
+
const ta = new TableAlias(table, "t" + this._tableAliasIncr++);
|
|
1634
|
+
this._tableAliasesByTable.set(key, ta);
|
|
1635
|
+
return ta;
|
|
1636
|
+
}
|
|
1637
|
+
buildQueryString() {
|
|
1638
|
+
const joins = this._join.map(
|
|
1639
|
+
(j) => " LEFT OUTER JOIN " + j.target.tableAlias.table + " AS " + j.target.tableAlias.alias + " ON " + j.source.tableAlias.alias + "." + j.source.column.name + " = " + j.target.tableAlias.alias + "." + j.target.column.name + (j.filterOp ? " AND " + this.buildFilter(j.filterOp) : "")
|
|
1640
|
+
);
|
|
1641
|
+
return "SELECT " + this._select.map((ca) => sqlOperationToString(ca)).join(",") + " FROM " + Array.from(this._from).map((ta) => ta.table + " AS " + ta.alias).join(",") + joins.join("") + this._buildWhere() + this._buildGroupBy() + this._buildOrderBy() + this._buildLimit();
|
|
1642
|
+
}
|
|
1643
|
+
_buildWhere() {
|
|
1644
|
+
return this._where.length > 0 ? " WHERE " + this._where : "";
|
|
1645
|
+
}
|
|
1646
|
+
_buildGroupBy() {
|
|
1647
|
+
return this._groupByParts.length > 0 ? " GROUP BY " + this._groupByParts.join(", ") : "";
|
|
1648
|
+
}
|
|
1649
|
+
_buildOrderBy() {
|
|
1650
|
+
return this._orderByParts.length > 0 ? " ORDER BY " + this._orderByParts.join(", ") : "";
|
|
1651
|
+
}
|
|
1652
|
+
_buildLimit() {
|
|
1653
|
+
return this._limit !== void 0 ? " LIMIT " + this._limit : "";
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
function selectSqlToString(selectOperation) {
|
|
1657
|
+
const qg = new SQLQueryGenerator();
|
|
1658
|
+
qg.generate(selectOperation);
|
|
1659
|
+
return qg.buildQueryString();
|
|
1660
|
+
}
|
|
1661
|
+
function toSql(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit) {
|
|
1662
|
+
const selectOp = buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy, groupBy, limit);
|
|
1663
|
+
return selectSqlToString(selectOp);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
// src/datafinder/runner.ts
|
|
1667
|
+
var _runner = null;
|
|
1668
|
+
function registerRunner(runner) {
|
|
1669
|
+
_runner = runner;
|
|
1670
|
+
}
|
|
1671
|
+
function clearRunner() {
|
|
1672
|
+
_runner = null;
|
|
1673
|
+
}
|
|
1674
|
+
function getRunner() {
|
|
1675
|
+
if (!_runner) throw new Error("No query runner registered. Call registerRunner() first.");
|
|
1676
|
+
return _runner;
|
|
1677
|
+
}
|
|
1678
|
+
var FinderResult = class {
|
|
1679
|
+
constructor(_businessDate, _processingDatetime, _columns, _table, _op) {
|
|
1680
|
+
this._businessDate = _businessDate;
|
|
1681
|
+
this._processingDatetime = _processingDatetime;
|
|
1682
|
+
this._columns = _columns;
|
|
1683
|
+
this._table = _table;
|
|
1684
|
+
this._op = _op;
|
|
1685
|
+
}
|
|
1686
|
+
_businessDate;
|
|
1687
|
+
_processingDatetime;
|
|
1688
|
+
_columns;
|
|
1689
|
+
_table;
|
|
1690
|
+
_op;
|
|
1691
|
+
_orderBy = [];
|
|
1692
|
+
_groupBy = [];
|
|
1693
|
+
_limit;
|
|
1694
|
+
orderByOp(...sorts) {
|
|
1695
|
+
this._orderBy = sorts;
|
|
1696
|
+
return this;
|
|
1697
|
+
}
|
|
1698
|
+
groupByOp(...attrs) {
|
|
1699
|
+
this._groupBy = attrs;
|
|
1700
|
+
return this;
|
|
1701
|
+
}
|
|
1702
|
+
limit(n) {
|
|
1703
|
+
this._limit = n;
|
|
1704
|
+
return this;
|
|
1705
|
+
}
|
|
1706
|
+
toSql() {
|
|
1707
|
+
return toSql(
|
|
1708
|
+
this._businessDate,
|
|
1709
|
+
this._processingDatetime,
|
|
1710
|
+
this._columns,
|
|
1711
|
+
this._table,
|
|
1712
|
+
this._op,
|
|
1713
|
+
this._orderBy,
|
|
1714
|
+
this._groupBy,
|
|
1715
|
+
this._limit
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
async toRows() {
|
|
1719
|
+
return getRunner().select(
|
|
1720
|
+
this._businessDate,
|
|
1721
|
+
this._processingDatetime,
|
|
1722
|
+
this._columns,
|
|
1723
|
+
this._table,
|
|
1724
|
+
this._op,
|
|
1725
|
+
this._orderBy,
|
|
1726
|
+
this._groupBy,
|
|
1727
|
+
this._limit
|
|
1728
|
+
);
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
function convertDate(value) {
|
|
1732
|
+
if (value === null) return null;
|
|
1733
|
+
if (value instanceof Date) return value;
|
|
1734
|
+
const normalized = /^\d{4}-\d{2}-\d{2}$/.test(value) ? value + "T00:00:00Z" : value;
|
|
1735
|
+
const d = new Date(normalized);
|
|
1736
|
+
if (isNaN(d.getTime())) throw new Error(`Cannot parse date: ${value}`);
|
|
1737
|
+
return d;
|
|
1738
|
+
}
|
|
1739
|
+
function convertInputsAndSelect(businessDate, processingDatetime, columns, table, op = new NoOperation()) {
|
|
1740
|
+
return new FinderResult(
|
|
1741
|
+
convertDate(businessDate),
|
|
1742
|
+
convertDate(processingDatetime),
|
|
1743
|
+
columns,
|
|
1744
|
+
table,
|
|
1745
|
+
op
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1749
|
+
0 && (module.exports = {
|
|
1750
|
+
AggregateOperation,
|
|
1751
|
+
AggregateOperator,
|
|
1752
|
+
Attribute,
|
|
1753
|
+
BiTemporalColumns,
|
|
1754
|
+
BinaryOperation,
|
|
1755
|
+
BooleanAttribute,
|
|
1756
|
+
BooleanConstantOperation,
|
|
1757
|
+
BusinessDateAndProcessingTemporalColumns,
|
|
1758
|
+
Column,
|
|
1759
|
+
ColumnWithJoin,
|
|
1760
|
+
ComparisonOperation,
|
|
1761
|
+
ComparisonOperator,
|
|
1762
|
+
ConstantOperation,
|
|
1763
|
+
CountAllOperation,
|
|
1764
|
+
DataCatalog,
|
|
1765
|
+
DataStore,
|
|
1766
|
+
Database,
|
|
1767
|
+
DateArithmeticOperation,
|
|
1768
|
+
DateAttribute,
|
|
1769
|
+
DateConstantOperation,
|
|
1770
|
+
DateDiffOperation,
|
|
1771
|
+
DateExtractOperation,
|
|
1772
|
+
DatePart,
|
|
1773
|
+
DateTimeAttribute,
|
|
1774
|
+
DateTimeConstantOperation,
|
|
1775
|
+
DecimalAttribute,
|
|
1776
|
+
DecimalConstantOperation,
|
|
1777
|
+
DoubleAttribute,
|
|
1778
|
+
ExistsOperation,
|
|
1779
|
+
FinderResult,
|
|
1780
|
+
FloatAttribute,
|
|
1781
|
+
FloatConstantOperation,
|
|
1782
|
+
ForeignKey,
|
|
1783
|
+
IntegerAttribute,
|
|
1784
|
+
IntegerConstantOperation,
|
|
1785
|
+
IsNotNullOperation,
|
|
1786
|
+
IsNullOperation,
|
|
1787
|
+
JoinOperation,
|
|
1788
|
+
JoinTreeNodeOperation,
|
|
1789
|
+
LogicalOperation,
|
|
1790
|
+
LogicalOperator,
|
|
1791
|
+
MilestonedTable,
|
|
1792
|
+
MilestoningColumns,
|
|
1793
|
+
NoOperation,
|
|
1794
|
+
NotExistsOperation,
|
|
1795
|
+
NumericAttribute,
|
|
1796
|
+
Operation,
|
|
1797
|
+
ProcessingTemporalColumns,
|
|
1798
|
+
RelatedFinder,
|
|
1799
|
+
RelationalOperationElement,
|
|
1800
|
+
ScalarFunction,
|
|
1801
|
+
ScalarFunctionOperation,
|
|
1802
|
+
Schema,
|
|
1803
|
+
SingleBusinessDateColumn,
|
|
1804
|
+
SortDirection,
|
|
1805
|
+
SortOperation,
|
|
1806
|
+
StringAttribute,
|
|
1807
|
+
StringConstantOperation,
|
|
1808
|
+
Table,
|
|
1809
|
+
UnaryOperation,
|
|
1810
|
+
WindowFunction,
|
|
1811
|
+
WindowFunctionOperation,
|
|
1812
|
+
WindowSpecification,
|
|
1813
|
+
clearRunner,
|
|
1814
|
+
convertInputsAndSelect,
|
|
1815
|
+
getRelatedFinderClass,
|
|
1816
|
+
getRunner,
|
|
1817
|
+
registerRelatedFinderClass,
|
|
1818
|
+
registerRunner,
|
|
1819
|
+
selectSqlToString,
|
|
1820
|
+
toSql
|
|
1821
|
+
});
|
|
1822
|
+
//# sourceMappingURL=index.cjs.map
|