All Projects → codeschool → Sqlite Parser

codeschool / Sqlite Parser

Licence: mit
JavaScript implentation of SQLite 3 query parser

Labels

Projects that are alternatives of or similar to Sqlite Parser

Store
PostgreSQL shopping cart
Stars: ✭ 213 (-23.66%)
Mutual labels:  plpgsql
id3c
Data logistics system enabling real-time pathogen surveillance. Built for the Seattle Flu Study.
Stars: ✭ 21 (-92.47%)
Mutual labels:  plpgsql
sql-surveyor
High-level SQL parser. Identify tables, columns, aliases and more from your SQL script in one easy to consume object. Supports PostgreSQL, MySQL, SQL Server and Oracle (PL/SQL) dialects.
Stars: ✭ 19 (-93.19%)
Mutual labels:  plpgsql
Freedom
capstone based disassembler for extracting to binnavi
Stars: ✭ 214 (-23.3%)
Mutual labels:  plpgsql
Pgmonitor
PostgreSQL Monitoring, Metrics Collection and Alerting Resources from Crunchy Data
Stars: ✭ 235 (-15.77%)
Mutual labels:  plpgsql
stacker.news
It's like Hacker News but we pay you Bitcoin.
Stars: ✭ 196 (-29.75%)
Mutual labels:  plpgsql
Schemaverse
The Schemaverse is a space-based strategy game implemented entirely within a PostgreSQL database. Compete against other players using raw SQL commands to command your fleet. Or, if your PL/pgSQL-foo is strong, wield it to write AI and have your fleet command itself!
Stars: ✭ 207 (-25.81%)
Mutual labels:  plpgsql
Pgmemento
Audit trail with schema versioning for PostgreSQL using transaction-based logging
Stars: ✭ 260 (-6.81%)
Mutual labels:  plpgsql
Xtuple
This repository contains the source code for the database schema for the PostBooks edition of xTuple ERP and xTuple's REST API server. The REST API server is written in JavaScript running on Node.js. The database schema for PostBooks runs on a PostgreSQL database server.
Stars: ✭ 247 (-11.47%)
Mutual labels:  plpgsql
pmts
Poor man's time series functionality for PostgreSQL
Stars: ✭ 31 (-88.89%)
Mutual labels:  plpgsql
Postgis Vt Util
postgres helper functions for making vector tiles
Stars: ✭ 216 (-22.58%)
Mutual labels:  plpgsql
Pg Coordtransform
基于PostgreSQL+PostGIS的火星坐标系、百度坐标系、WGS84坐标系、CGCS2000坐标系的转换函数
Stars: ✭ 224 (-19.71%)
Mutual labels:  plpgsql
mimeo
Extension for specialized, per-table replication between PostgreSQL instances
Stars: ✭ 74 (-73.48%)
Mutual labels:  plpgsql
Dbt Utils
Utility functions for dbt projects.
Stars: ✭ 212 (-24.01%)
Mutual labels:  plpgsql
Openopps Platform
Open Opportunities open source platform
Stars: ✭ 255 (-8.6%)
Mutual labels:  plpgsql
3dcitydb
3D City Database - The Open Source CityGML Database
Stars: ✭ 210 (-24.73%)
Mutual labels:  plpgsql
hashids.sql
PL/pgSQL implementation of hashids library
Stars: ✭ 40 (-85.66%)
Mutual labels:  plpgsql
Groupdate.sql
The simplest way to group temporal data
Stars: ✭ 260 (-6.81%)
Mutual labels:  plpgsql
Bedquilt Core
A JSON document store on PostgreSQL
Stars: ✭ 256 (-8.24%)
Mutual labels:  plpgsql
phpPgAdmin6
PHP7+ Based administration tool for PostgreSQL 9.3+
Stars: ✭ 45 (-83.87%)
Mutual labels:  plpgsql

sqlite-parser

NPM Version Image dependencies Status Image devDependencies Status Image License Type Image

This JavaScript library parses SQLite queries to generate abstract syntax tree (AST) representations of the parsed statements.

Try out the interactive demo to see it in action.

This parser is written against the SQLite 3 spec.

Install

npm install sqlite-parser

Install as a global module (since v1.0.0)

Use the command-line interface of the parser by installing it as a global module. The sqlite-parser command is then available to use to parse input SQL files and write the results to stdout or a JSON file. Additional usage instructions and options available through sqlite-parser --help.

npm i -g sqlite-parser

Basic Usage

The library exposes a function that accepts two arguments: a string containing SQL to parse and a callback function. If an AST cannot be generated from the input string then a descriptive error is generated.

If invoked without a callback function the parser will runs synchronously and return the resulting AST or throw an error if one occurs.

var sqliteParser = require('sqlite-parser');
var query = 'select pants from laundry;';
// sync
var ast = sqliteParser(query);
console.log(ast);

// async
sqliteParser(query, function (err, ast) {
  if (err) {
    console.error(err);
    return;
  }
  console.log(ast);
});

Use parser on Node streams (experimental) (since v1.0.0)

This library also includes experimental support as a stream transform that can accept a readable stream of SQL statements and produce a JSON string, representing the AST of each statement, as it is read and transformed. Using this method, the parser can handle files containing hundreds or thousands of queries at once without running into memory limitations. The AST for each statement is pushed down the stream as soon as it is read and parsed instead of reading the entire file into memory before parsing begins.

var parserTransform = require('sqlite-parser').createParser();
var readStream = require('fs').createReadStream('./large-input-file.sql');

readStream.pipe(parserTransform);
parserTransform.pipe(process.stdout);

parserTransform.on('error', function (err) {
  console.error(err);
  process.exit(1);
});

parserTransform.on('finish', function () {
  process.exit(0);
});

To pipe the output into a file that contains a single valid JSON structure, the output of the parser steam transform needs to be wrapped in statement list node where every statement is separated by a comma.

var fs = require('fs');
var sqliteParser = require('sqlite-parser');
var parserTransform = sqliteParser.createParser();
var singleNodeTransform = sqliteParser.createStitcher();
var readStream = fs.createReadStream('./large-input-file.sql');
var writeStream = fs.createWriteStream('./large-output-file.json');

readStream.pipe(parserTransform);
parserTransform.pipe(singleNodeTransform);
singleNodeTransform.pipe(writeStream);

parserTransform.on('error', function (err) {
  console.error(err);
  process.exit(1);
});

writeStream.on('finish', function () {
  process.exit(0);
});

AST

The AST is stable as of release 1.0.0. However, if changes need to be made to improve consistency between node types, they will be explicitly listed in the CHANGELOG.

Example

You can provide one or more SQL statements at a time. The resulting AST object has, at the highest level, a statement list node that contains an array of statements.

Input SQL

SELECT
 MAX(honey) AS "Max Honey"
FROM
 BeeHive

Result AST

{
  "type": "statement",
  "variant": "list",
  "statement": [
    {
      "type": "statement",
      "variant": "select",
      "result": [
        {
          "type": "function",
          "name": {
            "type": "identifier",
            "variant": "function",
            "name": "max"
          },
          "args": {
            "type": "expression",
            "variant": "list",
            "expression": [
              {
                "type": "identifier",
                "variant": "column",
                "name": "honey"
              }
            ]
          },
          "alias": "Max Honey"
        }
      ],
      "from": {
        "type": "identifier",
        "variant": "table",
        "name": "beehive"
      }
    }
  ]
}

Syntax Errors

This parser will try to create descriptive error messages when it cannot parse some input SQL. In addition to an approximate location for the syntax error, the parser will attempt to describe the area of concern (e.g.: Syntax error found near Column Identifier (WHERE Clause)).

Contributing

Contributions are welcome! You can get started by checking out the contributing guidelines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].