1+ import { v13 , v14 , v15 , v16 , v17 } from '@pgsql/parser' ;
2+ import { readFileSync , writeFileSync } from 'fs' ;
3+ import { join } from 'path' ;
4+ import { cleanTree } from '../test-utils/clean-tree' ;
5+
6+ async function testAst ( ) {
7+ try {
8+ // Read SQL from input.sql in the same directory
9+ const inputPath = join ( __dirname , 'input.sql' ) ;
10+ const sql = readFileSync ( inputPath , 'utf8' ) ;
11+
12+ // Parse the SQL
13+ const astv17 = await v17 . parse ( sql ) ;
14+ const astv16 = await v16 . parse ( sql ) ;
15+ const astv15 = await v15 . parse ( sql ) ;
16+ const astv14 = await v14 . parse ( sql ) ;
17+ const astv13 = await v13 . parse ( sql ) ;
18+
19+ const cleanedAstv17 = cleanTree ( astv17 ) ;
20+ const cleanedAstv16 = cleanTree ( astv16 ) ;
21+ const cleanedAstv15 = cleanTree ( astv15 ) ;
22+ const cleanedAstv14 = cleanTree ( astv14 ) ;
23+ const cleanedAstv13 = cleanTree ( astv13 ) ;
24+
25+ // Write JSON to output.json in the same directory
26+ const outputPathv13 = join ( __dirname , 'output-v13.json' ) ;
27+ const outputPathv14 = join ( __dirname , 'output-v14.json' ) ;
28+ const outputPathv15 = join ( __dirname , 'output-v15.json' ) ;
29+ const outputPathv16 = join ( __dirname , 'output-v16.json' ) ;
30+ const outputPathv17 = join ( __dirname , 'output-v17.json' ) ;
31+
32+ writeFileSync ( outputPathv13 , JSON . stringify ( cleanedAstv13 , null , 2 ) ) ;
33+ writeFileSync ( outputPathv14 , JSON . stringify ( cleanedAstv14 , null , 2 ) ) ;
34+ writeFileSync ( outputPathv15 , JSON . stringify ( cleanedAstv15 , null , 2 ) ) ;
35+ writeFileSync ( outputPathv16 , JSON . stringify ( cleanedAstv16 , null , 2 ) ) ;
36+ writeFileSync ( outputPathv17 , JSON . stringify ( cleanedAstv17 , null , 2 ) ) ;
37+
38+ console . log ( `Successfully parsed SQL from ${ inputPath } and wrote AST` ) ;
39+ } catch ( error ) {
40+ console . error ( 'Error processing SQL:' , error ) ;
41+ }
42+ }
43+
44+ testAst ( ) ;
0 commit comments