Skip to content

Commit

Permalink
Extend SingleStoreDB support (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Nov 22, 2022
2 parents b88d27a + 1445cde commit 7d00bec
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/languages/singlestoredb/singlestoredb.formatter.ts
Expand Up @@ -254,10 +254,27 @@ export const singlestoredb: DialectOptions = {
{ quote: '``', prefixes: ['@'], requirePrefix: true },
],
lineCommentTypes: ['--', '#'],
operators: [':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
operators: [
':=',
'&',
'|',
'^',
'~',
'<<',
'>>',
'<=>',
'&&',
'||',
'::',
'::$',
'::%',
':>',
'!:>',
],
postProcess,
},
formatOptions: {
alwaysDenseOperators: ['::', '::$', '::%'],
onelineClauses,
},
};
Expand Down
36 changes: 35 additions & 1 deletion test/singlestoredb.test.ts
@@ -1,3 +1,4 @@
import dedent from 'dedent-js';
import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js';
import behavesLikeMariaDbFormatter from './behavesLikeMariaDbFormatter.js';

Expand Down Expand Up @@ -33,7 +34,7 @@ describe('SingleStoreDbFormatter', () => {
]);
supportsOperators(
format,
[':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
[':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||', ':>', '!:>'],
['AND', 'OR']
);
supportsLimiting(format, { limit: true, offset: true });
Expand All @@ -45,4 +46,37 @@ describe('SingleStoreDbFormatter', () => {
modify: true,
renameTo: true,
});

describe(`formats traversal of semi structured data`, () => {
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'
`);
});
});
});

0 comments on commit 7d00bec

Please sign in to comment.