Skip to content

Commit d6e7866

Browse files
committed
Format FOR-clause in Transact-SQL
1 parent 4cec5e9 commit d6e7866

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/languages/transactsql/transactsql.formatter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const reservedClauses = expandPhrases([
1818
'ORDER BY',
1919
'OFFSET',
2020
'FETCH {FIRST | NEXT}',
21+
'FOR {BROWSE | XML | JSON}',
2122
'OPTION',
2223
// Data manipulation
2324
// - insert:

test/transactsql.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ describe('TransactSqlFormatter', () => {
148148
`);
149149
});
150150

151+
it('formats SELECT ... FOR BROWSE', () => {
152+
expect(format('SELECT col FOR BROWSE')).toBe(dedent`
153+
SELECT
154+
col
155+
FOR BROWSE
156+
`);
157+
});
158+
159+
it('formats SELECT ... FOR XML', () => {
160+
expect(format("SELECT col FOR XML PATH('Employee'), ROOT('Employees')")).toBe(dedent`
161+
SELECT
162+
col
163+
FOR XML
164+
PATH ('Employee'),
165+
ROOT ('Employees')
166+
`);
167+
});
168+
169+
it('formats SELECT ... FOR JSON', () => {
170+
expect(format('SELECT col FOR JSON PATH, WITHOUT_ARRAY_WRAPPER')).toBe(dedent`
171+
SELECT
172+
col
173+
FOR JSON
174+
PATH,
175+
WITHOUT_ARRAY_WRAPPER
176+
`);
177+
});
178+
151179
it('formats goto labels', () => {
152180
const result = format(
153181
`InfiniLoop:

0 commit comments

Comments
 (0)