Registry / database / rw-sql-parser

rw-sql-parser

JSON →
library1.0.1jsnpmunverified

A lexer and parser for basic SQL SELECT queries, written in JavaScript using JISON. This package is a fork of Forward's SQL Parser, with added support for hyphens in literals. It tokenizes SQL strings into a stream of tokens and parses them into a Select object with properties for where, group, order, and limit. Version 1.0.1 is the current stable release. It only supports basic SELECT statements and lacks full SQL coverage. The package is primarily intended for Node.js environments and requires CoffeeScript for building from source.

npm install rw-sql-parser
INSTALL
IMPORT
SIG · RW-SQL-PARSER
R
rw-sql-parser
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lexer
import { lexer } from 'rw-sql-parser'
The lexer is exported as a named export.
parser
import { parser } from 'rw-sql-parser'
The parser is exported as a named export.
Select
import { Select } from 'rw-sql-parser'
Select is a node type; available as named export if using lib/nodes.

Shows lexer tokenization and parser AST generation for a basic SELECT query.

import { lexer, parser } from 'rw-sql-parser'; const sql = "select * from my_table where foo = 'bar'"; const tokens = lexer.tokenize(sql); console.log(tokens); // [['SELECT','select',1],['STAR','*',1],['FROM','from',1],['LITERAL','my_table',1],['WHERE','where',1],['LITERAL','foo',1],['EQ','=',1],['STRING','bar',1]] const ast = parser.parse(tokens); console.log(ast.toString()); // SELECT * // FROM `my_table` // WHERE `foo` = 'bar'
Debug
Known issues
gotchaOnly basic SELECT queries are supported. Complex joins, subqueries, INSERT, UPDATE, DELETE are not implemented.
fix
Use a more complete SQL parser like `node-sql-parser` for full SQL support.
affects: <=1.0.1
gotchaThe token format is an array of [NAME, value, lineNumber] tailored for JISON, not standard JavaScript objects.
fix
Access token type via index 0, value via index 1.
affects: <=1.0.1
gotchaThe package requires CoffeeScript for building from source. npm install alone may not work without cake build.
fix
Run `npm install && cake build` if installing from source.
affects: <=1.0.1
Errors
Common errors & fixes
Error: Cannot find module 'rw-sql-parser'
Package not installed or npm install failed.
fix
Run `npm install rw-sql-parser` and ensure it's in node_modules.
TypeError: lexer.tokenize is not a function
Incorrect import; lexer is named, not default.
fix
Use `import { lexer } from 'rw-sql-parser';`
SyntaxError: Unexpected token
Query contains unsupported SQL syntax (e.g., JOIN, subquery).
fix
Restrict to basic SELECT with WHERE, GROUP BY, ORDER BY, LIMIT.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
Meta
1
Amazon
1
Resources
rw-sql-parser — npm install rw-sql-parser · libregistry