diff --git a/src/languages/singlestoredb/singlestoredb.formatter.ts b/src/languages/singlestoredb/singlestoredb.formatter.ts index 447251e3e..1188f96e2 100644 --- a/src/languages/singlestoredb/singlestoredb.formatter.ts +++ b/src/languages/singlestoredb/singlestoredb.formatter.ts @@ -254,10 +254,27 @@ export const singlestoredb: DialectOptions = { { quote: '``', prefixes: ['@'], requirePrefix: true }, ], lineCommentTypes: ['--', '#'], - operators: [':=', '&', '|', '^', '~', '<<', '>>', '<=>', '&&', '||'], + operators: [ + ':=', + '&', + '|', + '^', + '~', + '<<', + '>>', + '<=>', + '&&', + '||', + '::', + '::$', + '::%', + ':>', + '!:>', + ], postProcess, }, formatOptions: { + alwaysDenseOperators: ['::', '::$', '::%'], onelineClauses, }, }; diff --git a/test/singlestoredb.test.ts b/test/singlestoredb.test.ts index 5907f981a..4c25d2625 100644 --- a/test/singlestoredb.test.ts +++ b/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'; @@ -9,6 +10,7 @@ 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'; @@ -39,10 +41,65 @@ describe('SingleStoreDbFormatter', () => { 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 + `); + }); + }); });