Skip to content

Commit

Permalink
Add INTO Clause and Remove Invalid Data Definition (#609)
Browse files Browse the repository at this point in the history
Reverting a change I had made previously and adding `INTO` as a reserved
clause.
  • Loading branch information
nene authored Jun 14, 2023
2 parents 7f48f15 + 5939b1b commit 851af81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/languages/transactsql/transactsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);
const reservedClauses = expandPhrases([
// queries
'WITH',
'INTO',
'FROM',
'WHERE',
'GROUP BY',
Expand All @@ -29,8 +30,8 @@ const reservedClauses = expandPhrases([
'UPDATE SET',
// Data definition
'CREATE [OR ALTER] [MATERIALIZED] VIEW',
'CREATE [OR ALTER] TABLE',
'CREATE [OR ALTER] PROCEDURE',
'CREATE TABLE',
'CREATE [OR ALTER] {PROC | PROCEDURE}',
]);

const onelineClauses = expandPhrases([
Expand Down
29 changes: 13 additions & 16 deletions test/transactsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,24 @@ describe('TransactSqlFormatter', () => {
`);
});

it('formats SET NOCOUNT ON; GO CREATE OR ALTER TABLE', () => {
const result = format('SET NOCOUNT ON; GO CREATE OR ALTER TABLE t');
it('formats GO CREATE OR ALTER PROCEDURE', () => {
const result = format('GO CREATE OR ALTER PROCEDURE p');
expect(result).toBe(dedent`
SET
NOCOUNT ON;
GO
CREATE OR ALTER TABLE
t
GO
CREATE OR ALTER PROCEDURE
p
`);
});

it('formats SET NOCOUNT ON; GO CREATE OR ALTER PROCEDURE', () => {
const result = format('SET NOCOUNT ON; GO CREATE OR ALTER PROCEDURE p');
it('formats SELECT ... INTO clause', () => {
const result = format('SELECT col INTO #temp FROM tbl');
expect(result).toBe(dedent`
SET
NOCOUNT ON;
GO
CREATE OR ALTER PROCEDURE
p
SELECT
col
INTO
#temp
FROM
tbl
`);
});
});

0 comments on commit 851af81

Please sign in to comment.