diff --git a/src/languages/bigquery/bigquery.formatter.ts b/src/languages/bigquery/bigquery.formatter.ts index d162cfbf60..a9368adcb2 100644 --- a/src/languages/bigquery/bigquery.formatter.ts +++ b/src/languages/bigquery/bigquery.formatter.ts @@ -32,7 +32,6 @@ const reservedClauses = expandPhrases([ 'UPDATE SET', // Data definition, https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language 'CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS]', - 'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]', 'CLUSTER BY', 'FOR SYSTEM_TIME AS OF', // CREATE SNAPSHOT TABLE @@ -42,6 +41,8 @@ const reservedClauses = expandPhrases([ ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/src/languages/db2/db2.formatter.ts b/src/languages/db2/db2.formatter.ts index a9021831ad..e84e9c1fb0 100644 --- a/src/languages/db2/db2.formatter.ts +++ b/src/languages/db2/db2.formatter.ts @@ -36,10 +36,11 @@ const reservedClauses = expandPhrases([ 'INSERT', // Data definition 'CREATE [OR REPLACE] VIEW', - 'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]', // - update: 'UPDATE', 'WHERE CURRENT OF', diff --git a/src/languages/db2i/db2i.formatter.ts b/src/languages/db2i/db2i.formatter.ts index 1bdf258f7a..5c2a7a05b7 100644 --- a/src/languages/db2i/db2i.formatter.ts +++ b/src/languages/db2i/db2i.formatter.ts @@ -34,13 +34,14 @@ const reservedClauses = expandPhrases([ 'DELETE', 'INSERT', // Data definition - table - 'CREATE [OR REPLACE] TABLE', 'FOR SYSTEM NAME', // Data definition - view 'CREATE [OR REPLACE] [RECURSIVE] VIEW', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [OR REPLACE] TABLE', // - update: 'UPDATE', 'WHERE CURRENT OF', diff --git a/src/languages/hive/hive.formatter.ts b/src/languages/hive/hive.formatter.ts index 33386d5e7e..e62c8c827d 100644 --- a/src/languages/hive/hive.formatter.ts +++ b/src/languages/hive/hive.formatter.ts @@ -41,10 +41,11 @@ const reservedClauses = expandPhrases([ '[OVERWRITE] INTO TABLE', // Data definition 'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]', - 'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/src/languages/mariadb/mariadb.formatter.ts b/src/languages/mariadb/mariadb.formatter.ts index 7f2ee9ad44..a102f5ae2e 100644 --- a/src/languages/mariadb/mariadb.formatter.ts +++ b/src/languages/mariadb/mariadb.formatter.ts @@ -28,12 +28,13 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]', - 'CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]', // other 'RETURNING', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]', // - update: 'UPDATE [LOW_PRIORITY] [IGNORE]', // - delete: diff --git a/src/languages/mysql/mysql.formatter.ts b/src/languages/mysql/mysql.formatter.ts index 4bce901a96..378b9c7b61 100644 --- a/src/languages/mysql/mysql.formatter.ts +++ b/src/languages/mysql/mysql.formatter.ts @@ -28,10 +28,11 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]', - 'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]', // - update: 'UPDATE [LOW_PRIORITY] [IGNORE]', // - delete: diff --git a/src/languages/plsql/plsql.formatter.ts b/src/languages/plsql/plsql.formatter.ts index f73c33d2de..35880858bc 100644 --- a/src/languages/plsql/plsql.formatter.ts +++ b/src/languages/plsql/plsql.formatter.ts @@ -31,12 +31,13 @@ const reservedClauses = expandPhrases([ // Data definition 'CREATE [OR REPLACE] [NO FORCE | FORCE] [EDITIONING | EDITIONABLE | EDITIONABLE EDITIONING | NONEDITIONABLE] VIEW', 'CREATE MATERIALIZED VIEW', - 'CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE', // other 'RETURNING', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE', // - update: 'UPDATE [ONLY]', // - delete: diff --git a/src/languages/postgresql/postgresql.formatter.ts b/src/languages/postgresql/postgresql.formatter.ts index 6c6315d752..13e3453514 100644 --- a/src/languages/postgresql/postgresql.formatter.ts +++ b/src/languages/postgresql/postgresql.formatter.ts @@ -28,12 +28,13 @@ const reservedClauses = expandPhrases([ // Data definition 'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW', 'CREATE MATERIALIZED VIEW [IF NOT EXISTS]', - 'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]', // other 'RETURNING', ]); const onelineClauses = expandPhrases([ + // - create + 'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]', // - update: 'UPDATE [ONLY]', 'WHERE CURRENT OF', diff --git a/src/languages/redshift/redshift.formatter.ts b/src/languages/redshift/redshift.formatter.ts index 8c9dfb96fd..c00854c8c5 100644 --- a/src/languages/redshift/redshift.formatter.ts +++ b/src/languages/redshift/redshift.formatter.ts @@ -24,10 +24,11 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [OR REPLACE | MATERIALIZED] VIEW', - 'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/src/languages/singlestoredb/singlestoredb.formatter.ts b/src/languages/singlestoredb/singlestoredb.formatter.ts index a1f80a9fd6..9a9b3360a6 100644 --- a/src/languages/singlestoredb/singlestoredb.formatter.ts +++ b/src/languages/singlestoredb/singlestoredb.formatter.ts @@ -27,12 +27,13 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE VIEW', - 'CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [TEMPORARY] PROCEDURE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [EXTERNAL] FUNCTION', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/src/languages/snowflake/snowflake.formatter.ts b/src/languages/snowflake/snowflake.formatter.ts index c583a0b5ad..c91658a080 100644 --- a/src/languages/snowflake/snowflake.formatter.ts +++ b/src/languages/snowflake/snowflake.formatter.ts @@ -29,8 +29,6 @@ const reservedClauses = expandPhrases([ // - view 'CREATE [OR REPLACE] [SECURE] [RECURSIVE] VIEW [IF NOT EXISTS]', // - create/drop/merge table - 'CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]', - 'CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]', 'CLUSTER BY', '[WITH] {MASKING POLICY | TAG | ROW ACCESS POLICY}', 'COPY GRANTS', @@ -42,6 +40,9 @@ const reservedClauses = expandPhrases([ ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]', + 'CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/src/languages/spark/spark.formatter.ts b/src/languages/spark/spark.formatter.ts index fadbbfe878..198a4780a5 100644 --- a/src/languages/spark/spark.formatter.ts +++ b/src/languages/spark/spark.formatter.ts @@ -34,10 +34,11 @@ const reservedClauses = expandPhrases([ '[OVERWRITE] INTO TABLE', // Data definition 'CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]', - 'CREATE [EXTERNAL] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [EXTERNAL] TABLE [IF NOT EXISTS]', // - drop table: 'DROP TABLE [IF EXISTS]', // - alter table: diff --git a/src/languages/sql/sql.formatter.ts b/src/languages/sql/sql.formatter.ts index 95697e44a6..332b3de240 100644 --- a/src/languages/sql/sql.formatter.ts +++ b/src/languages/sql/sql.formatter.ts @@ -26,10 +26,11 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [RECURSIVE] VIEW', - 'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE', // - update: 'UPDATE', 'WHERE CURRENT OF', diff --git a/src/languages/sqlite/sqlite.formatter.ts b/src/languages/sqlite/sqlite.formatter.ts index b3c1c166e8..91c475ff7d 100644 --- a/src/languages/sqlite/sqlite.formatter.ts +++ b/src/languages/sqlite/sqlite.formatter.ts @@ -26,10 +26,11 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]', - 'CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]', // - update: 'UPDATE [OR ABORT | OR FAIL | OR IGNORE | OR REPLACE | OR ROLLBACK]', // - insert: diff --git a/src/languages/transactsql/transactsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts index 8f4091c8b0..578ad2e9e2 100644 --- a/src/languages/transactsql/transactsql.formatter.ts +++ b/src/languages/transactsql/transactsql.formatter.ts @@ -30,11 +30,12 @@ const reservedClauses = expandPhrases([ 'UPDATE SET', // Data definition 'CREATE [OR ALTER] [MATERIALIZED] VIEW', - 'CREATE TABLE', 'CREATE [OR ALTER] {PROC | PROCEDURE}', ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE TABLE', // - update: 'UPDATE', 'WHERE CURRENT OF', diff --git a/src/languages/trino/trino.formatter.ts b/src/languages/trino/trino.formatter.ts index d13c3e7030..1a4f8897ec 100644 --- a/src/languages/trino/trino.formatter.ts +++ b/src/languages/trino/trino.formatter.ts @@ -27,7 +27,6 @@ const reservedClauses = expandPhrases([ 'SET', // Data definition 'CREATE [OR REPLACE] [MATERIALIZED] VIEW', - 'CREATE TABLE [IF NOT EXISTS]', // MATCH_RECOGNIZE 'MATCH_RECOGNIZE', 'MEASURES', @@ -40,6 +39,8 @@ const reservedClauses = expandPhrases([ ]); const onelineClauses = expandPhrases([ + // - create: + 'CREATE TABLE [IF NOT EXISTS]', // - update: 'UPDATE', // - delete: diff --git a/test/behavesLikeMariaDbFormatter.ts b/test/behavesLikeMariaDbFormatter.ts index 9fe47ddd0e..873a99caf4 100644 --- a/test/behavesLikeMariaDbFormatter.ts +++ b/test/behavesLikeMariaDbFormatter.ts @@ -166,8 +166,7 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) { { keywordCase: 'upper' } ) ).toBe(dedent` - CREATE TABLE - account (id INT comment 'the most important column'); + CREATE TABLE account (id INT comment 'the most important column'); SELECT * diff --git a/test/bigquery.test.ts b/test/bigquery.test.ts index 2456953bcf..03309e060c 100644 --- a/test/bigquery.test.ts +++ b/test/bigquery.test.ts @@ -339,8 +339,7 @@ describe('BigQueryFormatter', () => { uris = ['gs://bucket/path1.csv'] )`; const expected = dedent` - CREATE EXTERNAL TABLE - dataset.CsvTable + CREATE EXTERNAL TABLE dataset.CsvTable WITH PARTITION COLUMNS (field_1 STRING, field_2 INT64) OPTIONS(format = 'CSV', uris = ['gs://bucket/path1.csv'])`; expect(format(input)).toBe(expected); diff --git a/test/features/constraints.ts b/test/features/constraints.ts index 4bda778842..52dc50a478 100644 --- a/test/features/constraints.ts +++ b/test/features/constraints.ts @@ -13,11 +13,10 @@ export default function supportsConstraints(format: FormatFn, actions: string[]) ); `) ).toBe(dedent` - CREATE TABLE - foo ( - update_time datetime ON UPDATE ${action}, - delete_time datetime ON DELETE ${action}, - ); + CREATE TABLE foo ( + update_time datetime ON UPDATE ${action}, + delete_time datetime ON DELETE ${action}, + ); `); }); }); diff --git a/test/features/createTable.ts b/test/features/createTable.ts index 508d9c1a86..b7e8fa64e2 100644 --- a/test/features/createTable.ts +++ b/test/features/createTable.ts @@ -15,8 +15,7 @@ export default function supportsCreateTable( ) { it('formats short CREATE TABLE', () => { expect(format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent` - CREATE TABLE - tbl (a INT PRIMARY KEY, b TEXT); + CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT); `); }); @@ -26,21 +25,19 @@ export default function supportsCreateTable( expect( format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, doggie INT NOT NULL);') ).toBe(dedent` - CREATE TABLE - tbl ( - a INT PRIMARY KEY, - b TEXT, - c INT NOT NULL, - doggie INT NOT NULL - ); + CREATE TABLE tbl ( + a INT PRIMARY KEY, + b TEXT, + c INT NOT NULL, + doggie INT NOT NULL + ); `); }); if (orReplace) { it('formats short CREATE OR REPLACE TABLE', () => { expect(format('CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent` - CREATE OR REPLACE TABLE - tbl (a INT PRIMARY KEY, b TEXT); + CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT); `); }); } @@ -48,8 +45,7 @@ export default function supportsCreateTable( if (ifNotExists) { it('formats short CREATE TABLE IF NOT EXISTS', () => { expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent` - CREATE TABLE IF NOT EXISTS - tbl (a INT PRIMARY KEY, b TEXT); + CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT); `); }); } @@ -59,11 +55,10 @@ export default function supportsCreateTable( expect( format(`CREATE TABLE tbl (a INT COMMENT 'Hello world!', b TEXT COMMENT 'Here we are!');`) ).toBe(dedent` - CREATE TABLE - tbl ( - a INT COMMENT 'Hello world!', - b TEXT COMMENT 'Here we are!' - ); + CREATE TABLE tbl ( + a INT COMMENT 'Hello world!', + b TEXT COMMENT 'Here we are!' + ); `); }); } @@ -71,8 +66,7 @@ export default function supportsCreateTable( if (tableComment) { it('formats short CREATE TABLE with comment', () => { expect(format(`CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!';`)).toBe(dedent` - CREATE TABLE - tbl (a INT, b TEXT) COMMENT = 'Hello, world!'; + CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!'; `); }); } diff --git a/test/features/createView.ts b/test/features/createView.ts index c368b7cb35..3d13ae80ba 100644 --- a/test/features/createView.ts +++ b/test/features/createView.ts @@ -61,8 +61,7 @@ export default function supportsCreateView( if (ifNotExists) { it('formats short CREATE TABLE IF NOT EXISTS', () => { expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent` - CREATE TABLE IF NOT EXISTS - tbl (a INT PRIMARY KEY, b TEXT); + CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT); `); }); } diff --git a/test/postgresql.test.ts b/test/postgresql.test.ts index 607f376a97..534a57c259 100644 --- a/test/postgresql.test.ts +++ b/test/postgresql.test.ts @@ -222,13 +222,12 @@ describe('PostgreSqlFormatter', () => { deleted_at TIME WITH TIME ZONE, modified_at TIMESTAMP(0) WITH TIME ZONE);`) ).toBe(dedent` - CREATE TABLE - time_table ( - id INT, - created_at TIMESTAMP WITH TIME ZONE, - deleted_at TIME WITH TIME ZONE, - modified_at TIMESTAMP(0) WITH TIME ZONE - ); + CREATE TABLE time_table ( + id INT, + created_at TIMESTAMP WITH TIME ZONE, + deleted_at TIME WITH TIME ZONE, + modified_at TIMESTAMP(0) WITH TIME ZONE + ); `); }); diff --git a/test/redshift.test.ts b/test/redshift.test.ts index c44a1d0859..6292dc7b29 100644 --- a/test/redshift.test.ts +++ b/test/redshift.test.ts @@ -2,24 +2,23 @@ import dedent from 'dedent-js'; import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js'; import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js'; - import supportsAlterTable from './features/alterTable.js'; +import supportsCommentOn from './features/commentOn.js'; +import supportsComments from './features/comments.js'; import supportsCreateTable from './features/createTable.js'; +import supportsCreateView from './features/createView.js'; +import supportsDeleteFrom from './features/deleteFrom.js'; import supportsDropTable from './features/dropTable.js'; +import supportsIdentifiers from './features/identifiers.js'; +import supportsInsertInto from './features/insertInto.js'; import supportsJoin from './features/join.js'; +import supportsLimiting from './features/limiting.js'; import supportsOperators from './features/operators.js'; -import supportsStrings from './features/strings.js'; -import supportsDeleteFrom from './features/deleteFrom.js'; -import supportsComments from './features/comments.js'; -import supportsCommentOn from './features/commentOn.js'; -import supportsIdentifiers from './features/identifiers.js'; -import supportsParams from './options/param.js'; import supportsSetOperations from './features/setOperations.js'; -import supportsLimiting from './features/limiting.js'; -import supportsInsertInto from './features/insertInto.js'; -import supportsUpdate from './features/update.js'; +import supportsStrings from './features/strings.js'; import supportsTruncateTable from './features/truncateTable.js'; -import supportsCreateView from './features/createView.js'; +import supportsUpdate from './features/update.js'; +import supportsParams from './options/param.js'; describe('RedshiftFormatter', () => { const language = 'redshift'; @@ -89,8 +88,7 @@ describe('RedshiftFormatter', () => { it('formats temp table name starting with #', () => { expect(format(`CREATE TABLE #tablename AS tbl;`)).toBe( dedent` - CREATE TABLE - #tablename AS tbl; + CREATE TABLE #tablename AS tbl; ` ); }); @@ -101,14 +99,13 @@ describe('RedshiftFormatter', () => { 'CREATE TABLE items (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, d INT NOT NULL, e INT NOT NULL) DISTKEY(created_at) SORTKEY(created_at);' ) ).toBe(dedent` - CREATE TABLE - items ( - a INT PRIMARY KEY, - b TEXT, - c INT NOT NULL, - d INT NOT NULL, - e INT NOT NULL - ) DISTKEY (created_at) SORTKEY (created_at); + CREATE TABLE items ( + a INT PRIMARY KEY, + b TEXT, + c INT NOT NULL, + d INT NOT NULL, + e INT NOT NULL + ) DISTKEY (created_at) SORTKEY (created_at); `); }); diff --git a/test/snowflake.test.ts b/test/snowflake.test.ts index 561c91b406..ecff64b3a0 100644 --- a/test/snowflake.test.ts +++ b/test/snowflake.test.ts @@ -176,11 +176,10 @@ describe('SnowflakeFormatter', () => { } ) ).toBe(dedent` - CREATE TABLE - tbl ( - first_column DOUBLE PRECISION, - second_column NUMBER (38, 0), - third STRING - );`); + CREATE TABLE tbl ( + first_column DOUBLE PRECISION, + second_column NUMBER (38, 0), + third STRING + );`); }); });