GithubHelp home page GithubHelp logo

oleg-andreyev / sql-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mistic100/sql-parser

0.0 1.0 0.0 1.8 MB

A SQL parser written in pure JS

License: MIT License

HTML 1.62% JavaScript 98.38%

sql-parser's Introduction

SQL Parser

NPM version jsDelivr CDN GZIP size Build Status

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-mistic

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

npm install
npm run compile

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'

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.

sql-parser's People

Contributors

andykent avatar besquared avatar bjornharrtell avatar davegraziosi avatar davidcrawford avatar dependabot-preview[bot] avatar dependabot[bot] avatar haskellcamargo avatar laf avatar mistic100 avatar mixu avatar numtel avatar reynardmh avatar sthupukari avatar zubairov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.