Skip to content

Commit f0174e6

Browse files
committed
Format DO statement
1 parent cba381f commit f0174e6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/syntax/do.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { DoStmt } from "sql-parser-cst";
2+
import { CstToDocMap } from "../CstToDocMap";
3+
4+
export const doMap: CstToDocMap<DoStmt> = {
5+
do_stmt: (print) => print.spaced(["doKw", "language", "body"]),
6+
};

src/syntax/transformMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createTableMap } from "./create_table";
1010
import { dataTypeMap } from "./data_type";
1111
import { dclMap } from "./dcl";
1212
import { deleteMap } from "./delete";
13+
import { doMap } from "./do";
1314
import { domainMap } from "./domain";
1415
import { dropTableMap } from "./drop_table";
1516
import { explainMap } from "./explain";
@@ -56,6 +57,7 @@ export const transformMap: Partial<CstToDocMap<Node>> = {
5657
...dataTypeMap,
5758
...dclMap,
5859
...deleteMap,
60+
...doMap,
5961
...domainMap,
6062
...dropTableMap,
6163
...explainMap,

test/proc/do.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import dedent from "dedent-js";
2+
import { testPostgresql } from "../test_utils";
3+
4+
describe("do", () => {
5+
it(`formats DO statement`, async () => {
6+
await testPostgresql(dedent`
7+
DO $$
8+
BEGIN
9+
PERFORM proc_name(arg1, arg2, arg3);
10+
END
11+
$$
12+
`);
13+
});
14+
15+
it(`formats DO [LANGUAGE <language>]`, async () => {
16+
await testPostgresql(dedent`
17+
DO LANGUAGE plpgsql 'SELECT 1;'
18+
`);
19+
});
20+
});

0 commit comments

Comments
 (0)