Skip to content

Commit 7d00bec

Browse files
committed
Extend SingleStoreDB support (#531)
2 parents b88d27a + 1445cde commit 7d00bec

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/languages/singlestoredb/singlestoredb.formatter.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,27 @@ export const singlestoredb: DialectOptions = {
254254
{ quote: '``', prefixes: ['@'], requirePrefix: true },
255255
],
256256
lineCommentTypes: ['--', '#'],
257-
operators: [':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
257+
operators: [
258+
':=',
259+
'&',
260+
'|',
261+
'^',
262+
'~',
263+
'<<',
264+
'>>',
265+
'<=>',
266+
'&&',
267+
'||',
268+
'::',
269+
'::$',
270+
'::%',
271+
':>',
272+
'!:>',
273+
],
258274
postProcess,
259275
},
260276
formatOptions: {
277+
alwaysDenseOperators: ['::', '::$', '::%'],
261278
onelineClauses,
262279
},
263280
};

test/singlestoredb.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dedent from 'dedent-js';
12
import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
23
import behavesLikeMariaDbFormatter from './behavesLikeMariaDbFormatter.js';
34

@@ -33,7 +34,7 @@ describe('SingleStoreDbFormatter', () => {
3334
]);
3435
supportsOperators(
3536
format,
36-
[':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
37+
[':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||', ':>', '!:>'],
3738
['AND', 'OR']
3839
);
3940
supportsLimiting(format, { limit: true, offset: true });
@@ -45,4 +46,37 @@ describe('SingleStoreDbFormatter', () => {
4546
modify: true,
4647
renameTo: true,
4748
});
49+
50+
describe(`formats traversal of semi structured data`, () => {
51+
it(`formats '::' path-operator without spaces`, () => {
52+
expect(format(`SELECT * FROM foo WHERE json_foo::bar = 'foobar'`)).toBe(dedent`
53+
SELECT
54+
*
55+
FROM
56+
foo
57+
WHERE
58+
json_foo::bar = 'foobar'
59+
`);
60+
});
61+
it(`formats '::$' conversion path-operator without spaces`, () => {
62+
expect(format(`SELECT * FROM foo WHERE json_foo::$bar = 'foobar'`)).toBe(dedent`
63+
SELECT
64+
*
65+
FROM
66+
foo
67+
WHERE
68+
json_foo::$bar = 'foobar'
69+
`);
70+
});
71+
it(`formats '::%' conversion path-operator without spaces`, () => {
72+
expect(format(`SELECT * FROM foo WHERE json_foo::%bar = 'foobar'`)).toBe(dedent`
73+
SELECT
74+
*
75+
FROM
76+
foo
77+
WHERE
78+
json_foo::%bar = 'foobar'
79+
`);
80+
});
81+
});
4882
});

0 commit comments

Comments
 (0)