@@ -7,60 +7,9 @@ import { Parser } from '@pgsql/parser';
77 * Transforms PostgreSQL v15 AST nodes to v16 format
88 */
99export class V15ToV16Transformer {
10- private parser15 = new Parser ( 15 ) ;
11- private parser16 = new Parser ( 16 ) ;
12- private transformationCache = new Map < string , any > ( ) ;
1310
14- private shouldTransformEmptyIval ( context : TransformerContext ) : { ival : number } | null {
15-
16- return null ;
17- }
1811
19- private detectEmptyIvalTransformation ( sql : string ) : number | null {
20- try {
21- const cacheKey = `empty_ival_${ sql } ` ;
22- if ( this . transformationCache . has ( cacheKey ) ) {
23- return this . transformationCache . get ( cacheKey ) ;
24- }
2512
26- const pg15Result = this . parser15 . parse ( sql ) ;
27- const pg16Result = this . parser16 . parse ( sql ) ;
28-
29- const pg15AConst = this . findAConstInAST ( pg15Result ) ;
30- const pg16AConst = this . findAConstInAST ( pg16Result ) ;
31-
32- if ( pg15AConst && pg16AConst ) {
33- const pg15IsEmpty = pg15AConst . ival && Object . keys ( pg15AConst . ival ) . length === 0 ;
34- const pg16HasNested = pg16AConst . ival && typeof pg16AConst . ival . ival === 'number' ;
35-
36- if ( pg15IsEmpty && pg16HasNested ) {
37- const targetValue = pg16AConst . ival . ival ;
38- this . transformationCache . set ( cacheKey , targetValue ) ;
39- return targetValue ;
40- }
41- }
42-
43- this . transformationCache . set ( cacheKey , null ) ;
44- return null ;
45- } catch ( error ) {
46- return null ;
47- }
48- }
49-
50- private findAConstInAST ( obj : any ) : any {
51- if ( ! obj || typeof obj !== 'object' ) return null ;
52-
53- if ( obj . A_Const ) return obj . A_Const ;
54-
55- for ( const key in obj ) {
56- if ( typeof obj [ key ] === 'object' ) {
57- const result = this . findAConstInAST ( obj [ key ] ) ;
58- if ( result ) return result ;
59- }
60- }
61-
62- return null ;
63- }
6413
6514 transform ( node : PG15 . Node , context : TransformerContext = { parentNodeTypes : [ ] } ) : any {
6615 if ( node == null ) {
@@ -101,7 +50,7 @@ export class V15ToV16Transformer {
10150 if ( typeof this [ methodName ] === 'function' ) {
10251 const childContext : TransformerContext = {
10352 ...context ,
104- parentNodeTypes : [ ...context . parentNodeTypes , nodeType ]
53+ parentNodeTypes : [ ...( context . parentNodeTypes || [ ] ) , nodeType ]
10554 } ;
10655 return ( this [ methodName ] as any ) ( nodeData , childContext ) ;
10756 }
@@ -941,16 +890,6 @@ export class V15ToV16Transformer {
941890
942891 Integer ( node : PG15 . Integer , context : TransformerContext ) : any {
943892 const result : any = { ...node } ;
944-
945- // Handle case where PG15 produces empty Integer nodes that need different handling based on context
946- if ( Object . keys ( node ) . length === 0 ) {
947- if ( context . parentNodeTypes . includes ( 'TypeName' ) ) {
948- result . ival = - 1 ;
949- } else if ( context . parentNodeTypes . includes ( 'A_Const' ) ) {
950- result . ival = - 1 ;
951- }
952- }
953-
954893 return { Integer : result } ;
955894 }
956895
0 commit comments