diff --git a/src/dialect.ts b/src/dialect.ts index 7a093387ce..a4ad930170 100644 --- a/src/dialect.ts +++ b/src/dialect.ts @@ -42,4 +42,7 @@ const processDialectFormatOptions = ( ): ProcessedDialectFormatOptions => ({ alwaysDenseOperators: options.alwaysDenseOperators || [], onelineClauses: Object.fromEntries(options.onelineClauses.map(name => [name, true])), + tabularOnelineClauses: Object.fromEntries( + (options.tabularOnelineClauses ?? options.onelineClauses).map(name => [name, true]) + ), }); diff --git a/src/formatter/ExpressionFormatter.ts b/src/formatter/ExpressionFormatter.ts index 8a18f7a4bc..a306e22fd1 100644 --- a/src/formatter/ExpressionFormatter.ts +++ b/src/formatter/ExpressionFormatter.ts @@ -50,6 +50,8 @@ export interface DialectFormatOptions { alwaysDenseOperators?: string[]; // List of clauses that should be formatted on a single line onelineClauses: string[]; + // List of clauses that should be formatted on a single line in tabular style + tabularOnelineClauses?: string[]; } // Contains the same data as DialectFormatOptions, @@ -57,6 +59,7 @@ export interface DialectFormatOptions { export interface ProcessedDialectFormatOptions { alwaysDenseOperators: string[]; onelineClauses: Record; + tabularOnelineClauses: Record; } /** Formats a generic SQL expression */ @@ -255,7 +258,11 @@ export default class ExpressionFormatter { } private isOnelineClause(node: ClauseNode): boolean { - return this.dialectCfg.onelineClauses[node.nameKw.text]; + if (isTabularStyle(this.cfg)) { + return this.dialectCfg.tabularOnelineClauses[node.nameKw.text]; + } else { + return this.dialectCfg.onelineClauses[node.nameKw.text]; + } } private formatClauseInIndentedStyle(node: ClauseNode) { diff --git a/src/languages/bigquery/bigquery.formatter.ts b/src/languages/bigquery/bigquery.formatter.ts index 10663428b9..5b40bc13d0 100644 --- a/src/languages/bigquery/bigquery.formatter.ts +++ b/src/languages/bigquery/bigquery.formatter.ts @@ -38,10 +38,13 @@ const reservedClauses = expandPhrases([ 'REMOTE WITH CONNECTION', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases([ + 'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ // - create: // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language - 'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS]', // - update: 'UPDATE', @@ -160,7 +163,7 @@ export const bigquery: DialectOptions = { name: 'bigquery', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...tabularOnelineClauses, ...standardOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -187,7 +190,8 @@ export const bigquery: DialectOptions = { postProcess, }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/db2/db2.formatter.ts b/src/languages/db2/db2.formatter.ts index b420d18e50..dfe5815e0a 100644 --- a/src/languages/db2/db2.formatter.ts +++ b/src/languages/db2/db2.formatter.ts @@ -36,9 +36,12 @@ const reservedClauses = expandPhrases([ 'INSERT', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [OR REPLACE] VIEW', // - update: 'UPDATE', @@ -261,7 +264,7 @@ export const db2: DialectOptions = { name: 'db2', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -298,6 +301,7 @@ export const db2: DialectOptions = { ], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/db2i/db2i.formatter.ts b/src/languages/db2i/db2i.formatter.ts index 51abe10c95..de4900a805 100644 --- a/src/languages/db2i/db2i.formatter.ts +++ b/src/languages/db2i/db2i.formatter.ts @@ -37,9 +37,10 @@ const reservedClauses = expandPhrases([ 'FOR SYSTEM NAME', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE [OR REPLACE] TABLE']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE [OR REPLACE] TABLE', 'CREATE [OR REPLACE] [RECURSIVE] VIEW', // - update: 'UPDATE', @@ -157,7 +158,7 @@ export const db2i: DialectOptions = { name: 'db2i', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -177,6 +178,7 @@ export const db2i: DialectOptions = { operators: ['**', '¬=', '¬>', '¬<', '!>', '!<', '||', '=>'], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/hive/hive.formatter.ts b/src/languages/hive/hive.formatter.ts index 256f0cbfd9..4e6a9e1cf6 100644 --- a/src/languages/hive/hive.formatter.ts +++ b/src/languages/hive/hive.formatter.ts @@ -41,9 +41,12 @@ const reservedClauses = expandPhrases([ '[OVERWRITE] INTO TABLE', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]', // - update: 'UPDATE', @@ -86,7 +89,7 @@ export const hive: DialectOptions = { name: 'hive', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -100,6 +103,7 @@ export const hive: DialectOptions = { operators: ['%', '~', '^', '|', '&', '<=>', '==', '!', '||'], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/mariadb/mariadb.formatter.ts b/src/languages/mariadb/mariadb.formatter.ts index 3a5c80b81b..d1384da022 100644 --- a/src/languages/mariadb/mariadb.formatter.ts +++ b/src/languages/mariadb/mariadb.formatter.ts @@ -30,9 +30,12 @@ const reservedClauses = expandPhrases([ 'RETURNING', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]', // - update: 'UPDATE [LOW_PRIORITY] [IGNORE]', @@ -269,7 +272,7 @@ export const mariadb: DialectOptions = { name: 'mariadb', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -311,6 +314,7 @@ export const mariadb: DialectOptions = { postProcess, }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/mysql/mysql.formatter.ts b/src/languages/mysql/mysql.formatter.ts index 71082775ff..501f0707d8 100644 --- a/src/languages/mysql/mysql.formatter.ts +++ b/src/languages/mysql/mysql.formatter.ts @@ -28,9 +28,10 @@ const reservedClauses = expandPhrases([ 'SET', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE [TEMPORARY] TABLE [IF NOT EXISTS]']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]', // - update: 'UPDATE [LOW_PRIORITY] [IGNORE]', @@ -236,7 +237,7 @@ export const mysql: DialectOptions = { name: 'mysql', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -280,6 +281,7 @@ export const mysql: DialectOptions = { postProcess, }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/plsql/plsql.formatter.ts b/src/languages/plsql/plsql.formatter.ts index 00927df9fc..0618e0c82a 100644 --- a/src/languages/plsql/plsql.formatter.ts +++ b/src/languages/plsql/plsql.formatter.ts @@ -32,9 +32,12 @@ const reservedClauses = expandPhrases([ 'RETURNING', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [OR REPLACE] [NO FORCE | FORCE] [EDITIONING | EDITIONABLE | EDITIONABLE EDITIONING | NONEDITIONABLE] VIEW', 'CREATE MATERIALIZED VIEW', // - update: @@ -85,7 +88,7 @@ export const plsql: DialectOptions = { name: 'plsql', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -122,7 +125,8 @@ export const plsql: DialectOptions = { }, formatOptions: { alwaysDenseOperators: ['@'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/postgresql/postgresql.formatter.ts b/src/languages/postgresql/postgresql.formatter.ts index 32821c9ecf..c120750398 100644 --- a/src/languages/postgresql/postgresql.formatter.ts +++ b/src/languages/postgresql/postgresql.formatter.ts @@ -29,9 +29,12 @@ const reservedClauses = expandPhrases([ 'RETURNING', ]); -const onelineClauses = expandPhrases([ - // - create +const standardOnelineClauses = expandPhrases([ 'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create 'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW', 'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]', // - update: @@ -256,7 +259,7 @@ export const postgresql: DialectOptions = { name: 'postgresql', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -364,6 +367,7 @@ export const postgresql: DialectOptions = { }, formatOptions: { alwaysDenseOperators: ['::', ':'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/redshift/redshift.formatter.ts b/src/languages/redshift/redshift.formatter.ts index 83b83fd45b..9c2d573bf7 100644 --- a/src/languages/redshift/redshift.formatter.ts +++ b/src/languages/redshift/redshift.formatter.ts @@ -24,9 +24,12 @@ const reservedClauses = expandPhrases([ 'SET', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [OR REPLACE | MATERIALIZED] VIEW', // - update: 'UPDATE', @@ -143,7 +146,7 @@ export const redshift: DialectOptions = { name: 'redshift', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -172,6 +175,7 @@ export const redshift: DialectOptions = { }, formatOptions: { alwaysDenseOperators: ['::'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/singlestoredb/singlestoredb.formatter.ts b/src/languages/singlestoredb/singlestoredb.formatter.ts index 658b6a7026..819bccdd1b 100644 --- a/src/languages/singlestoredb/singlestoredb.formatter.ts +++ b/src/languages/singlestoredb/singlestoredb.formatter.ts @@ -30,9 +30,12 @@ const reservedClauses = expandPhrases([ 'CREATE [OR REPLACE] [EXTERNAL] FUNCTION', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE VIEW', // - update: 'UPDATE', @@ -238,7 +241,7 @@ export const singlestoredb: DialectOptions = { name: 'singlestoredb', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -280,6 +283,7 @@ export const singlestoredb: DialectOptions = { }, formatOptions: { alwaysDenseOperators: ['::', '::$', '::%'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/snowflake/snowflake.formatter.ts b/src/languages/snowflake/snowflake.formatter.ts index a8952c204f..d8b57d9fa2 100644 --- a/src/languages/snowflake/snowflake.formatter.ts +++ b/src/languages/snowflake/snowflake.formatter.ts @@ -36,10 +36,13 @@ const reservedClauses = expandPhrases([ 'WHEN NOT MATCHED THEN INSERT', ]); -const onelineClauses = expandPhrases([ - // - create: +const standardOnelineClauses = expandPhrases([ 'CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create: 'CREATE [OR REPLACE] [SECURE] [RECURSIVE] VIEW [IF NOT EXISTS]', // - update: 'UPDATE', @@ -298,7 +301,7 @@ export const snowflake: DialectOptions = { name: 'snowflake', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -331,6 +334,7 @@ export const snowflake: DialectOptions = { }, formatOptions: { alwaysDenseOperators: [':', '::'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/spark/spark.formatter.ts b/src/languages/spark/spark.formatter.ts index b241ef230a..64e64f1a95 100644 --- a/src/languages/spark/spark.formatter.ts +++ b/src/languages/spark/spark.formatter.ts @@ -34,9 +34,10 @@ const reservedClauses = expandPhrases([ '[OVERWRITE] INTO TABLE', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE [EXTERNAL] TABLE [IF NOT EXISTS]']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE [EXTERNAL] TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]', // - drop table: 'DROP TABLE [IF EXISTS]', @@ -122,7 +123,7 @@ export const spark: DialectOptions = { name: 'spark', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -143,7 +144,8 @@ export const spark: DialectOptions = { postProcess, }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/sql/sql.formatter.ts b/src/languages/sql/sql.formatter.ts index 1405e57db3..765f4c79af 100644 --- a/src/languages/sql/sql.formatter.ts +++ b/src/languages/sql/sql.formatter.ts @@ -26,9 +26,10 @@ const reservedClauses = expandPhrases([ 'SET', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE', 'CREATE [RECURSIVE] VIEW', // - update: 'UPDATE', @@ -77,7 +78,7 @@ export const sql: DialectOptions = { name: 'sql', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -93,6 +94,7 @@ export const sql: DialectOptions = { operators: ['||'], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/sqlite/sqlite.formatter.ts b/src/languages/sqlite/sqlite.formatter.ts index 46ac0fb5fb..5d7c10c05e 100644 --- a/src/languages/sqlite/sqlite.formatter.ts +++ b/src/languages/sqlite/sqlite.formatter.ts @@ -26,9 +26,10 @@ const reservedClauses = expandPhrases([ 'SET', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]', 'CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]', // - update: 'UPDATE [OR ABORT | OR FAIL | OR IGNORE | OR REPLACE | OR ROLLBACK]', @@ -68,7 +69,7 @@ export const sqlite: DialectOptions = { name: 'sqlite', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -87,6 +88,7 @@ export const sqlite: DialectOptions = { operators: ['%', '~', '&', '|', '<<', '>>', '==', '->', '->>', '||'], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/transactsql/transactsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts index 512f13415f..415a602cfc 100644 --- a/src/languages/transactsql/transactsql.formatter.ts +++ b/src/languages/transactsql/transactsql.formatter.ts @@ -34,9 +34,10 @@ const reservedClauses = expandPhrases([ 'CREATE [OR ALTER] {PROC | PROCEDURE}', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE TABLE']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE TABLE', 'CREATE [OR ALTER] [MATERIALIZED] VIEW', // - update: 'UPDATE', @@ -228,7 +229,7 @@ export const transactsql: DialectOptions = { name: 'transactsql', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -263,6 +264,7 @@ export const transactsql: DialectOptions = { }, formatOptions: { alwaysDenseOperators: ['::'], - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/src/languages/trino/trino.formatter.ts b/src/languages/trino/trino.formatter.ts index ab67a59ec2..68ac8009c7 100644 --- a/src/languages/trino/trino.formatter.ts +++ b/src/languages/trino/trino.formatter.ts @@ -36,9 +36,10 @@ const reservedClauses = expandPhrases([ 'DEFINE', ]); -const onelineClauses = expandPhrases([ +const standardOnelineClauses = expandPhrases(['CREATE TABLE [IF NOT EXISTS]']); + +const tabularOnelineClauses = expandPhrases([ // - create: - 'CREATE TABLE [IF NOT EXISTS]', 'CREATE [OR REPLACE] [MATERIALIZED] VIEW', // - update: 'UPDATE', @@ -128,7 +129,7 @@ export const trino: DialectOptions = { name: 'trino', tokenizerOptions: { reservedSelect, - reservedClauses: [...reservedClauses, ...onelineClauses], + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], reservedSetOperations, reservedJoins, reservedPhrases, @@ -163,6 +164,7 @@ export const trino: DialectOptions = { ], }, formatOptions: { - onelineClauses, + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, }, }; diff --git a/test/features/createTable.ts b/test/features/createTable.ts index 96cc0c0803..f0749eeca3 100644 --- a/test/features/createTable.ts +++ b/test/features/createTable.ts @@ -67,4 +67,21 @@ export default function supportsCreateTable(format: FormatFn, cfg: CreateTableCo `); }); } + + it('correctly indents CREATE TABLE in tabular style', () => { + expect( + format( + `CREATE TABLE foo ( + id INT PRIMARY KEY NOT NULL, + fname VARCHAR NOT NULL + );`, + { indentStyle: 'tabularLeft' } + ) + ).toBe(dedent` + CREATE TABLE foo ( + id INT PRIMARY KEY NOT NULL, + fname VARCHAR NOT NULL + ); + `); + }); }