-
Notifications
You must be signed in to change notification settings - Fork 391
/
singlestoredb.test.ts
105 lines (100 loc) · 3.18 KB
/
singlestoredb.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import dedent from 'dedent-js';
import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
import behavesLikeMariaDbFormatter from './behavesLikeMariaDbFormatter.js';
import supportsJoin from './features/join.js';
import supportsOperators from './features/operators.js';
import supportsSetOperations from './features/setOperations.js';
import supportsLimiting from './features/limiting.js';
import supportsCreateTable from './features/createTable.js';
import supportsCreateView from './features/createView.js';
import supportsAlterTable from './features/alterTable.js';
import supportsStrings from './features/strings.js';
import supportsBetween from './features/between.js';
describe('SingleStoreDbFormatter', () => {
const language = 'singlestoredb';
const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });
behavesLikeMariaDbFormatter(format);
// in addition to string types listed in behavesLikeMariaDbFormatter
supportsStrings(format, ["B''"]);
supportsJoin(format, {
without: ['NATURAL INNER JOIN', 'NATURAL FULL', 'NATURAL JOIN'],
additionally: ['STRAIGHT_JOIN'],
});
supportsSetOperations(format, [
'UNION',
'UNION ALL',
'UNION DISTINCT',
'EXCEPT',
'INTERSECT',
'MINUS',
]);
supportsOperators(
format,
[':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
['AND', 'OR']
);
supportsLimiting(format, { limit: true, offset: true });
supportsCreateTable(format, { ifNotExists: true });
supportsCreateView(format);
supportsBetween(format);
supportsAlterTable(format, {
addColumn: true,
dropColumn: true,
modify: true,
renameTo: true,
});
describe(`formats traversal of semi structured data`, () => {
it(`formats '.' path-operator without spaces`, () => {
expect(format(`SELECT TO_JSON(foo.*) AS foo_json FROM foo`)).toBe(dedent`
SELECT
TO_JSON(foo.*) AS foo_json
FROM
foo
`);
});
it(`formats '::' path-operator without spaces`, () => {
expect(format(`SELECT * FROM foo WHERE json_foo::bar = 'foobar'`)).toBe(dedent`
SELECT
*
FROM
foo
WHERE
json_foo::bar = 'foobar'
`);
});
it(`formats '::$' conversion path-operator without spaces`, () => {
expect(format(`SELECT * FROM foo WHERE json_foo::$bar = 'foobar'`)).toBe(dedent`
SELECT
*
FROM
foo
WHERE
json_foo::$bar = 'foobar'
`);
});
it(`formats '::%' conversion path-operator without spaces`, () => {
expect(format(`SELECT * FROM foo WHERE json_foo::%bar = 'foobar'`)).toBe(dedent`
SELECT
*
FROM
foo
WHERE
json_foo::%bar = 'foobar'
`);
});
});
describe(`formats custom type-cast operators`, () => {
it(`formats ':>' type-cast operator`, () => {
expect(format(`SELECT 1 :> DOUBLE AS foo`)).toBe(dedent`
SELECT
1 :> DOUBLE AS foo
`);
});
it(`formats '!:>' type-cast operator`, () => {
expect(format(`SELECT 1 !:> DOUBLE AS foo`)).toBe(dedent`
SELECT
1 !:> DOUBLE AS foo
`);
});
});
});