Skip to content

Commit bbab038

Browse files
committed
Added further support for SingleStoreDB type-cast and path operators.
1 parent 175835c commit bbab038

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/languages/singlestoredb/singlestoredb.formatter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,11 @@ export const singlestoredb: DialectOptions = {
254254
{ quote: '``', prefixes: ['@'], requirePrefix: true },
255255
],
256256
lineCommentTypes: ['--', '#'],
257-
operators: [':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'],
257+
operators: [':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||', '::', '::$', '::%', ':>', '!:>'],
258258
postProcess,
259259
},
260260
formatOptions: {
261+
alwaysDenseOperators: ['::', '::$', '::%'],
261262
onelineClauses,
262263
},
263264
};

test/singlestoredb.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import supportsCreateTable from './features/createTable.js';
99
import supportsCreateView from './features/createView.js';
1010
import supportsAlterTable from './features/alterTable.js';
1111
import supportsStrings from './features/strings.js';
12+
import dedent from 'dedent-js';
1213

1314
describe('SingleStoreDbFormatter', () => {
1415
const language = 'singlestoredb';
@@ -45,4 +46,67 @@ describe('SingleStoreDbFormatter', () => {
4546
modify: true,
4647
renameTo: true,
4748
});
49+
// it('allows operations in BETWEEN ranges', () => {
50+
// expect(format('SELECT SUM(extendedprice * discount) AS revenue FROM item WHERE discount BETWEEN 0.06 - 0.01 AND 0.06 + 0.01')).toBe(dedent`
51+
// SELECT
52+
// SUM(extendedprice * discount) AS revenue
53+
// FROM
54+
// item
55+
// WHERE
56+
// discount BETWEEN 0.06 - 0.01 AND 0.06 + 0.01
57+
// `);
58+
// });
59+
describe(`formats traversal of semi structured data`, () => {
60+
it(`formats '.' path-operator without spaces`, () => {
61+
expect(format(`SELECT TO_JSON(foo.*) AS foo_json FROM foo`)).toBe(dedent`
62+
SELECT
63+
TO_JSON(foo.*) AS foo_json
64+
FROM
65+
foo
66+
`);
67+
});
68+
it(`formats '::' path-operator without spaces`, () => {
69+
expect(format(`SELECT * FROM foo WHERE json_foo::bar = 'foobar'`)).toBe(dedent`
70+
SELECT
71+
*
72+
FROM
73+
foo
74+
WHERE
75+
json_foo::bar = 'foobar'
76+
`);
77+
});
78+
it(`formats '::$' conversion path-operator without spaces`, () => {
79+
expect(format(`SELECT * FROM foo WHERE json_foo::$bar = 'foobar'`)).toBe(dedent`
80+
SELECT
81+
*
82+
FROM
83+
foo
84+
WHERE
85+
json_foo::$bar = 'foobar'
86+
`);
87+
});
88+
it(`formats '::%' conversion path-operator without spaces`, () => {
89+
expect(format(`SELECT * FROM foo WHERE json_foo::%bar = 'foobar'`)).toBe(dedent`
90+
SELECT
91+
*
92+
FROM
93+
foo
94+
WHERE
95+
json_foo::%bar = 'foobar'
96+
`);
97+
});
98+
});
99+
describe(`formats custom type-cast operators`, () => {
100+
it(`formats ':>' type-cast operator`, () => {
101+
expect(format(`SELECT 1 :> DOUBLE AS foo`)).toBe(dedent`
102+
SELECT
103+
1 :> DOUBLE AS foo
104+
`);
105+
expect(format(`SELECT 1 !:> DOUBLE AS foo`)).toBe(dedent`
106+
SELECT
107+
1 !:> DOUBLE AS foo
108+
`);
109+
});
110+
});
111+
48112
});

0 commit comments

Comments
 (0)