Skip to content

Commit

Permalink
deparser in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Mar 30, 2024
1 parent c4d03dd commit f09a196
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ npm install @pgsql/utils
With the AST helper methods, creating complex SQL ASTs becomes straightforward and intuitive.

```ts
import { CreateStmt, ColumnDef } from '@pgsql/types';
import { CreateStmt, ColumnDef } from '@pgsql/types/types/wrapped';
import { deparse } from 'pgsql-deparser';
import ast from '@pgsql/utils';

const newColumn: ColumnDef = ast.columnDef({
Expand All @@ -55,6 +56,8 @@ const createStmt: CreateStmt = ast.createStmt({
}),
tableElts: [newColumn]
});

deparse(createStmt, {}) // SQL!
```

### Enum Value Conversion
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/__test__/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`asts 1`] = `
"CREATE TABLE (
id int4
) INHERITS ( )"
`;

exports[`getEnumValue 1`] = `"AEXPR_OP"`;

exports[`getEnumValue 2`] = `"AEXPR_OP_ANY"`;
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/__test__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as u from '../src';
import ast from '../src/asts';
import { CreateStmt, ColumnDef } from '@pgsql/types';
import { CreateStmt, ColumnDef } from '@pgsql/types/types/wrapped';
import { deparse } from 'pgsql-deparser';

it('getEnumValue', () => {
expect(u.getEnumValue('A_Expr_Kind', 0)).toMatchSnapshot();
Expand All @@ -25,5 +26,5 @@ it('asts', () => {
}),
tableElts: [newColumn]
})
expect(createStmt).toBeTruthy();
expect(deparse(createStmt, {})).toMatchSnapshot();
});
1 change: 1 addition & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"esprima": "4.0.1",
"jest": "^29.5.0",
"pg-proto-parser": "^1.12.2",
"pgsql-deparser": "^13.11.0",
"prettier": "^2.8.7",
"rimraf": "5.0.5",
"ts-jest": "^29.1.0",
Expand Down

0 comments on commit f09a196

Please sign in to comment.