@balena/abstract-sql-compiler 10.2.3-build-renovate-major-22-node-d6c0f904df738bdfb51aa65395e2b146a26000e6-1 → 10.2.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/.versionbot/CHANGELOG.yml +21 -6
- package/CHANGELOG.md +4 -2
- package/package.json +3 -3
- package/test/abstract-sql/aggregate-json.ts +2 -13
- package/test/abstract-sql/aggregate.ts +14 -38
- package/test/abstract-sql/and-or-boolean-optimisations.ts +5 -16
- package/test/abstract-sql/{case-when-else.js → case-when-else.ts} +13 -22
- package/test/abstract-sql/cast.ts +3 -14
- package/test/abstract-sql/coalesce.ts +3 -14
- package/test/abstract-sql/comparisons.ts +14 -25
- package/test/abstract-sql/dates.ts +23 -37
- package/test/abstract-sql/duration.ts +3 -17
- package/test/abstract-sql/empty-query-optimisations.ts +4 -16
- package/test/abstract-sql/functions_wrapper.ts +3 -16
- package/test/abstract-sql/insert-query.ts +2 -13
- package/test/abstract-sql/is-distinct.ts +9 -23
- package/test/abstract-sql/joins.ts +3 -14
- package/test/abstract-sql/json.ts +4 -18
- package/test/abstract-sql/math.ts +28 -39
- package/test/abstract-sql/nested-in-optimisations.ts +5 -16
- package/test/abstract-sql/not-not-optimisations.ts +2 -13
- package/test/abstract-sql/test.ts +192 -0
- package/test/abstract-sql/text.ts +11 -22
- package/test/odata/test.js +19 -22
- package/test/abstract-sql/test.js +0 -92
@@ -1,92 +0,0 @@
|
|
1
|
-
import * as AbstractSQLCompiler from '../..';
|
2
|
-
|
3
|
-
import { expect } from 'chai';
|
4
|
-
import _ from 'lodash';
|
5
|
-
|
6
|
-
const bindingsTest = function (actualBindings, expectedBindings) {
|
7
|
-
if (expectedBindings == null) {
|
8
|
-
expectedBindings = false;
|
9
|
-
}
|
10
|
-
if (expectedBindings === false) {
|
11
|
-
it('should not have any bindings', () => {
|
12
|
-
expect(actualBindings).to.be.empty;
|
13
|
-
});
|
14
|
-
} else {
|
15
|
-
it('should have matching bindings', () => {
|
16
|
-
expect(actualBindings).to.deep.equal(expectedBindings);
|
17
|
-
});
|
18
|
-
}
|
19
|
-
};
|
20
|
-
|
21
|
-
const equals = (actual, expected) => {
|
22
|
-
expect(actual).to.equal(expected);
|
23
|
-
};
|
24
|
-
const sqlEquals = {
|
25
|
-
websql: equals,
|
26
|
-
mysql: equals,
|
27
|
-
postgres(actual, expected) {
|
28
|
-
let num = 1;
|
29
|
-
while (_.includes(expected, '?')) {
|
30
|
-
expected = expected.replace('?', '$' + num);
|
31
|
-
num++;
|
32
|
-
}
|
33
|
-
equals(actual, expected);
|
34
|
-
},
|
35
|
-
};
|
36
|
-
|
37
|
-
const runExpectation = function (
|
38
|
-
describe,
|
39
|
-
engine,
|
40
|
-
input,
|
41
|
-
expectedBindings,
|
42
|
-
body,
|
43
|
-
expectation,
|
44
|
-
) {
|
45
|
-
if (expectation == null) {
|
46
|
-
if (body == null) {
|
47
|
-
expectation = expectedBindings;
|
48
|
-
expectedBindings = false;
|
49
|
-
} else {
|
50
|
-
expectation = body;
|
51
|
-
}
|
52
|
-
body = {};
|
53
|
-
}
|
54
|
-
|
55
|
-
describe('Parsing ' + JSON.stringify(input), function () {
|
56
|
-
let result;
|
57
|
-
try {
|
58
|
-
result = AbstractSQLCompiler[engine].compileRule(input);
|
59
|
-
} catch (e) {
|
60
|
-
expectation(e);
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
if (Array.isArray(result)) {
|
64
|
-
for (let i = 0; i < result.length; i++) {
|
65
|
-
const actualResult = result[i];
|
66
|
-
if (expectedBindings[0][0] === 'Bind') {
|
67
|
-
bindingsTest(actualResult.bindings, expectedBindings);
|
68
|
-
} else {
|
69
|
-
bindingsTest(actualResult.bindings, expectedBindings[i]);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
} else {
|
73
|
-
bindingsTest(result.bindings, expectedBindings);
|
74
|
-
}
|
75
|
-
return expectation(result, sqlEquals[engine]);
|
76
|
-
});
|
77
|
-
};
|
78
|
-
|
79
|
-
const bindRunExpectation = function (engine) {
|
80
|
-
const bound = runExpectation.bind(null, describe, engine);
|
81
|
-
bound.skip = runExpectation.bind(null, describe.skip, engine);
|
82
|
-
// eslint-disable-next-line no-only-tests/no-only-tests -- this is a false positive
|
83
|
-
bound.only = runExpectation.bind(null, describe.only, engine);
|
84
|
-
return bound;
|
85
|
-
};
|
86
|
-
|
87
|
-
const testFn = bindRunExpectation('postgres');
|
88
|
-
testFn.postgres = bindRunExpectation('postgres');
|
89
|
-
testFn.mysql = bindRunExpectation('mysql');
|
90
|
-
testFn.websql = bindRunExpectation('websql');
|
91
|
-
|
92
|
-
export default testFn;
|