Skip to content

Commit

Permalink
Merge PR #490: Format ALTER TABLE and some other statements using one…
Browse files Browse the repository at this point in the history
…line style
  • Loading branch information
nene committed Oct 4, 2022
2 parents cdfbf33 + 5237348 commit 4c60475
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 367 deletions.
30 changes: 17 additions & 13 deletions src/languages/bigquery/bigquery.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,28 @@ const reservedClauses = expandPhrases([
'INSERT [INTO]',
'VALUES',
// - update:
'UPDATE',
'SET',
// - delete:
'DELETE [FROM]',
// - merge:
'MERGE [INTO]',
'WHEN [NOT] MATCHED [BY SOURCE | BY TARGET] [THEN]',
'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
'WITH CONNECTION',
'WITH PARTITION COLUMNS',
'REMOTE WITH CONNECTION',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE',
// - delete:
'DELETE [FROM]',
// - drop table:
'DROP [SNAPSHOT | EXTERNAL] TABLE [IF EXISTS]',
// - alter table:
'ALTER TABLE [IF EXISTS]',
Expand All @@ -49,19 +60,12 @@ const reservedClauses = expandPhrases([
'SET OPTIONS', // for alter column
'DROP NOT NULL', // for alter column
'SET DATA TYPE', // for alter column

'CLUSTER BY',
'FOR SYSTEM_TIME AS OF', // CREATE SNAPSHOT TABLE
'WITH CONNECTION',
'WITH PARTITION COLUMNS',
'REMOTE WITH CONNECTION',
// - alter schema
'ALTER SCHEMA [IF EXISTS]',

// - alter view
'ALTER [MATERIALIZED] VIEW [IF EXISTS]',
// - alter bi_capacity
'ALTER BI_CAPACITY',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE TABLE',
// - create schema
Expand Down
18 changes: 10 additions & 8 deletions src/languages/db2/db2.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ const reservedClauses = expandPhrases([
'INSERT INTO',
'VALUES',
// - update:
'UPDATE',
'SET',
'WHERE CURRENT OF',
'WITH {RR | RS | CS | UR}',
// - delete:
'DELETE FROM',
// - merge:
'MERGE INTO',
'WHEN [NOT] MATCHED [THEN]',
Expand All @@ -36,6 +31,16 @@ const reservedClauses = expandPhrases([
// Data definition
'CREATE [OR REPLACE] VIEW',
'CREATE [GLOBAL TEMPORARY] TABLE',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE',
'WHERE CURRENT OF',
'WITH {RR | RS | CS | UR}',
// - delete:
'DELETE FROM',
// - drop table:
'DROP TABLE [HIERARCHY]',
// alter table:
'ALTER TABLE',
Expand All @@ -46,9 +51,6 @@ const reservedClauses = expandPhrases([
'SET DATA TYPE', // for alter column
'SET NOT NULL', // for alter column
'DROP {IDENTITY | EXPRESSION | DEFAULT | NOT NULL}', // for alter column
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// other
Expand Down
14 changes: 8 additions & 6 deletions src/languages/hive/hive.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ const reservedClauses = expandPhrases([
'INSERT INTO [TABLE]',
'VALUES',
// - update:
'UPDATE',
'SET',
// - delete:
'DELETE FROM',
// - merge:
'MERGE INTO',
'WHEN [NOT] MATCHED [THEN]',
Expand All @@ -47,13 +44,18 @@ const reservedClauses = expandPhrases([
// Data definition
'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]',
'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE',
// - delete:
'DELETE FROM',
// - drop table:
'DROP TABLE [IF EXISTS]',
// - alter table:
'ALTER TABLE',
'RENAME TO',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// other
Expand Down
18 changes: 10 additions & 8 deletions src/languages/mariadb/mariadb.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ const reservedClauses = expandPhrases([
'REPLACE [LOW_PRIORITY | DELAYED] [INTO]',
'VALUES',
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
'SET',
// - delete:
'DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM',
// 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([
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
// - delete:
'DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM',
// - drop table:
'DROP [TEMPORARY] TABLE [IF EXISTS]',
// - alter table:
'ALTER [ONLINE] [IGNORE] TABLE [IF EXISTS]',
Expand All @@ -44,11 +51,6 @@ const reservedClauses = expandPhrases([
'ALTER [COLUMN]',
'{SET | DROP} DEFAULT', // for alter column
'SET {VISIBLE | INVISIBLE}', // for alter column
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// https://mariadb.com/docs/reference/mdb/sql-statements/
Expand Down
14 changes: 8 additions & 6 deletions src/languages/mysql/mysql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ const reservedClauses = expandPhrases([
'REPLACE [LOW_PRIORITY | DELAYED] [INTO]',
'VALUES',
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
'SET',
// - delete:
'DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM',
// Data definition
'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]',
'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
// - delete:
'DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM',
// - drop table:
'DROP [TEMPORARY] TABLE [IF EXISTS]',
// - alter table:
'ALTER TABLE',
Expand All @@ -43,9 +48,6 @@ const reservedClauses = expandPhrases([
'RENAME COLUMN',
'ALTER [COLUMN]',
'{SET | DROP} DEFAULT', // for alter column
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// https://dev.mysql.com/doc/refman/8.0/en/sql-statements.html
Expand Down
10 changes: 6 additions & 4 deletions src/languages/n1ql/n1ql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ const reservedClauses = expandPhrases([
'INSERT INTO',
'VALUES',
// - update:
'UPDATE',
'SET',
// - delete:
'DELETE FROM',
// - merge:
'MERGE INTO',
'WHEN [NOT] MATCHED THEN',
'UPDATE SET',
'INSERT',
// other
'USE KEYS',
'NEST',
'UNNEST',
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE',
// - delete:
'DELETE FROM',
// - set schema:
'SET SCHEMA',
// https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html
'ADVISE',
Expand Down Expand Up @@ -74,6 +75,7 @@ const onelineClauses = expandPhrases([
'LET',
'SET CURRENT SCHEMA',
'SHOW',
'USE [PRIMARY] KEYS',
]);

const reservedSetOperations = expandPhrases(['UNION [ALL]', 'EXCEPT [ALL]', 'INTERSECT [ALL]']);
Expand Down
18 changes: 10 additions & 8 deletions src/languages/plsql/plsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ const reservedClauses = expandPhrases([
'INSERT [INTO | ALL INTO]',
'VALUES',
// - update:
'UPDATE [ONLY]',
'SET',
// - delete:
'DELETE FROM [ONLY]',
// - merge:
'MERGE [INTO]',
'WHEN [NOT] MATCHED [THEN]',
Expand All @@ -37,6 +34,16 @@ const reservedClauses = expandPhrases([
'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([
// - update:
'UPDATE [ONLY]',
// - delete:
'DELETE FROM [ONLY]',
// - drop table:
'DROP TABLE',
// - alter table:
'ALTER TABLE',
Expand All @@ -45,11 +52,6 @@ const reservedClauses = expandPhrases([
'MODIFY',
'RENAME TO',
'RENAME COLUMN',
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE TABLE',
// other
Expand Down
20 changes: 11 additions & 9 deletions src/languages/postgresql/postgresql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ const reservedClauses = expandPhrases([
'INSERT INTO',
'VALUES',
// - update:
'UPDATE [ONLY]',
'SET',
'WHERE CURRENT OF',
// - delete:
'DELETE FROM [ONLY]',
// 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([
// - update:
'UPDATE [ONLY]',
'WHERE CURRENT OF',
// - delete:
'DELETE FROM [ONLY]',
// - drop table:
'DROP TABLE [IF EXISTS]',
// - alter table:
'ALTER TABLE [IF EXISTS] [ONLY]',
Expand All @@ -46,11 +53,6 @@ const reservedClauses = expandPhrases([
'[SET DATA] TYPE', // for alter column
'{SET | DROP} DEFAULT', // for alter column
'{SET | DROP} NOT NULL', // for alter column
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE] [ONLY]',
// other
Expand Down
14 changes: 8 additions & 6 deletions src/languages/redshift/redshift.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ const reservedClauses = expandPhrases([
'INSERT INTO',
'VALUES',
// - update:
'UPDATE',
'SET',
// - delete:
'DELETE [FROM]',
// Data definition
'CREATE [OR REPLACE | MATERIALIZED] VIEW',
'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - update:
'UPDATE',
// - delete:
'DELETE [FROM]',
// - drop table:
'DROP TABLE [IF EXISTS]',
// - alter table:
'ALTER TABLE',
Expand All @@ -41,9 +46,6 @@ const reservedClauses = expandPhrases([
'ALTER COLUMN',
'TYPE', // for alter column
'ENCODE', // for alter column
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// https://docs.aws.amazon.com/redshift/latest/dg/c_SQL_commands.html
Expand Down
14 changes: 8 additions & 6 deletions src/languages/singlestoredb/singlestoredb.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ const reservedClauses = expandPhrases([
'VALUES',
'REPLACE [INTO]',
// - update:
'UPDATE',
'SET',
// - delete:
'DELETE [FROM]',
// 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([
// - update:
'UPDATE',
// - delete:
'DELETE [FROM]',
// - drop table:
'DROP [TEMPORARY] TABLE [IF EXISTS]',
// - alter table:
'ALTER [ONLINE] TABLE',
Expand All @@ -43,9 +48,6 @@ const reservedClauses = expandPhrases([
'MODIFY [COLUMN]',
'CHANGE',
'RENAME [TO | AS]',
]);

const onelineClauses = expandPhrases([
// - truncate:
'TRUNCATE [TABLE]',
// https://docs.singlestore.com/managed-service/en/reference/sql-reference.html
Expand Down

0 comments on commit 4c60475

Please sign in to comment.