{"repo":"oguimbal/pgsql-ast-parser","free":true,"listed":false,"github":"https://github.com/oguimbal/pgsql-ast-parser","clone":"git clone https://github.com/oguimbal/pgsql-ast-parser.git","description":"Yet another simple Postgres SQL parser","language":"TypeScript","stars":347,"topics":["nodejs","deno","typescript","postgresql","postgres","ast","sql","postgres-sql-parser","parser","pgsql"],"license":null,"category":"databases-storage","readme_excerpt":"🏃‍♀️ pgsql-ast-parser is a Postgres SQL syntax parser. It produces a typed AST (Abstract Syntax Tree), covering the most common syntaxes of pgsql. ❤ It works both in node or in browser. ⚠ This parser does not support (yet) PL/pgSQL. It might not even cover some funky syntaxes. ❤ Open an issue if you find an bug or unsupported syntax ! 🔗 This parser has been created to implement pg-mem , an in-memory postgres db emulator. 👉 play with it here ⭐ this repo if you like this package, it helps to motivate me :) 📐 Installation With NodeJS With Deno Just reference it like that: 📖 Parsing SQL ⚠ I strongly recommend NOT using this parser without Typescript. It will work, but types are awesome. Parse sql to an AST like this: 🔍 Inspecting SQL AST Once you have parsed an AST, you might want to traverse it easily to know what's in it. There is a helper for that: astVisitor. Here is an example which lists all the tables used in a request, and which counts how many joins it contains: You'll find that AST visitors (that's the name of this pattern) are quite flexible and powerful once you get used to them ! 👉 Here is the implementation of toSql which uses an astVisitor to reconstitude SQL from an AST (see below). 🖨 Converting an AST to SQL That's super easy: Like with astVisitor() or astModifier() , you can also convert subparts of AST to SQL (not necessarily a whole statement) by calling other methods of toSql. 📝 Modifying SQL AST There is a special kind of visitor, which I called ast","default_branch":null,"files":null,"tree":[],"storefront":"/r/oguimbal","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/oguimbal/pgsql-ast-parser/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}