gitmyhub

sqlite3-parser-js

TypeScript ★ 66 updated 2mo ago

Pure JavaScript port of SQLite's LALR(1) SQL parser with improved error messages

A JavaScript library that parses SQLite SQL queries into a structured tree so tools can analyze or transform them programmatically.

JavaScriptTypeScriptsetup: easycomplexity 2/5

sqlite3-parser is a JavaScript library that reads SQLite SQL query strings and converts them into a structured tree (called an Abstract Syntax Tree, or AST) that programs can analyze and manipulate. This is useful any time you need to understand what a SQL query does programmatically — for example, to validate queries, transform them, highlight syntax in an editor, or build developer tools.

The parser is derived directly from SQLite's official grammar definition file, so it recognizes the same syntax SQLite itself does and produces highly accurate results. It is written in pure JavaScript/TypeScript with no WebAssembly or native code, which means it works in web browsers, Node.js, and other JavaScript runtimes without any special setup. The library ships at about 32 kilobytes compressed, making it lightweight for use in front-end applications. According to the project's own benchmarks, it runs 2 to 200 times faster than competing JavaScript SQL parsers.

A notable feature is its improved error messages. When a query has a syntax problem, the error output includes the exact location in the source, a suggestion of what tokens would have been valid at that point, and helpful hints for common mistakes such as unclosed parentheses or reserved keywords used as table names. The library also includes a command-line tool for inspecting the AST of a query and a traversal API for walking the tree. You would use this if you are building a SQL editor, a query linter, a database migration tool, or any developer tooling that needs to understand SQLite query structure.

Where it fits