Skip to content

Commit 9dc27f1

Browse files
authored
Merge pull request #18 from mathsalmi/mssql_keywords
Add TSQL (SQL Server) keywords and tests
2 parents 2fa9f7c + 59b6ddc commit 9dc27f1

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/languages/StandardSqlFormatter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ const reservedWords = [
4343

4444
const reservedToplevelWords = [
4545
"ADD", "AFTER", "ALTER COLUMN", "ALTER TABLE", "DELETE FROM", "EXCEPT", "FROM", "GROUP BY", "HAVING", "INSERT INTO", "INTERSECT",
46-
"LIMIT", "MODIFY", "ORDER BY", "SELECT", "SET CURRENT SCHEMA", "SET SCHEMA", "SET", "UNION ALL", "UNION", "UPDATE", "VALUES", "WHERE"
46+
"LIMIT", "MODIFY", "ORDER BY", "SELECT", "SET CURRENT SCHEMA", "SET SCHEMA", "SET", "UNION ALL", "UNION", "UPDATE", "VALUES", "WHERE",
47+
"GO"
4748
];
4849

4950
const reservedNewlineWords = [
50-
"AND", "INNER JOIN", "JOIN", "LEFT JOIN", "LEFT OUTER JOIN", "OR", "OUTER JOIN", "RIGHT JOIN", "RIGHT OUTER JOIN", "XOR"
51+
"AND", "INNER JOIN", "JOIN", "LEFT JOIN", "LEFT OUTER JOIN", "OR", "OUTER JOIN", "RIGHT JOIN", "RIGHT OUTER JOIN", "XOR",
52+
"CROSS JOIN", "CROSS APPLY", "OUTER APPLY"
5153
];
5254

5355
let tokenizer;

test/StandardSqlFormatterTest.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,63 @@ describe("StandardSqlFormatter", function() {
157157
" third;\n"
158158
);
159159
});
160+
161+
it("formats query with GO batch separator", function() {
162+
const result = sqlFormatter.format("SELECT 1 GO SELECT 2", {
163+
language: "sql",
164+
params: ["first", "second", "third"]
165+
});
166+
expect(result).toBe(
167+
"SELECT\n" +
168+
" 1\n" +
169+
"GO\n" +
170+
"SELECT\n" +
171+
" 2\n"
172+
);
173+
});
174+
175+
it("formats SELECT query with CROSS JOIN", function() {
176+
const result = sqlFormatter.format("SELECT a, b FROM t CROSS JOIN t2 on t.id = t2.id_t", {
177+
language: "sql",
178+
params: ["first", "second", "third"]
179+
});
180+
expect(result).toBe(
181+
"SELECT\n" +
182+
" a,\n" +
183+
" b\n" +
184+
"FROM\n" +
185+
" t\n" +
186+
" CROSS JOIN t2 on t.id = t2.id_t\n"
187+
);
188+
});
189+
190+
it("formats SELECT query with CROSS APPLY", function() {
191+
const result = sqlFormatter.format("SELECT a, b FROM t CROSS APPLY fn(t.id)", {
192+
language: "sql",
193+
params: ["first", "second", "third"]
194+
});
195+
expect(result).toBe(
196+
"SELECT\n" +
197+
" a,\n" +
198+
" b\n" +
199+
"FROM\n" +
200+
" t\n" +
201+
" CROSS APPLY fn(t.id)\n"
202+
);
203+
});
204+
205+
it("formats SELECT query with OUTER APPLY", function() {
206+
const result = sqlFormatter.format("SELECT a, b FROM t OUTER APPLY fn(t.id)", {
207+
language: "sql",
208+
params: ["first", "second", "third"]
209+
});
210+
expect(result).toBe(
211+
"SELECT\n" +
212+
" a,\n" +
213+
" b\n" +
214+
"FROM\n" +
215+
" t\n" +
216+
" OUTER APPLY fn(t.id)\n"
217+
);
218+
});
160219
});

0 commit comments

Comments
 (0)