Repository: sql-formatter-org/sql-formatter
Pull request #427 (2022-09-05 10:37:48)

Rename tsql to transactsql (keeping tsql as alias)
This is largely to sync the alphabetic ordering in wiki (Transact-SQL before Trino) with file order (trino before tsql).

Also I think "transactsql" is a clearer name to use, though T-SQL is a very common abbreviation of it.


Patch:
diff --git a/README.md b/README.md
index 7df55e95..8aa2ad8d 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ sql-formatter -h
 
 ```
 usage: sql-formatter [-h] [-o OUTPUT] \
-[-l {bigquery,db2,hive,mariadb,mysql,n1ql,plsql,postgresql,redshift,singlestoredb,spark,sql,sqlite,trino,tsql}] [-c CONFIG] [--version] [FILE]
+[-l {bigquery,db2,hive,mariadb,mysql,n1ql,plsql,postgresql,redshift,singlestoredb,spark,sql,sqlite,transactsql,trino,tsql}] [-c CONFIG] [--version] [FILE]
 
 SQL Formatter
 
diff --git a/docs/language.md b/docs/language.md
index 5b057d2c..97c5926d 100644
--- a/docs/language.md
+++ b/docs/language.md
@@ -17,8 +17,8 @@ Specifies the SQL dialect to use.
 - `"singlestoredb"` - [SingleStoreDB][]
 - `"spark"` - [Spark][]
 - `"sqlite"` - [SQLite][sqlite]
+- `"transactsql"` or `"tsql"` - [SQL Server Transact-SQL][tsql]
 - `"trino"` - [Trino][] / [Presto][]
-- `"tsql"` - [SQL Server Transact-SQL][tsql]
 - custom formatter class (see below)
 
 The default `"sql"` dialect is meant for cases where you don't know which dialect of SQL you're about to format.
diff --git a/src/languages/tsql/tsql.formatter.ts b/src/languages/transactsql/transactsql.formatter.ts
similarity index 96%
rename from src/languages/tsql/tsql.formatter.ts
rename to src/languages/transactsql/transactsql.formatter.ts
index 0ecb4fba..1214c5e9 100644
--- a/src/languages/tsql/tsql.formatter.ts
+++ b/src/languages/transactsql/transactsql.formatter.ts
@@ -1,8 +1,8 @@
 import { expandPhrases } from 'src/expandPhrases';
 import Formatter from 'src/formatter/Formatter';
 import Tokenizer from 'src/lexer/Tokenizer';
-import { functions } from './tsql.functions';
-import { keywords } from './tsql.keywords';
+import { functions } from './transactsql.functions';
+import { keywords } from './transactsql.keywords';
 
 const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);
 
@@ -213,7 +213,7 @@ const reservedJoins = expandPhrases([
 const reservedPhrases = expandPhrases(['ON DELETE', 'ON UPDATE', '{ROWS | RANGE} BETWEEN']);
 
 // https://docs.microsoft.com/en-us/sql/t-sql/language-reference?view=sql-server-ver15
-export default class TSqlFormatter extends Formatter {
+export default class TransactSqlFormatter extends Formatter {
   tokenizer() {
     return new Tokenizer({
       reservedCommands,
diff --git a/src/languages/tsql/tsql.functions.ts b/src/languages/transactsql/transactsql.functions.ts
similarity index 100%
rename from src/languages/tsql/tsql.functions.ts
rename to src/languages/transactsql/transactsql.functions.ts
diff --git a/src/languages/tsql/tsql.keywords.ts b/src/languages/transactsql/transactsql.keywords.ts
similarity index 100%
rename from src/languages/tsql/tsql.keywords.ts
rename to src/languages/transactsql/transactsql.keywords.ts
diff --git a/src/sqlFormatter.ts b/src/sqlFormatter.ts
index 114a6b4c..9dc4208e 100644
--- a/src/sqlFormatter.ts
+++ b/src/sqlFormatter.ts
@@ -11,7 +11,7 @@ import SparkFormatter from 'src/languages/spark/spark.formatter';
 import SqliteFormatter from 'src/languages/sqlite/sqlite.formatter';
 import SqlFormatter from 'src/languages/sql/sql.formatter';
 import TrinoFormatter from 'src/languages/trino/trino.formatter';
-import TSqlFormatter from 'src/languages/tsql/tsql.formatter';
+import TransactSqlFormatter from 'src/languages/transactsql/transactsql.formatter';
 import SingleStoreDbFormatter from './languages/singlestoredb/singlestoredb.formatter';
 
 import { FormatOptions } from './FormatOptions';
@@ -31,8 +31,9 @@ export const formatters = {
   spark: SparkFormatter,
   sql: SqlFormatter,
   sqlite: SqliteFormatter,
+  transactsql: TransactSqlFormatter,
   trino: TrinoFormatter,
-  tsql: TSqlFormatter,
+  tsql: TransactSqlFormatter, // alias for transactsql
 };
 export type SqlLanguage = keyof typeof formatters;
 export const supportedDialects = Object.keys(formatters);


Test patch:
diff --git a/test/tsql.test.ts b/test/transactsql.test.ts
similarity index 89%
rename from test/tsql.test.ts
rename to test/transactsql.test.ts
index 6d186d35..791d7fb9 100644
--- a/test/tsql.test.ts
+++ b/test/transactsql.test.ts
@@ -24,8 +24,8 @@ import supportsTruncateTable from './features/truncateTable';
 import supportsMergeInto from './features/mergeInto';
 import supportsCreateView from './features/createView';
 
-describe('TSqlFormatter', () => {
-  const language = 'tsql';
+describe('TransactSqlFormatter', () => {
+  const language = 'transactsql';
   const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });
 
   behavesLikeSqlFormatter(format);
@@ -69,17 +69,13 @@ describe('TSqlFormatter', () => {
   supportsWindow(format);
   supportsLimiting(format, { offset: true, fetchFirst: true, fetchNext: true });
 
-  // TODO: The following are duplicated from StandardSQLFormatter test
-
-  it('formats INSERT without INTO', () => {
-    const result = format(
-      "INSERT Customers (ID, MoneyBalance, Address, City) VALUES (12,-123.4, 'Skagen 2111','Stv');"
-    );
+  it('supports language:tsql alias', () => {
+    const result = originalFormat('SELECT [my column] FROM [my table];', { language: 'tsql' });
     expect(result).toBe(dedent`
-      INSERT
-        Customers (ID, MoneyBalance, Address, City)
-      VALUES
-        (12, -123.4, 'Skagen 2111', 'Stv');
+      SELECT
+        [my column]
+      FROM
+        [my table];
     `);
   });