A SQL parser for Node.js that converts SQL statements into an abstract syntax tree (AST) and back. Version 5.3.27 supports multiple dialects including MySQL, PostgreSQL, SQLite, BigQuery, and others. It outputs visited table and column lists with authority information. Released monthly, it supports SELECT, INSERT, UPDATE, DELETE, DROP, TRUNCATE, and RENAME commands. Differentiators: provides both AST and table/column lists, supports multiple databases, and is available as a UMD bundle for browsers. Ships TypeScript types.
npm install node-sql-parser-benberiNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Parses a SQL SELECT statement into an AST, retrieves table and column lists, and converts AST back to SQL.
Use dynamic import: const { Parser } = await import('node-sql-parser'); or set type:'module' in package.json.Use 'parser.astify(sql)' instead of 'parser.parse(sql).ast'.
Upgrade to v5+ to avoid external type dependency.
Check supported dialect list; for unsupported syntax, consider using raw string manipulation.
Use the exact dialect string as documented: 'mysql', 'postgresql', 'sqlite', etc.
Use: import { Parser } from 'node-sql-parser'; const parser = new Parser();Run: npm install node-sql-parser. Do not use @taozhi8833998/node-sql-parser for npm registry.
Update to v5.3+ or wrap subquery in parentheses properly.