A SQL parser written in pure JS
Clone or download
Pull request Compare This branch is 39 commits ahead of forward:master.
Latest commit 67f2079 Aug 18, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
browser Build 1.2.2 May 1, 2018
lib Build 1.2.2 May 1, 2018
src Merge remote-tracking branch 'davegraziosi/master' Aug 18, 2018
test Merge remote-tracking branch 'davegraziosi/master' Aug 18, 2018
.gitignore Update .gitignore Aug 29, 2016
Cakefile Build 1.2.2 May 1, 2018
LICENSE Fix #4 Support ILIKE operator Apr 2, 2018
README.md Build 1.2.2 May 1, 2018
bower.json Build Nov 9, 2016
index.js remove all runtime dependancies and make a browser friendly single fi… Dec 24, 2011
package.json Build 1.2.2 May 1, 2018


SQL Parser

NPM version

SQL Parser is a lexer, grammar and parser for SQL written in JS. Currently it is only capable of parsing fairly basic SELECT queries but full SQL support will hopefully come in time. See the specs for examples of currently supported queries.


The package is distributed on NPM and can be installed with...

npm install sql-parser-mistic

It is also available on Bower :

bower install sql-parser

To build from source you'll need to run the following from the root of the project...

npm install
npm run build

Tests are written using Mocha and can be run with...

npm test


The lexer takes a SQL query string as input and returns a stream of tokens in the format

['NAME', 'value', lineNumber]

Here is a simple example...

lexer.tokenize('select * from my_table')


The tokenized output is in a format compatible with JISON.


The parser only currently supports SELECT queries but is able to produce a Select object with properties for where, group, order, limit. See lib/nodes.coffee for more info of the returned object structure. Calling .toString() on a Select object should give you back a well formatted version of the original SQL input.

tokens = lexer.tokenize("select * from my_table where foo = 'bar'")

  FROM `my_table`
  WHERE `foo` = 'bar'


A lot of the boilerplate and compilation code in this project is borrowed from the CoffeeScript project as it was the best example of a project using JISON that I could find. Thanks.


Contributions in the form of pull requests that add syntax support are very welcome but should be supported by both Lexer and Parser level tests.