@balena/abstract-sql-compiler 11.0.0-build-11-x-b2280608fff69d9959999c79db6245c4ad561bbc-1 → 11.0.0-build-11-x-7511b8ebe5a9461f20add0ed97d0670ed3b5a479-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/package.json +5 -2
- package/.github/workflows/flowzone.yml +0 -21
- package/.husky/pre-commit +0 -2
- package/.versionbot/CHANGELOG.yml +0 -10729
- package/CHANGELOG.md +0 -3515
- package/repo.yml +0 -12
- package/src/abstract-sql-compiler.ts +0 -1138
- package/src/abstract-sql-optimizer.ts +0 -1632
- package/src/abstract-sql-rules-to-sql.ts +0 -1730
- package/src/abstract-sql-schema-optimizer.ts +0 -172
- package/src/referenced-fields.ts +0 -600
- package/test/abstract-sql/aggregate-json.ts +0 -49
- package/test/abstract-sql/aggregate.ts +0 -161
- package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
- package/test/abstract-sql/case-when-else.ts +0 -48
- package/test/abstract-sql/cast.ts +0 -25
- package/test/abstract-sql/coalesce.ts +0 -24
- package/test/abstract-sql/comparisons.ts +0 -360
- package/test/abstract-sql/dates.ts +0 -512
- package/test/abstract-sql/duration.ts +0 -56
- package/test/abstract-sql/empty-query-optimisations.ts +0 -54
- package/test/abstract-sql/functions-wrapper.ts +0 -70
- package/test/abstract-sql/get-referenced-fields.ts +0 -674
- package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
- package/test/abstract-sql/insert-query.ts +0 -22
- package/test/abstract-sql/is-distinct.ts +0 -102
- package/test/abstract-sql/joins.ts +0 -84
- package/test/abstract-sql/json.ts +0 -58
- package/test/abstract-sql/math.ts +0 -467
- package/test/abstract-sql/nested-in-optimisations.ts +0 -200
- package/test/abstract-sql/not-not-optimisations.ts +0 -15
- package/test/abstract-sql/schema-checks.ts +0 -168
- package/test/abstract-sql/schema-informative-reference.ts +0 -420
- package/test/abstract-sql/schema-rule-optimization.ts +0 -120
- package/test/abstract-sql/schema-rule-to-check.ts +0 -393
- package/test/abstract-sql/schema-views.ts +0 -73
- package/test/abstract-sql/test.ts +0 -192
- package/test/abstract-sql/text.ts +0 -168
- package/test/model.sbvr +0 -60
- package/test/odata/expand.ts +0 -674
- package/test/odata/fields.ts +0 -59
- package/test/odata/filterby.ts +0 -1517
- package/test/odata/orderby.ts +0 -96
- package/test/odata/paging.ts +0 -48
- package/test/odata/resource-parsing.ts +0 -568
- package/test/odata/select.ts +0 -119
- package/test/odata/stress.ts +0 -93
- package/test/odata/test.ts +0 -297
- package/test/sbvr/pilots.ts +0 -1097
- package/test/sbvr/reference-type.ts +0 -211
- package/test/sbvr/test.ts +0 -101
- package/tsconfig.build.json +0 -6
- package/tsconfig.json +0 -25
@@ -1,161 +0,0 @@
|
|
1
|
-
import { expect } from 'chai';
|
2
|
-
import test from './test.js';
|
3
|
-
|
4
|
-
describe('Count', () => {
|
5
|
-
test(['SelectQuery', ['Select', [['Count', '*']]]], (result, sqlEquals) => {
|
6
|
-
it('should produce a valid COUNT(*) statement', () => {
|
7
|
-
sqlEquals(result, 'SELECT COUNT(*)');
|
8
|
-
});
|
9
|
-
});
|
10
|
-
});
|
11
|
-
|
12
|
-
describe('Average', () => {
|
13
|
-
test(
|
14
|
-
['SelectQuery', ['Select', [['Average', ['Number', 5]]]]],
|
15
|
-
(result, sqlEquals) => {
|
16
|
-
it('should produce a valid AVG(5) statement', () => {
|
17
|
-
sqlEquals(result, 'SELECT AVG(5)');
|
18
|
-
});
|
19
|
-
},
|
20
|
-
);
|
21
|
-
});
|
22
|
-
|
23
|
-
describe('Sum', () => {
|
24
|
-
test(
|
25
|
-
['SelectQuery', ['Select', [['Sum', ['Number', 5]]]]],
|
26
|
-
(result, sqlEquals) => {
|
27
|
-
it('should produce a valid SUM(5) statement', () => {
|
28
|
-
sqlEquals(result, 'SELECT SUM(5)');
|
29
|
-
});
|
30
|
-
},
|
31
|
-
);
|
32
|
-
});
|
33
|
-
|
34
|
-
describe('Subtract now timestamp from now timestamp', () => {
|
35
|
-
test(
|
36
|
-
[
|
37
|
-
'SelectQuery',
|
38
|
-
['Select', [['Subtract', ['CurrentTimestamp'], ['CurrentTimestamp']]]],
|
39
|
-
],
|
40
|
-
(result, sqlEquals) => {
|
41
|
-
it('Subtract now timestamp from now timestamp', () => {
|
42
|
-
sqlEquals(result, 'SELECT CURRENT_TIMESTAMP - CURRENT_TIMESTAMP');
|
43
|
-
});
|
44
|
-
},
|
45
|
-
);
|
46
|
-
});
|
47
|
-
|
48
|
-
describe('Subtract Duration from now timestamp', () => {
|
49
|
-
test(
|
50
|
-
[
|
51
|
-
'SelectQuery',
|
52
|
-
[
|
53
|
-
'Select',
|
54
|
-
[['Subtract', ['CurrentTimestamp'], ['Duration', { day: 1 }]]],
|
55
|
-
],
|
56
|
-
],
|
57
|
-
(result, sqlEquals) => {
|
58
|
-
it('Subtract Duration from now timestamp', () => {
|
59
|
-
sqlEquals(result, `SELECT CURRENT_TIMESTAMP - INTERVAL '1 0:0:0.0'`);
|
60
|
-
});
|
61
|
-
},
|
62
|
-
);
|
63
|
-
});
|
64
|
-
|
65
|
-
// this is not allowed
|
66
|
-
describe('Add now timestamp to now timestamp should fail', () => {
|
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
|
-
);
|
78
|
-
});
|
79
|
-
|
80
|
-
describe('Add Duration to now timestamp', () => {
|
81
|
-
test(
|
82
|
-
[
|
83
|
-
'SelectQuery',
|
84
|
-
['Select', [['Add', ['CurrentTimestamp'], ['Duration', { day: 1 }]]]],
|
85
|
-
],
|
86
|
-
(result, sqlEquals) => {
|
87
|
-
it('Add Duration to now timestamp', () => {
|
88
|
-
sqlEquals(result, `SELECT CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0'`);
|
89
|
-
});
|
90
|
-
},
|
91
|
-
);
|
92
|
-
});
|
93
|
-
|
94
|
-
describe('Substract DateTrunc datefield from now timestamp', () => {
|
95
|
-
test(
|
96
|
-
[
|
97
|
-
'SelectQuery',
|
98
|
-
[
|
99
|
-
'Select',
|
100
|
-
[
|
101
|
-
[
|
102
|
-
'Subtract',
|
103
|
-
['CurrentTimestamp'],
|
104
|
-
[
|
105
|
-
'DateTrunc',
|
106
|
-
['EmbeddedText', 'milliseconds'],
|
107
|
-
['Date', '2022-10-10'],
|
108
|
-
],
|
109
|
-
],
|
110
|
-
],
|
111
|
-
],
|
112
|
-
],
|
113
|
-
[['Date', '2022-10-10']],
|
114
|
-
(result, sqlEquals) => {
|
115
|
-
it('Substract DateTrunc datefield from now timestamp', () => {
|
116
|
-
sqlEquals(
|
117
|
-
result,
|
118
|
-
`SELECT CURRENT_TIMESTAMP - DATE_TRUNC('milliseconds', $1)`,
|
119
|
-
);
|
120
|
-
});
|
121
|
-
},
|
122
|
-
);
|
123
|
-
});
|
124
|
-
|
125
|
-
describe('Substract DateTrunc datefield from now timestamp', () => {
|
126
|
-
test(
|
127
|
-
[
|
128
|
-
'SelectQuery',
|
129
|
-
[
|
130
|
-
'Select',
|
131
|
-
[
|
132
|
-
[
|
133
|
-
'Subtract',
|
134
|
-
[
|
135
|
-
'DateTrunc',
|
136
|
-
['EmbeddedText', 'milliseconds'],
|
137
|
-
['Date', '2021-11-11'],
|
138
|
-
],
|
139
|
-
[
|
140
|
-
'DateTrunc',
|
141
|
-
['EmbeddedText', 'milliseconds'],
|
142
|
-
['Date', '2022-10-10'],
|
143
|
-
],
|
144
|
-
],
|
145
|
-
],
|
146
|
-
],
|
147
|
-
],
|
148
|
-
[
|
149
|
-
['Date', '2021-11-11'],
|
150
|
-
['Date', '2022-10-10'],
|
151
|
-
],
|
152
|
-
(result, sqlEquals) => {
|
153
|
-
it('Substract DateTrunc datefield from now timestamp', () => {
|
154
|
-
sqlEquals(
|
155
|
-
result,
|
156
|
-
`SELECT DATE_TRUNC('milliseconds', $1) - DATE_TRUNC('milliseconds', $2)`,
|
157
|
-
);
|
158
|
-
});
|
159
|
-
},
|
160
|
-
);
|
161
|
-
});
|
@@ -1,115 +0,0 @@
|
|
1
|
-
import { stripIndent } from 'common-tags';
|
2
|
-
import test from './test.js';
|
3
|
-
|
4
|
-
describe('Unnecessary booleans should be removed', () => {
|
5
|
-
test(
|
6
|
-
[
|
7
|
-
'SelectQuery',
|
8
|
-
['Select', []],
|
9
|
-
['From', ['Table', 'table']],
|
10
|
-
[
|
11
|
-
'Where',
|
12
|
-
[
|
13
|
-
'And',
|
14
|
-
['Equals', ['ReferencedField', 'table', 'field1'], ['Text', 'a']],
|
15
|
-
['Boolean', true],
|
16
|
-
],
|
17
|
-
],
|
18
|
-
],
|
19
|
-
[['Text', 'a']],
|
20
|
-
(result, sqlEquals) => {
|
21
|
-
it('should simplify `... AND true` to `...`', () => {
|
22
|
-
sqlEquals(
|
23
|
-
result,
|
24
|
-
stripIndent`
|
25
|
-
SELECT 1
|
26
|
-
FROM "table"
|
27
|
-
WHERE "table"."field1" = $1
|
28
|
-
`,
|
29
|
-
);
|
30
|
-
});
|
31
|
-
},
|
32
|
-
);
|
33
|
-
test(
|
34
|
-
[
|
35
|
-
'SelectQuery',
|
36
|
-
['Select', []],
|
37
|
-
['From', ['Table', 'table']],
|
38
|
-
[
|
39
|
-
'Where',
|
40
|
-
[
|
41
|
-
'Or',
|
42
|
-
['Equals', ['ReferencedField', 'table', 'field1'], ['Text', 'a']],
|
43
|
-
['Boolean', false],
|
44
|
-
],
|
45
|
-
],
|
46
|
-
],
|
47
|
-
[['Text', 'a']],
|
48
|
-
(result, sqlEquals) => {
|
49
|
-
it('should simplify `... OR false` to `...`', () => {
|
50
|
-
sqlEquals(
|
51
|
-
result,
|
52
|
-
stripIndent`
|
53
|
-
SELECT 1
|
54
|
-
FROM "table"
|
55
|
-
WHERE "table"."field1" = $1
|
56
|
-
`,
|
57
|
-
);
|
58
|
-
});
|
59
|
-
},
|
60
|
-
);
|
61
|
-
test(
|
62
|
-
[
|
63
|
-
'SelectQuery',
|
64
|
-
['Select', []],
|
65
|
-
['From', ['Table', 'table']],
|
66
|
-
[
|
67
|
-
'Where',
|
68
|
-
[
|
69
|
-
'And',
|
70
|
-
['Equals', ['ReferencedField', 'table', 'field1'], ['Text', 'a']],
|
71
|
-
['Boolean', false],
|
72
|
-
],
|
73
|
-
],
|
74
|
-
],
|
75
|
-
(result, sqlEquals) => {
|
76
|
-
it('should simplify `... AND false` to `false`', () => {
|
77
|
-
sqlEquals(
|
78
|
-
result,
|
79
|
-
stripIndent`
|
80
|
-
SELECT 1
|
81
|
-
FROM "table"
|
82
|
-
WHERE false
|
83
|
-
`,
|
84
|
-
);
|
85
|
-
});
|
86
|
-
},
|
87
|
-
);
|
88
|
-
test(
|
89
|
-
[
|
90
|
-
'SelectQuery',
|
91
|
-
['Select', []],
|
92
|
-
['From', ['Table', 'table']],
|
93
|
-
[
|
94
|
-
'Where',
|
95
|
-
[
|
96
|
-
'Or',
|
97
|
-
['Equals', ['ReferencedField', 'table', 'field1'], ['Text', 'a']],
|
98
|
-
['Boolean', true],
|
99
|
-
],
|
100
|
-
],
|
101
|
-
],
|
102
|
-
(result, sqlEquals) => {
|
103
|
-
it('should simplify `... AND true` to `true`', () => {
|
104
|
-
sqlEquals(
|
105
|
-
result,
|
106
|
-
stripIndent`
|
107
|
-
SELECT 1
|
108
|
-
FROM "table"
|
109
|
-
WHERE true
|
110
|
-
`,
|
111
|
-
);
|
112
|
-
});
|
113
|
-
},
|
114
|
-
);
|
115
|
-
});
|
@@ -1,48 +0,0 @@
|
|
1
|
-
import type {
|
2
|
-
CaseNode,
|
3
|
-
SelectQueryNode,
|
4
|
-
} from '../../out/abstract-sql-compiler.js';
|
5
|
-
import test from './test.js';
|
6
|
-
|
7
|
-
const buildSelect = (withElse: boolean): SelectQueryNode => {
|
8
|
-
let caseNode: CaseNode = [
|
9
|
-
'Case',
|
10
|
-
['When', ['Equals', ['Number', -2], ['Number', -2]], ['Text', 'Equal']],
|
11
|
-
];
|
12
|
-
if (withElse) {
|
13
|
-
caseNode = [...caseNode, ['Else', ['Text', 'Not Equal']]];
|
14
|
-
}
|
15
|
-
return ['SelectQuery', ['Select', [['Alias', caseNode, 'equal_alias']]]];
|
16
|
-
};
|
17
|
-
|
18
|
-
test(
|
19
|
-
buildSelect(true),
|
20
|
-
[
|
21
|
-
['Text', 'Equal'],
|
22
|
-
['Text', 'Not Equal'],
|
23
|
-
],
|
24
|
-
(result, sqlEquals) => {
|
25
|
-
it('should produce a valid case statement', () => {
|
26
|
-
sqlEquals(
|
27
|
-
result,
|
28
|
-
`\
|
29
|
-
SELECT CASE
|
30
|
-
WHEN -2 = -2 THEN ?
|
31
|
-
ELSE ?
|
32
|
-
END AS "equal_alias"`,
|
33
|
-
);
|
34
|
-
});
|
35
|
-
},
|
36
|
-
);
|
37
|
-
|
38
|
-
test(buildSelect(false), [['Text', 'Equal']], (result, sqlEquals) => {
|
39
|
-
it('should produce a valid case statement without an else', () => {
|
40
|
-
sqlEquals(
|
41
|
-
result,
|
42
|
-
`\
|
43
|
-
SELECT CASE
|
44
|
-
WHEN -2 = -2 THEN ?
|
45
|
-
END AS "equal_alias"`,
|
46
|
-
);
|
47
|
-
});
|
48
|
-
});
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import test from './test.js';
|
2
|
-
|
3
|
-
describe('Cast', () => {
|
4
|
-
test(
|
5
|
-
['SelectQuery', ['Select', [['Cast', ['Number', 1.2], 'Integer']]]],
|
6
|
-
(result, sqlEquals) => {
|
7
|
-
it('should produce a valid integer cast statement', () => {
|
8
|
-
sqlEquals(result, 'SELECT CAST(1.2 AS INTEGER)');
|
9
|
-
});
|
10
|
-
},
|
11
|
-
);
|
12
|
-
|
13
|
-
test(
|
14
|
-
[
|
15
|
-
'SelectQuery',
|
16
|
-
['Select', [['Cast', ['Date', '2022-10-10T10:10:10.000Z'], 'Date']]],
|
17
|
-
],
|
18
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
19
|
-
(result, sqlEquals) => {
|
20
|
-
it('should produce a valid date cast statement', () => {
|
21
|
-
sqlEquals(result, `SELECT CAST($1 AS DATE)`);
|
22
|
-
});
|
23
|
-
},
|
24
|
-
);
|
25
|
-
});
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import test from './test.js';
|
2
|
-
|
3
|
-
describe('Coalesce', () => {
|
4
|
-
test(
|
5
|
-
['SelectQuery', ['Select', [['Coalesce', ['Number', 1], ['Number', 2]]]]],
|
6
|
-
(result, sqlEquals) => {
|
7
|
-
it('should produce a valid coalesce statement', () => {
|
8
|
-
sqlEquals(result, 'SELECT COALESCE(1, 2)');
|
9
|
-
});
|
10
|
-
},
|
11
|
-
);
|
12
|
-
test(
|
13
|
-
[
|
14
|
-
'SelectQuery',
|
15
|
-
['Select', [['Coalesce', ['Text', '1'], ['Null'], ['Number', 2]]]],
|
16
|
-
],
|
17
|
-
[['Text', '1']],
|
18
|
-
(result, sqlEquals) => {
|
19
|
-
it('should produce a valid coalesce statement', () => {
|
20
|
-
sqlEquals(result, 'SELECT COALESCE($1, NULL, 2)');
|
21
|
-
});
|
22
|
-
},
|
23
|
-
);
|
24
|
-
});
|