Package Exports
- @florajs/sql-parser
- @florajs/sql-parser/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@florajs/sql-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@florajs/sql-parser
Parse simple SQL statements into an abstract syntax tree (AST) and convert it back to SQL.
Usage
Create AST for SQL statement
const { Parser } = require('@florajs/sql-parser');
const parser = new Parser();
const ast = parser.parse('SELECT * FROM t');
console.log(ast);Convert AST back to SQL
const { Parser } = require('@florajs/sql-parser');
const ast = (new Parser()).parse('SELECT * FROM t');
const toSQL = require('@florajs/sql-parser').util.astToSQL;
console.log(toSQL(ast));The generated SQL is ANSI SQL compliant. To run those queries on MySQL, make sure you set correct SQL mode
SET SESSION sql_mode = 'ANSI';before running any query.
Acknowledgement
This project is based on the SQL parser extracted from Alibaba's nquery module.