🖨 Converting an AST to SQLThat's super easy:import { toSql } from 'pgsql-ast-parser'; const sql: string = toSql.statement(myAst);Like with astVisitor() or astModifier(), you can also convert subparts of AST to SQL (not necessarily a whole statement) by calling other methods of...
npm i pgsql-ast-parser With Deno Just reference it like that: import{/* imports here */}from'https://deno.land/x/pgsql_ast_parser/mod.ts'; 📖 Parsing SQL ⚠ I strongly recommend NOT using this parser without Typescript. It will work, but types are awesome. ...
import*aspgsqlAstParserfrom'pgsql-ast-parser'constinput=`select json->'foo'::text->>'bar'::text as bar from json_table`constast=pgsqlAstParser.parse(input)[0]constoutput=pgsqlAstParser.toSql.statement(ast)console.log(output)// SELECT (((json->'foo')::text )->>'bar')::text ) ...
Parse sql to an AST like this:import { parse, Statement } from 'pgsql-ast-parser'; // parse multiple statements const ast: Statement[] = parse(`BEGIN TRANSACTION; insert into my_table values (1, 'two')`); // parse a single statement const ast: Statement = parseFirst(`SELECT * ...