From f09a196c049c084d98120dba2e0a14dd5e94574a Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sat, 30 Mar 2024 10:47:00 -0700 Subject: [PATCH] deparser in tests --- packages/utils/README.md | 5 ++++- packages/utils/__test__/__snapshots__/utils.test.ts.snap | 6 ++++++ packages/utils/__test__/utils.test.ts | 5 +++-- packages/utils/package.json | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/utils/README.md b/packages/utils/README.md index cd1f54f..e772fad 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -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({ @@ -55,6 +56,8 @@ const createStmt: CreateStmt = ast.createStmt({ }), tableElts: [newColumn] }); + +deparse(createStmt, {}) // SQL! ``` ### Enum Value Conversion diff --git a/packages/utils/__test__/__snapshots__/utils.test.ts.snap b/packages/utils/__test__/__snapshots__/utils.test.ts.snap index f5abb4e..c8b82d8 100644 --- a/packages/utils/__test__/__snapshots__/utils.test.ts.snap +++ b/packages/utils/__test__/__snapshots__/utils.test.ts.snap @@ -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"`; diff --git a/packages/utils/__test__/utils.test.ts b/packages/utils/__test__/utils.test.ts index e409f06..e64230b 100644 --- a/packages/utils/__test__/utils.test.ts +++ b/packages/utils/__test__/utils.test.ts @@ -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(); @@ -25,5 +26,5 @@ it('asts', () => { }), tableElts: [newColumn] }) - expect(createStmt).toBeTruthy(); + expect(deparse(createStmt, {})).toMatchSnapshot(); }); \ No newline at end of file diff --git a/packages/utils/package.json b/packages/utils/package.json index 43f4f9a..997ed7a 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -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",