npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-sql-parser

v1.6.0

Published

> parse / stringify sql (select grammar) in js.

Downloads

149,287

Readme

js-sql-parser

parse / stringify sql (select grammar) in js.

Build Status NPM Version NPM Downloads

sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html

news

  • Unicode extended char support for column name or alias & Function call in table_factor since v1.6.0
  • Support feature PlaceHolder like ${param} since v1.5.0 #43
  • Fix bug using ' & " for column alias? since v1.4.1 #40, #44
  • Fix bug tableFactor alias since v1.3.0 #34
  • Add support for "`" quoted alias since v1.2.2. #33
  • Fix bug stringify keyword having since v1.2.1. #29
  • Typo 'refrence' has been fixed to 'reference' since v1.2.0.

for more changes see CHANGELOG

commonjs usage

npm install --save js-sql-parser

const parser = require('js-sql-parser');
const ast = parser.parse('select * from dual');

console.log(JSON.stringify(ast, null, 2));

ast.value.selectItems.value[0].value = 'foo';
ast.value.from.value[0].value.value.value = 'bar';

console.log(parser.stringify(ast));
// SELECT foo FROM bar
// placeholder test
const parser = require('js-sql-parser');
const ast = parser.parse('select ${a} as a');

ast['value']['selectItems']['value'][0]['value'] = "'value'";
console.log(parser.stringify(ast));
// SELECT 'value' AS a

Note: PlaceHolder is an literal value but not an identifier. Table_name / column_name / function_name are identifier thus should NOT be placed with placeholder.

script tag

<script src="./dist/parser/sqlParser.js"><script/>

var sqlParser = window.sqlParser;
var ast = sqlParser.parse('select * from dual');
var sql = sqlParser.stringify(ast);

AMD supported

...

unsupported grammar currently

  • Hexadecimal Literals as x'01af' X'01af', but 0x01af is supported.
  • keyword COLLATE.
  • parammarker: keyword PREPARE / EXECUTE / DEALLOCATE
  • variable: keyword SET / CREATE PROCEDURE / CREATE FUNCTION
  • identifier expr: ODBC escape syntax
  • matchexpr: Full-Text Search Functions. // to support
  • intervalexpr: Date INTERVAL keyword. // to support
  • into outfile: INTO OUTFILE keyword. // to support

Build

  • Run npm run build to build the distributable.

LICENSE

MIT