Registry / serialization / sqlite-parser

sqlite-parser

JSON →
library1.0.1jsnpmunverified

The `sqlite-parser` library provides a JavaScript implementation for parsing SQLite 3 SQL queries, generating an Abstract Syntax Tree (AST) representation. It supports both synchronous and asynchronous parsing via a callback function, allowing for flexible integration into applications. Since version 1.0.0, it introduced experimental stream transform capabilities (`createParser`, `createStitcher`) designed to handle large SQL files efficiently by processing them in chunks rather than loading the entire file into memory, which helps mitigate memory limitations. The library explicitly targets the SQLite 3 specification for its parsing logic. Its latest release, v1.0.1, was published over seven years ago (as of 2026), indicating that the project is no longer actively maintained. The AST structure itself underwent significant changes in pre-1.0.0 releases, particularly regarding property casing and the representation of complex expressions like `CASE` statements and binary operations. It is compatible with Node.js environments from version 4 onwards and can also be used in browsers via a bundled script.

npm install sqlite-parser
INSTALL
IMPORT
SIG · SQLITE-PARSER
S
sqlite-parser
serializationjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

sqliteParser
const sqliteParser = require('sqlite-parser');
import sqliteParser from 'sqlite-parser';
Primarily designed for CommonJS; direct ESM import might not work without a transpiler or ESM wrapper. The main export is the parser function itself.
createParser
const { createParser } = require('sqlite-parser');
import { createParser } from 'sqlite-parser';
Used for creating a stream transform for parsing large SQL files. Available since v1.0.0. Follows CommonJS named export pattern.
createStitcher
const { createStitcher } = require('sqlite-parser');
import { createStitcher } from 'sqlite-parser';
Used in conjunction with `createParser` to combine streamed AST nodes into a single, valid JSON array. Available since v1.0.0. Follows CommonJS named export pattern.

This quickstart demonstrates both synchronous and asynchronous parsing of a single SQLite query using the `sqliteParser` function. It also includes an example of how to use the `createParser` and `createStitcher` stream transforms for parsing large SQL files, writing the resulting AST to stdout.

const sqliteParser = require('sqlite-parser'); const fs = require('fs'); const path = require('path'); const query = 'SELECT pants FROM laundry WHERE color = "blue";'; // Synchronous parsing try { const astSync = sqliteParser(query); console.log('Synchronous AST:', JSON.stringify(astSync, null, 2)); } catch (err) { console.error('Synchronous Error:', err.message); } // Asynchronous parsing with callback sqliteParser(query, function (err, astAsync) { if (err) { console.error('Asynchronous Error:', err.message); return; } console.log('Asynchronous AST:', JSON.stringify(astAsync, null, 2)); }); // Example for stream parsing (requires a dummy file) const largeSqlFile = path.join(__dirname, 'large-input.sql'); fs.writeFileSync(largeSqlFile, 'CREATE TABLE users (id INT, name TEXT);\nINSERT INTO users VALUES (1, \'Alice\');'); const parserTransform = sqliteParser.createParser(); const singleNodeTransform = sqliteParser.createStitcher(); const readStream = fs.createReadStream(largeSqlFile); console.log('\n--- Stream Parsing Output ---'); readStream.pipe(parserTransform); parserTransform.pipe(singleNodeTransform); singleNodeTransform.pipe(process.stdout); parserTransform.on('error', function (err) { console.error('\nStream Parser Error:', err.message); process.exit(1); }); singleNodeTransform.on('finish', function () { console.log('\n--- Stream Parsing Finished ---'); fs.unlinkSync(largeSqlFile); // Clean up dummy file });
Debug
Known issues
breakingAll named values for properties such as `variant`, `format`, and `type` in the AST are now always lowercase, even if uppercase in the input SQL (e.g., `NATURAL JOIN` becomes `natural join`).
fix
Update consumers of the AST to expect and handle lowercase property values, performing case-insensitive checks if compatibility with older ASTs is required.
affects: >=1.0.0-rc2
breakingThe AST format for `CASE` expressions has significantly changed. The outer expression is now `variant: 'case'`, and internal `when` and `else` variants have specific `condition` and `consequent` properties.
fix
Review and refactor code that processes `CASE` expressions in the AST to conform to the new structure, especially regarding `variant` types and property names.
affects: >=1.0.0-rc2
breakingThe parsing order for binary expressions was changed, which may result in different AST structures for queries containing multiple chained binary expressions (e.g., `WHERE x != 2 OR x == 3 AND y > 5`).
fix
Thoroughly test existing SQL queries to verify the generated ASTs and adjust any logic that relies on a specific parse tree order for complex binary expressions.
affects: >=0.15.0-beta
breakingExpressions like `x NOT NULL` which were previously treated as unary expressions are now considered binary expressions in the AST.
fix
Update AST traversal or processing logic to correctly identify and handle `NOT NULL` as a binary expression rather than a unary one.
affects: >=0.15.0-beta
gotchaRunning the uglified bundle (`dist/sqlite-parser.js`) in the browser could lead to a `RangeError: Maximum call stack size exceeded`. As a result, the minification step was skipped, and only the browserified bundle is published.
fix
Ensure you are using the correct browserified (unminified) bundle if deploying to browser environments. Avoid relying on custom minification of the `dist/sqlite-parser.js` file if you encounter this error.
affects: >=1.0.0-rc3
gotchaThis project appears to be abandoned, with its last release (v1.0.1) over 7 years ago. No further updates, bug fixes, or security patches are expected.
fix
Consider the long-term viability and security implications when adopting this library. Evaluate alternative, actively maintained SQLite parsers if active development and support are critical requirements.
affects: >=1.0.1
Errors
Common errors & fixes
RangeError: Maximum call stack size exceeded
Occurs when attempting to run the uglified browser bundle due to recursive parsing logic.
fix
Do not use the minified `dist/sqlite-parser.js` directly in a browser environment; use the provided browserified bundle, which skips minification to avoid this issue (as of v1.0.0-rc3).
Error: Cannot find module 'sqlite-parser' or parser not working after npm install
In versions prior to v0.14.2, the minified bundle targeted by `package.json`'s `main` property was sometimes missing from the `dist/` folder after release tasks.
fix
Ensure you are using a version >= 0.14.2. If on an older version, manually verify `dist/sqlite-parser.min.js` exists or update to a newer, stable release.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
20
Meta
2
OpenAI (training)
1
Resources
sqlite-parser — npm install sqlite-parser · libregistry