@balena/abstract-sql-compiler 10.5.0-build-joshbwlng-date-trunc-456a4a82262ae24000cf4427451b6ef107b876b3-1 → 11.0.0-build-11-x-db9cd30f6ec498e5293df9e060f5531cd960b1cc-1
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/.versionbot/CHANGELOG.yml +28 -7
- package/CHANGELOG.md +4 -2
- package/out/AbstractSQLCompiler.d.ts +6 -5
- package/out/AbstractSQLCompiler.js +45 -57
- package/out/AbstractSQLCompiler.js.map +1 -1
- package/out/AbstractSQLOptimiser.d.ts +1 -1
- package/out/AbstractSQLOptimiser.js +8 -56
- package/out/AbstractSQLOptimiser.js.map +1 -1
- package/out/AbstractSQLRules2SQL.d.ts +2 -2
- package/out/AbstractSQLRules2SQL.js +206 -229
- package/out/AbstractSQLRules2SQL.js.map +1 -1
- package/out/AbstractSQLSchemaOptimiser.d.ts +2 -2
- package/out/AbstractSQLSchemaOptimiser.js +14 -21
- package/out/AbstractSQLSchemaOptimiser.js.map +1 -1
- package/out/referenced-fields.d.ts +1 -1
- package/out/referenced-fields.js +17 -24
- package/out/referenced-fields.js.map +1 -1
- package/package.json +4 -4
- package/src/AbstractSQLCompiler.ts +22 -18
- package/src/AbstractSQLOptimiser.ts +6 -22
- package/src/AbstractSQLRules2SQL.ts +6 -11
- package/src/AbstractSQLSchemaOptimiser.ts +6 -5
- package/src/referenced-fields.ts +4 -4
- package/test/abstract-sql/aggregate-json.ts +1 -1
- package/test/abstract-sql/aggregate.ts +25 -10
- package/test/abstract-sql/and-or-boolean-optimisations.ts +1 -1
- package/test/abstract-sql/case-when-else.ts +5 -2
- package/test/abstract-sql/cast.ts +1 -1
- package/test/abstract-sql/coalesce.ts +1 -1
- package/test/abstract-sql/comparisons.ts +1 -1
- package/test/abstract-sql/dates.ts +10 -27
- package/test/abstract-sql/duration.ts +1 -1
- package/test/abstract-sql/empty-query-optimisations.ts +2 -2
- package/test/abstract-sql/functions_wrapper.ts +1 -1
- package/test/abstract-sql/get-referenced-fields.ts +1 -1
- package/test/abstract-sql/get-rule-referenced-fields.ts +1 -1
- package/test/abstract-sql/insert-query.ts +1 -1
- package/test/abstract-sql/is-distinct.ts +1 -1
- package/test/abstract-sql/joins.ts +1 -1
- package/test/abstract-sql/json.ts +1 -1
- package/test/abstract-sql/math.ts +1 -1
- package/test/abstract-sql/nested-in-optimisations.ts +1 -1
- package/test/abstract-sql/not-not-optimisations.ts +1 -1
- package/test/abstract-sql/schema-checks.ts +1 -1
- package/test/abstract-sql/schema-informative-reference.ts +1 -1
- package/test/abstract-sql/schema-rule-optimization.ts +1 -1
- package/test/abstract-sql/schema-rule-to-check.ts +1 -1
- package/test/abstract-sql/schema-views.ts +37 -2
- package/test/abstract-sql/test.ts +1 -1
- package/test/abstract-sql/text.ts +1 -1
- package/test/odata/expand.ts +3 -3
- package/test/odata/filterby.ts +8 -4
- package/test/odata/orderby.ts +2 -2
- package/test/odata/paging.ts +2 -2
- package/test/odata/resource_parsing.ts +5 -5
- package/test/odata/select.ts +2 -2
- package/test/odata/stress.ts +2 -2
- package/test/odata/test.ts +24 -20
- package/test/sbvr/pilots.ts +3 -3
- package/test/sbvr/reference-type.ts +3 -3
- package/test/sbvr/test.ts +12 -10
@@ -6,24 +6,28 @@ export const enum Engines {
|
|
6
6
|
/* eslint-enable @typescript-eslint/no-shadow */
|
7
7
|
}
|
8
8
|
|
9
|
-
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
|
10
|
-
import type { Binding, SqlResult } from './AbstractSQLRules2SQL';
|
11
|
-
import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL';
|
12
|
-
export { Binding, SqlResult } from './AbstractSQLRules2SQL';
|
9
|
+
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
|
10
|
+
import type { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
|
11
|
+
import { AbstractSQLRules2SQL } from './AbstractSQLRules2SQL.js';
|
12
|
+
export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
|
13
13
|
import type { SbvrType } from '@balena/sbvr-types';
|
14
|
-
import sbvrTypes from '@balena/sbvr-types';
|
15
|
-
|
14
|
+
import $sbvrTypes from '@balena/sbvr-types';
|
15
|
+
const { default: sbvrTypes } = $sbvrTypes;
|
16
|
+
import {
|
17
|
+
optimizeSchema,
|
18
|
+
generateRuleSlug,
|
19
|
+
} from './AbstractSQLSchemaOptimiser.js';
|
16
20
|
import type {
|
17
21
|
ReferencedFields,
|
18
22
|
RuleReferencedFields,
|
19
23
|
ModifiedFields,
|
20
|
-
} from './referenced-fields';
|
24
|
+
} from './referenced-fields.js';
|
21
25
|
import {
|
22
26
|
getReferencedFields,
|
23
27
|
getRuleReferencedFields,
|
24
28
|
getModifiedFields,
|
25
29
|
insertAffectedIdsBinds,
|
26
|
-
} from './referenced-fields';
|
30
|
+
} from './referenced-fields.js';
|
27
31
|
|
28
32
|
export type { ReferencedFields, RuleReferencedFields, ModifiedFields };
|
29
33
|
|
@@ -174,9 +178,7 @@ export type NumberTypeNodes = StrictNumberTypeNodes | UnknownTypeNodes;
|
|
174
178
|
|
175
179
|
export type FieldNode = ['Field', string];
|
176
180
|
export type ReferencedFieldNode = ['ReferencedField', string, string];
|
177
|
-
export type DateTruncNode =
|
178
|
-
| ['DateTrunc', TextTypeNodes, DateTypeNodes]
|
179
|
-
| ['DateTrunc', TextTypeNodes, DateTypeNodes, TextTypeNodes];
|
181
|
+
export type DateTruncNode = ['DateTrunc', TextTypeNodes, DateTypeNodes];
|
180
182
|
export type ToDateNode = ['ToDate', DateTypeNodes];
|
181
183
|
export type ToTimeNode = ['ToTime', DateTypeNodes];
|
182
184
|
export type CurrentTimestampNode = ['CurrentTimestamp'];
|
@@ -495,6 +497,7 @@ export interface AbstractSqlTable {
|
|
495
497
|
primitive: false | string;
|
496
498
|
triggers?: Trigger[];
|
497
499
|
checks?: Check[];
|
500
|
+
viewDefinition?: Omit<Definition, 'binds'>;
|
498
501
|
definition?: Definition;
|
499
502
|
modifyFields?: AbstractSqlTable['fields'];
|
500
503
|
modifyName?: AbstractSqlTable['name'];
|
@@ -813,18 +816,19 @@ $$;`);
|
|
813
816
|
if (typeof table === 'string') {
|
814
817
|
return;
|
815
818
|
}
|
816
|
-
const { definition } = table;
|
817
|
-
if (definition != null) {
|
819
|
+
const { definition, viewDefinition } = table;
|
820
|
+
if (viewDefinition != null && definition != null) {
|
821
|
+
throw new Error('Cannot have both a definition and a viewDefinition');
|
822
|
+
}
|
823
|
+
if (definition != null || viewDefinition != null) {
|
818
824
|
if (table.fields.some(({ computed }) => computed != null)) {
|
819
825
|
throw new Error(
|
820
826
|
`Using computed fields alongside a custom table definition is unsupported, found for table resourceName: '${table.resourceName}', name: '${table.name}'`,
|
821
827
|
);
|
822
828
|
}
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
}
|
827
|
-
let definitionAbstractSql = definition.abstractSql;
|
829
|
+
}
|
830
|
+
if (viewDefinition != null) {
|
831
|
+
let definitionAbstractSql = viewDefinition.abstractSql;
|
828
832
|
// If there are any resource nodes then it's a dynamic definition and cannot become a view
|
829
833
|
if (containsNode(definitionAbstractSql, isResourceNode)) {
|
830
834
|
return;
|
@@ -25,6 +25,7 @@ import type {
|
|
25
25
|
CrossJoinNode,
|
26
26
|
CurrentDateNode,
|
27
27
|
CurrentTimestampNode,
|
28
|
+
DateTruncNode,
|
28
29
|
DeleteQueryNode,
|
29
30
|
DivideNode,
|
30
31
|
DurationNode,
|
@@ -70,7 +71,6 @@ import type {
|
|
70
71
|
ReferencedFieldNode,
|
71
72
|
ReplaceNode,
|
72
73
|
StrictBooleanTypeNodes,
|
73
|
-
StrictDateTypeNodes,
|
74
74
|
StrictNumberTypeNodes,
|
75
75
|
StrictTextTypeNodes,
|
76
76
|
RightJoinNode,
|
@@ -104,9 +104,9 @@ import type {
|
|
104
104
|
EscapeForLikeNode,
|
105
105
|
EqualsAnyNode,
|
106
106
|
NotInNode,
|
107
|
-
} from './AbstractSQLCompiler';
|
108
|
-
import { isFieldTypeNode } from './AbstractSQLCompiler';
|
109
|
-
import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL';
|
107
|
+
} from './AbstractSQLCompiler.js';
|
108
|
+
import { isFieldTypeNode } from './AbstractSQLCompiler.js';
|
109
|
+
import * as AbstractSQLRules2SQL from './AbstractSQLRules2SQL.js';
|
110
110
|
|
111
111
|
const {
|
112
112
|
isAbstractSqlQuery,
|
@@ -298,9 +298,7 @@ const BooleanValue = MatchValue<BooleanTypeNodes>(
|
|
298
298
|
isBooleanValue as typeof AbstractSQLRules2SQL.isBooleanValue,
|
299
299
|
);
|
300
300
|
|
301
|
-
const isDateValue =
|
302
|
-
return type === 'Now' || AbstractSQLRules2SQL.isDateValue(type);
|
303
|
-
};
|
301
|
+
const { isDateValue } = AbstractSQLRules2SQL;
|
304
302
|
const DateValue = MatchValue(isDateValue);
|
305
303
|
|
306
304
|
const { isJSONValue } = AbstractSQLRules2SQL;
|
@@ -886,16 +884,7 @@ const typeRules = {
|
|
886
884
|
Floor: matchArgs<FloorNode>('Floor', NumericValue),
|
887
885
|
Ceiling: matchArgs<CeilingNode>('Ceiling', NumericValue),
|
888
886
|
ToDate: matchArgs<ToDateNode>('ToDate', DateValue),
|
889
|
-
DateTrunc: (
|
890
|
-
checkMinArgs('DateTrunc', args, 2);
|
891
|
-
const precision = TextValue(getAbstractSqlQuery(args, 0));
|
892
|
-
const date = DateValue(getAbstractSqlQuery(args, 1));
|
893
|
-
const timeZone =
|
894
|
-
args.length === 3 ? TextValue(getAbstractSqlQuery(args, 2)) : undefined;
|
895
|
-
return timeZone
|
896
|
-
? ['DateTrunc', precision, date, timeZone]
|
897
|
-
: ['DateTrunc', precision, date];
|
898
|
-
},
|
887
|
+
DateTrunc: matchArgs<DateTruncNode>('DateTrunc', TextValue, DateValue),
|
899
888
|
ToTime: matchArgs<ToTimeNode>('ToTime', DateValue),
|
900
889
|
ExtractJSONPathAsText: (args): ExtractJSONPathAsTextNode => {
|
901
890
|
checkMinArgs('ExtractJSONPathAsText', args, 1);
|
@@ -1532,11 +1521,6 @@ const typeRules = {
|
|
1532
1521
|
EscapeForLike: matchArgs<EscapeForLikeNode>('EscapeForLike', TextValue),
|
1533
1522
|
|
1534
1523
|
// Virtual functions
|
1535
|
-
Now: rewriteMatch(
|
1536
|
-
'Now',
|
1537
|
-
[],
|
1538
|
-
Helper<MatchFn<CurrentTimestampNode>>(() => ['CurrentTimestamp']),
|
1539
|
-
),
|
1540
1524
|
Contains: rewriteMatch(
|
1541
1525
|
'Contains',
|
1542
1526
|
[TextValue, TextValue],
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import sbvrTypes from '@balena/sbvr-types';
|
1
|
+
import $sbvrTypes from '@balena/sbvr-types';
|
2
|
+
const { default: sbvrTypes } = $sbvrTypes;
|
2
3
|
import type {
|
3
4
|
AbstractSqlQuery,
|
4
5
|
AbstractSqlType,
|
@@ -17,8 +18,8 @@ import type {
|
|
17
18
|
StrictDurationTypeNodes,
|
18
19
|
StrictTextArrayTypeNodes,
|
19
20
|
StrictJSONTypeNodes,
|
20
|
-
} from './AbstractSQLCompiler';
|
21
|
-
import { Engines, isFieldTypeNode } from './AbstractSQLCompiler';
|
21
|
+
} from './AbstractSQLCompiler.js';
|
22
|
+
import { Engines, isFieldTypeNode } from './AbstractSQLCompiler.js';
|
22
23
|
|
23
24
|
export type Binding =
|
24
25
|
| [string, any]
|
@@ -1207,7 +1208,7 @@ const typeRules: Record<string, MatchFn> = {
|
|
1207
1208
|
return `DATE(${date})`;
|
1208
1209
|
},
|
1209
1210
|
DateTrunc: (args, indent) => {
|
1210
|
-
|
1211
|
+
checkArgs('DateTrunc', args, 2);
|
1211
1212
|
const precision = TextValue(getAbstractSqlQuery(args, 0), indent);
|
1212
1213
|
const date = DateValue(getAbstractSqlQuery(args, 1), indent);
|
1213
1214
|
// Postgres generated timestamps have a microseconds precision
|
@@ -1215,13 +1216,7 @@ const typeRules: Record<string, MatchFn> = {
|
|
1215
1216
|
// js timestamps that have only milliseconds precision
|
1216
1217
|
// thus supporting for truncating to a given precision
|
1217
1218
|
if (engine === Engines.postgres) {
|
1218
|
-
|
1219
|
-
args.length === 3
|
1220
|
-
? TextValue(getAbstractSqlQuery(args, 2), indent)
|
1221
|
-
: undefined;
|
1222
|
-
return timeZone
|
1223
|
-
? `DATE_TRUNC(${precision}, ${date}, ${timeZone})`
|
1224
|
-
: `DATE_TRUNC(${precision}, ${date})`;
|
1219
|
+
return `DATE_TRUNC(${precision}, ${date})`;
|
1225
1220
|
} else if (
|
1226
1221
|
// not postgresql ==> no need to truncate ==> return timestamp as is (milliseconds precision)
|
1227
1222
|
precision === "'milliseconds'" ||
|
@@ -4,17 +4,18 @@ export const enum Engines {
|
|
4
4
|
websql = 'websql',
|
5
5
|
}
|
6
6
|
|
7
|
-
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
|
8
|
-
export { Binding, SqlResult } from './AbstractSQLRules2SQL';
|
9
|
-
import sbvrTypes from '@balena/sbvr-types';
|
7
|
+
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
|
8
|
+
export { Binding, SqlResult } from './AbstractSQLRules2SQL.js';
|
9
|
+
import $sbvrTypes from '@balena/sbvr-types';
|
10
|
+
const { default: sbvrTypes } = $sbvrTypes;
|
10
11
|
import type {
|
11
12
|
AbstractSqlModel,
|
12
13
|
AbstractSqlQuery,
|
13
14
|
AbstractSqlType,
|
14
15
|
BooleanTypeNodes,
|
15
16
|
WhereNode,
|
16
|
-
} from './AbstractSQLCompiler';
|
17
|
-
import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler';
|
17
|
+
} from './AbstractSQLCompiler.js';
|
18
|
+
import { isFromNode, isSelectQueryNode } from './AbstractSQLCompiler.js';
|
18
19
|
|
19
20
|
const countFroms = (n: AbstractSqlType[]) => {
|
20
21
|
let count = 0;
|
package/src/referenced-fields.ts
CHANGED
@@ -48,7 +48,7 @@ import type {
|
|
48
48
|
ToJSONNode,
|
49
49
|
UnionQueryNode,
|
50
50
|
WhereNode,
|
51
|
-
} from './AbstractSQLCompiler';
|
51
|
+
} from './AbstractSQLCompiler.js';
|
52
52
|
import {
|
53
53
|
isAliasNode,
|
54
54
|
isFromNode,
|
@@ -56,9 +56,9 @@ import {
|
|
56
56
|
isSelectQueryNode,
|
57
57
|
isTableNode,
|
58
58
|
isWhereNode,
|
59
|
-
} from './AbstractSQLCompiler';
|
60
|
-
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser';
|
61
|
-
import { isAbstractSqlQuery } from './AbstractSQLRules2SQL';
|
59
|
+
} from './AbstractSQLCompiler.js';
|
60
|
+
import { AbstractSQLOptimiser } from './AbstractSQLOptimiser.js';
|
61
|
+
import { isAbstractSqlQuery } from './AbstractSQLRules2SQL.js';
|
62
62
|
|
63
63
|
export interface ReferencedFields {
|
64
64
|
[alias: string]: string[];
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect } from 'chai';
|
2
|
-
import test from './test';
|
2
|
+
import test from './test.js';
|
3
3
|
|
4
4
|
describe('Count', () => {
|
5
5
|
test(['SelectQuery', ['Select', [['Count', '*']]]], (result, sqlEquals) => {
|
@@ -33,7 +33,10 @@ describe('Sum', () => {
|
|
33
33
|
|
34
34
|
describe('Subtract now timestamp from now timestamp', () => {
|
35
35
|
test(
|
36
|
-
[
|
36
|
+
[
|
37
|
+
'SelectQuery',
|
38
|
+
['Select', [['Subtract', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
|
39
|
+
],
|
37
40
|
(result, sqlEquals) => {
|
38
41
|
it('Subtract now timestamp from now timestamp', () => {
|
39
42
|
sqlEquals(result, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
|
@@ -46,7 +49,10 @@ describe('Subtract Duration from now timestamp', () => {
|
|
46
49
|
test(
|
47
50
|
[
|
48
51
|
'SelectQuery',
|
49
|
-
[
|
52
|
+
[
|
53
|
+
'Select',
|
54
|
+
[['Subtract', ['CurrentTimestamp'], ['Duration', { day: 1 }]]],
|
55
|
+
],
|
50
56
|
],
|
51
57
|
(result, sqlEquals) => {
|
52
58
|
it('Subtract Duration from now timestamp', () => {
|
@@ -58,16 +64,25 @@ describe('Subtract Duration from now timestamp', () => {
|
|
58
64
|
|
59
65
|
// this is not allowed
|
60
66
|
describe('Add now timestamp to now timestamp should fail', () => {
|
61
|
-
test.fail(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
test.fail(
|
68
|
+
[
|
69
|
+
'SelectQuery',
|
70
|
+
['Select', [['Add', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
|
71
|
+
],
|
72
|
+
(err) => {
|
73
|
+
it('Add now timestamp to now timestamp should fail', () => {
|
74
|
+
expect(err).to.be.an('error');
|
75
|
+
});
|
76
|
+
},
|
77
|
+
);
|
66
78
|
});
|
67
79
|
|
68
80
|
describe('Add Duration to now timestamp', () => {
|
69
81
|
test(
|
70
|
-
[
|
82
|
+
[
|
83
|
+
'SelectQuery',
|
84
|
+
['Select', [['Add', ['CurrentTimestamp'], ['Duration', { day: 1 }]]]],
|
85
|
+
],
|
71
86
|
(result, sqlEquals) => {
|
72
87
|
it('Add Duration to now timestamp', () => {
|
73
88
|
sqlEquals(result, `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`);
|
@@ -85,7 +100,7 @@ describe('Substract DateTrunc datefield from now timestamp', () => {
|
|
85
100
|
[
|
86
101
|
[
|
87
102
|
'Subtract',
|
88
|
-
['
|
103
|
+
['CurrentTimestamp'],
|
89
104
|
[
|
90
105
|
'DateTrunc',
|
91
106
|
['EmbeddedText', 'milliseconds'],
|
@@ -1,5 +1,8 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type {
|
2
|
+
CaseNode,
|
3
|
+
SelectQueryNode,
|
4
|
+
} from '../../out/AbstractSQLCompiler.js';
|
5
|
+
import test from './test.js';
|
3
6
|
|
4
7
|
const buildSelect = (withElse: boolean): SelectQueryNode => {
|
5
8
|
let caseNode: CaseNode = [
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import test from './test';
|
1
|
+
import test from './test.js';
|
2
2
|
|
3
3
|
describe('Year', () => {
|
4
4
|
test(
|
@@ -127,29 +127,6 @@ describe('DateTrunc', () => {
|
|
127
127
|
});
|
128
128
|
},
|
129
129
|
);
|
130
|
-
|
131
|
-
test(
|
132
|
-
[
|
133
|
-
'SelectQuery',
|
134
|
-
[
|
135
|
-
'Select',
|
136
|
-
[
|
137
|
-
[
|
138
|
-
'DateTrunc',
|
139
|
-
['EmbeddedText', 'year'],
|
140
|
-
['Date', '2022-10-10'],
|
141
|
-
['EmbeddedText', 'UTC'],
|
142
|
-
],
|
143
|
-
],
|
144
|
-
],
|
145
|
-
],
|
146
|
-
[['Date', '2022-10-10']],
|
147
|
-
(result, sqlEquals) => {
|
148
|
-
it('should produce a valid DateTrunc statement', () => {
|
149
|
-
sqlEquals(result, `SELECT DATE_TRUNC('year', $1, 'UTC')`);
|
150
|
-
});
|
151
|
-
},
|
152
|
-
);
|
153
130
|
});
|
154
131
|
|
155
132
|
describe('ToTime', () => {
|
@@ -359,7 +336,13 @@ describe('SubtractDateDate', () => {
|
|
359
336
|
'SelectQuery',
|
360
337
|
[
|
361
338
|
'Select',
|
362
|
-
[
|
339
|
+
[
|
340
|
+
[
|
341
|
+
'Multiply',
|
342
|
+
['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
|
343
|
+
['Number', 4],
|
344
|
+
],
|
345
|
+
],
|
363
346
|
],
|
364
347
|
],
|
365
348
|
(result, sqlEquals) => {
|
@@ -377,7 +360,7 @@ describe('SubtractDateDate', () => {
|
|
377
360
|
[
|
378
361
|
[
|
379
362
|
'Multiply',
|
380
|
-
['SubtractDateDate', ['
|
363
|
+
['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
|
381
364
|
['Subtract', ['Number', 4], ['Number', 5]],
|
382
365
|
],
|
383
366
|
],
|
@@ -403,7 +386,7 @@ describe('SubtractDateDate', () => {
|
|
403
386
|
'SubtractDateDate',
|
404
387
|
[
|
405
388
|
'AddDateDuration',
|
406
|
-
['
|
389
|
+
['CurrentTimestamp'],
|
407
390
|
[
|
408
391
|
'Duration',
|
409
392
|
{
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { stripIndent } from 'common-tags';
|
2
|
-
import type { SelectQueryNode } from '../../
|
2
|
+
import type { SelectQueryNode } from '../../out/AbstractSQLCompiler.js';
|
3
3
|
|
4
|
-
import test from './test';
|
4
|
+
import test from './test.js';
|
5
5
|
|
6
6
|
describe('Empty queries should be optimized', () => {
|
7
7
|
const emptyQuery: SelectQueryNode = [
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect } from 'chai';
|
2
|
-
import * as AbstractSqlCompiler from '../../
|
2
|
+
import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
|
3
3
|
|
4
4
|
describe('getReferencedFields', () => {
|
5
5
|
it('should work with selected fields', () => {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect } from 'chai';
|
2
|
-
import * as AbstractSqlCompiler from '../../
|
2
|
+
import * as AbstractSqlCompiler from '../../out/AbstractSQLCompiler.js';
|
3
3
|
|
4
4
|
describe('getRuleReferencedFields', () => {
|
5
5
|
it('should work with single table NOT EXISTS', () => {
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import * as AbstractSQLCompiler from '
|
1
|
+
import * as AbstractSQLCompiler from '../../out/AbstractSQLCompiler.js';
|
2
2
|
import { expect } from 'chai';
|
3
3
|
|
4
|
-
it('a table with a static definition should produce a view', () => {
|
4
|
+
it('a table with a static definition should not produce a view', () => {
|
5
5
|
expect(
|
6
6
|
AbstractSQLCompiler.postgres.compileSchema({
|
7
7
|
synonyms: {},
|
@@ -30,6 +30,41 @@ it('a table with a static definition should produce a view', () => {
|
|
30
30
|
.to.have.property('createSchema')
|
31
31
|
.that.deep.equals([
|
32
32
|
`\
|
33
|
+
CREATE TABLE IF NOT EXISTS "test" (
|
34
|
+
"id" INTEGER NULL PRIMARY KEY
|
35
|
+
);`,
|
36
|
+
]);
|
37
|
+
});
|
38
|
+
|
39
|
+
it('a table with a view definition should produce a view', () => {
|
40
|
+
expect(
|
41
|
+
AbstractSQLCompiler.postgres.compileSchema({
|
42
|
+
synonyms: {},
|
43
|
+
relationships: {},
|
44
|
+
tables: {
|
45
|
+
test: {
|
46
|
+
name: 'test',
|
47
|
+
resourceName: 'test',
|
48
|
+
idField: 'id',
|
49
|
+
fields: [
|
50
|
+
{
|
51
|
+
fieldName: 'id',
|
52
|
+
dataType: 'Integer',
|
53
|
+
index: 'PRIMARY KEY',
|
54
|
+
},
|
55
|
+
],
|
56
|
+
indexes: [],
|
57
|
+
primitive: false,
|
58
|
+
viewDefinition: { abstractSql: ['Table', 'other table'] },
|
59
|
+
},
|
60
|
+
},
|
61
|
+
rules: [],
|
62
|
+
lfInfo: { rules: {} },
|
63
|
+
}),
|
64
|
+
)
|
65
|
+
.to.have.property('createSchema')
|
66
|
+
.that.deep.equals([
|
67
|
+
`\
|
33
68
|
CREATE OR REPLACE VIEW "test" AS (
|
34
69
|
SELECT *
|
35
70
|
FROM "other table"
|
package/test/odata/expand.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import type { ExpectationFailFn, ExpectationSuccessFn } from './test';
|
2
|
-
import test from './test';
|
1
|
+
import type { ExpectationFailFn, ExpectationSuccessFn } from './test.js';
|
2
|
+
import test from './test.js';
|
3
3
|
import {
|
4
4
|
pilotFields,
|
5
5
|
aliasFields,
|
6
6
|
aliasLicenceFields,
|
7
7
|
aliasPlaneFields,
|
8
8
|
aliasPilotCanFlyPlaneFields,
|
9
|
-
} from './fields';
|
9
|
+
} from './fields.js';
|
10
10
|
import _ from 'lodash';
|
11
11
|
|
12
12
|
type TestFn = (
|