Skip to content
This repository was archived by the owner on May 15, 2020. It is now read-only.
/ flora-sql-parser Public archive
forked from florajs/sql-parser

Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.

License

Notifications You must be signed in to change notification settings

Workiva/flora-sql-parser

 
 

Repository files navigation

Flora SQL Parser

Build Status NPM version Dependencies

Parse simple SQL statements into an abstract syntax tree (AST) and convert it back to SQL.

Setup

Run npm install

Tests

Run npm run test

Usage

Create AST for SQL statement:

const { Parser } = require('flora-sql-parser');
const parser = new Parser();
const ast = parser.parse('SELECT * FROM t');

console.log(ast);

Convert AST back to SQL:

const { Parser } = require('flora-sql-parser');
const ast = (new Parser()).parse('SELECT * FROM t');
const toSQL = require('flora-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.

License

MIT

About

Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.0%
  • Dockerfile 1.0%