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

sql-ast

v0.3.0

Published

MySQL parser

Downloads

161

Readme

sql-ast v0.3.0

The current goal of sql-ast is to parse the output of mysqldump into an AST. If anyone wants to expand the capability of this library, feel free to send some pull requests!

const {parse} = require('sql-ast');

parse(input); // => [object Array]

Note: The current feature set is very limited. Open an issue if you have want something that isn't supported yet.

 

Whitespace

Tokens are not created for whitespace.

This includes spaces, tabs (\t), line breaks (\n), and carriage returns (\r).

Comments

Tokens are not created for comments.

All three styles are supported: /*, --, and #.

One exception is /*!-style comments, which annotate the minimum MySQL version required to run the statement(s) or apply the attribute(s) contained within. Special version tokens are created for these comments.

 

Token types

  • word is a character group matching /^[a-z0-9_$]+$/i
  • ident is a character group wrapped with backtick quotes
  • punct is a character matching /^[(),.;=]$/
  • string is a character group wrapped with single or double quotes
  • number is a character group matching /^-?[0-9]+(\.[0-9]+)?(E-?[0-9]+)?$/
  • variable is a character group matching /^@@?[$._a-z]+$/i
  • version is a /*!-style comment or its */ closer

Every token has these properties:

  • type: string
  • value: string|number
  • start: number
  • end: number

Notes

  • The value of a number is a number literal.
  • The value of a ident or string does not include the quotes.
  • The value of a version tells you the minimum MySQL version required before any following tokens can be used. This remains in effect until another version token is found.
  • When the value of a version token is:
    • > 0 a minimum version of MySQL is required
    • == 0 no minimum version, but MySQL is required
    • == -1 MySQL is not required

 

AST Nodes

Every AST node extends the Node class and has start and end properties.

Action nodes are typically owned by statements that perform actions (eg: ALTER).

Attribute nodes are typically owned by statements, column definitions, and index definitions. Some examples are IF EXISTS and ENGINE=ISAM.

Column and Index nodes are owned by CREATE TABLE statements.

Literal and Variable nodes are created for value expressions.

Variable nodes are also created when a SET statement sets a variable. In this case, the node has a value property.

Row nodes are owned by INSERT and REPLACE statements.

Statement nodes only exist in the top-level array returned by parse.

Notes

  • All node types are exported by the main module.
  • They have no methods by default. Feel free to define methods as you see fit.
  • More node types may be added in the future.