File tree Expand file tree Collapse file tree 4 files changed +14
-3
lines changed
Expand file tree Collapse file tree 4 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,8 @@ npm install @pgsql/utils
3939With the AST helper methods, creating complex SQL ASTs becomes straightforward and intuitive.
4040
4141``` ts
42- import { CreateStmt , ColumnDef } from ' @pgsql/types' ;
42+ import { CreateStmt , ColumnDef } from ' @pgsql/types/types/wrapped' ;
43+ import { deparse } from ' pgsql-deparser' ;
4344import ast from ' @pgsql/utils' ;
4445
4546const newColumn: ColumnDef = ast .columnDef ({
@@ -55,6 +56,8 @@ const createStmt: CreateStmt = ast.createStmt({
5556 }),
5657 tableElts: [newColumn ]
5758});
59+
60+ deparse (createStmt , {}) // SQL!
5861```
5962
6063### Enum Value Conversion
Original file line number Diff line number Diff line change 11// Jest Snapshot v1, https://goo.gl/fbAQLP
22
3+ exports [` asts 1` ] = `
4+ "CREATE TABLE (
5+ id int4
6+ ) INHERITS ( )"
7+ ` ;
8+
39exports [` getEnumValue 1` ] = ` "AEXPR_OP"` ;
410
511exports [` getEnumValue 2` ] = ` "AEXPR_OP_ANY"` ;
Original file line number Diff line number Diff line change 11import * as u from '../src' ;
22import ast from '../src/asts' ;
3- import { CreateStmt , ColumnDef } from '@pgsql/types' ;
3+ import { CreateStmt , ColumnDef } from '@pgsql/types/types/wrapped' ;
4+ import { deparse } from 'pgsql-deparser' ;
45
56it ( 'getEnumValue' , ( ) => {
67 expect ( u . getEnumValue ( 'A_Expr_Kind' , 0 ) ) . toMatchSnapshot ( ) ;
@@ -25,5 +26,5 @@ it('asts', () => {
2526 } ) ,
2627 tableElts : [ newColumn ]
2728 } )
28- expect ( createStmt ) . toBeTruthy ( ) ;
29+ expect ( deparse ( createStmt , { } ) ) . toMatchSnapshot ( ) ;
2930} ) ;
Original file line number Diff line number Diff line change 6666 "esprima" : " 4.0.1" ,
6767 "jest" : " ^29.5.0" ,
6868 "pg-proto-parser" : " ^1.12.2" ,
69+ "pgsql-deparser" : " ^13.11.0" ,
6970 "prettier" : " ^2.8.7" ,
7071 "rimraf" : " 5.0.5" ,
7172 "ts-jest" : " ^29.1.0" ,
You can’t perform that action at this time.
0 commit comments