• Stars
    star
    530
  • Rank 83,660 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 13 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A SQL parser written in pure JS

SQL Parser

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.

Installation

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

npm install sql-parser

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

npm install
cake build

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

npm test

Lexer

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')

[
  ['SELECT','select',1],
  ['STAR','*',1],
  ['FROM','from',1],
  ['LITERAL','my_table',1]
]

The tokenized output is in a format compatible with JISON.

Parser

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')
parser.parse(tokens).toString()

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

Credits

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

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.

More Repositories

1

capify-ec2

Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.
Ruby
198
star
2

timothy

Timothy's primary goal is to make The Yellow Elephant rich and famous
JavaScript
93
star
3

node-hive

Node Hive Client Library
JavaScript
61
star
4

node-hdfs

Access to Hadoop's HDFS via libhdfs and JNI
C++
53
star
5

mandy

Easy Map/Reduce with Hadoop and Ruby. Also see http://github.com/forward/mandy-lab for examples.
Ruby
45
star
6

capify-cloud

Ruby
25
star
7

flume-zeromq

A zeromq sink for flume
Java
15
star
8

capistrano-deploy-tagger

Capistrano-Deploy-Tagger creates and updates certain tags in Git each time you perform a deploy. The first tag defaults to 'inproduction' and is always updated to refer to the revision that was just deployed. The second tag is a timestamp applied to every revision that is deployed to production.
Ruby
14
star
9

harlequin

A JS library for producing color formatted data tables
JavaScript
12
star
10

incanter-BLAS

modified version of Incanter using BLAS instead of COLT
Clojure
7
star
11

misty

DSL for AWS Cloud formation
Ruby
5
star
12

extramuros

clojure friendly mahout
Java
4
star
13

node-clickatell

node.js click for Clickatell SMS gateway
JavaScript
4
star
14

clj-bq

Google BigQuery Clojure wrapper
Clojure
3
star
15

rbase

Ruby Hbase client
Ruby
3
star
16

metris

Multiplayer Tetris built for the Node Knockout 2011
JavaScript
3
star
17

rbpig

Java
2
star
18

capistrano-ec2-selfdeploy-tag

Note: This project is deprecated and will no longer be maintained. Please switch to the Capistrano-Deploy-Tagger project for future updates.
Ruby
2
star
19

movemberize

A javascript plugin to movemberize your site.
JavaScript
1
star
20

stage

Show interface for lighting and automation control, written in Ruby.
Ruby
1
star
21

detective

Ruby
1
star
22

jreject-rails

JavaScript
1
star
23

toptrumps

Ruby
1
star
24

mandy-lab

Map/Reduce Exercises for Hadoop with Mandy Gem
Ruby
1
star
25

clj-rpm

Ring integration for NewRelic RPM
Clojure
1
star
26

sound-doodle

@antoniogarrote @BarisBalic and @thattommyhall's entry in NodeKnockout 2012
JavaScript
1
star