{"id":22405,"library":"sqlite3-parser","title":"sqlite3-parser","description":"A fast, pure JavaScript LALR(1) parser for SQLite SQL syntax, generated from SQLite's parse.y grammar. Version 0.7.1 ships TypeScript types, runs in Node, Bun, and browsers, and is ~32 KB gzipped. It provides improved error messages with location, expected tokens, and common mistake hints. Compared to alternatives like sql.js or node-sqlite3, it is purely a parser (no database connection) and is 2x-200x faster than other JavaScript SQL parsers (e.g., @nene/query-lang, sql-parser-cst).","status":"active","version":"0.7.1","language":"javascript","source_language":"en","source_url":"https://github.com/justjake/sqlite3-parser-js","tags":["javascript","sql","sqlite","parser","ast","lalr","syntax","tokenizer","sqlite3","typescript"],"install":[{"cmd":"npm install sqlite3-parser","lang":"bash","label":"npm"},{"cmd":"yarn add sqlite3-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add sqlite3-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v0.7.0; CommonJS require is not supported. Use dynamic import or bundler with ESM interop.","wrong":"const parse = require('sqlite3-parser').parse","symbol":"parse","correct":"import { parse } from 'sqlite3-parser'"},{"note":"Same ESM-only constraint. TypeScript users must ensure moduleResolution is 'node16' or 'bundler'.","wrong":"const { parseStmt } = require('sqlite3-parser')","symbol":"parseStmt","correct":"import { parseStmt } from 'sqlite3-parser'"},{"note":"Convenience function that throws on parse error. Useful when you know the SQL is valid.","symbol":"parseOrThrow","correct":"import { parseOrThrow } from 'sqlite3-parser'"},{"note":"ParseOk is a type-only export. Use `import type` to avoid runtime errors in isolated modules.","wrong":"import { ParseOk } from 'sqlite3-parser'","symbol":"type ParseOk","correct":"import type { ParseOk } from 'sqlite3-parser'"},{"note":"Error diagnostics are not subclasses of Error. Always check `result.status` before accessing error info.","symbol":"type ParseDiagnostic","correct":"import type { ParseDiagnostic } from 'sqlite3-parser'"}],"quickstart":{"code":"import { parse, parseStmt, parseOrThrow } from 'sqlite3-parser';\n\n// Parse multiple statements\nconst multi = parse(`SELECT * FROM t1; INSERT INTO t2 VALUES (1)`);\nif (multi.status === 'ok') {\n  console.log(multi.root.cmds.length); // 2\n  console.log(multi.root.cmds[0].type); // SelectStmt\n}\n\n// Parse single statement\nconst single = parseStmt('SELECT id FROM users WHERE name = ?');\nif (single.status === 'ok') {\n  console.log(single.root.type); // SelectStmt\n}\n\n// Parse or throw\nconst stmt = parseOrThrow('UPDATE t SET x = 1');\nconsole.log(stmt.root.type); // CmdList (always contains one command)\n\n// Incremental parsing with allowTrailing\nconst result = parseStmt('SELECT 1; SELECT 2', { allowTrailing: true });\nif (result.status === 'ok') {\n  console.log(result.tail); // 9 (index where next statement starts)\n}","lang":"typescript","description":"Demonstrates parsing multiple statements, single statement, throwing on error, and incremental parsing with allowTrailing option."},"warnings":[{"fix":"Use import syntax, or upgrade to Node >=14 and use dynamic import.","message":"ESM-only since v0.7.0. Deep require('sqlite3-parser') will fail with ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Always check result.status === 'ok' before using result.root. Use parseOrThrow for exception-based flow.","message":"ParseDiagnostic is not a subclass of Error; catching 'instanceof Error' will not catch parse errors.","severity":"gotcha","affected_versions":">=0.6.0"},{"fix":"Use parse for multi-statement scripts, or pass allowTrailing: true to parseStmt for incremental parsing.","message":"parseStmt by default rejects trailing content (e.g., multiple semicolon-separated statements). This differs from parse which accepts multiple statements.","severity":"gotcha","affected_versions":">=0.6.0"},{"fix":"Access result.root instead of result.ast, and check result.status before accessing root.","message":"In v0.6.0, the return type changed from {ast} to {root} and added status field. Old code using result.ast will break.","severity":"breaking","affected_versions":"<0.6.0"}],"env_vars":null,"search_vec":"'0.7.1':22 '1':9 '200x':71 '2x':70 '2x-200x':69 '32':34 'altern':52 'ast':88 'browser':31 'bun':29 'common':47 'compar':50 'connect':66 'cst':83 'databas':65 'e.g':78 'error':40 'expect':44 'fast':5 'faster':72 'generat':15 'grammar':20 'gzip':36 'hint':49 'improv':39 'javascript':7,75,84 'kb':35 'lalr':8,89 'like':53 'locat':43 'messag':41 'mistak':48 'nene/query-lang':79 'node':28,57 'node-sqlite3':56 'parse.y':19 'parser':3,10,63,77,82,87 'provid':38 'pure':6,61 'run':26 'ship':23 'sql':13,76,81,85 'sql-parser-cst':80 'sql.js':54 'sqlite':12,17,86 'sqlite3':2,58,92 'sqlite3-parser':1 'syntax':14,90 'token':45,91 'type':25 'typescript':24,93 'version':21","created_at":"2026-04-27T17:05:00.423048+00:00","updated_at":"2026-04-27T17:05:00.423048+00:00","problems":[{"fix":"Replace require('sqlite3-parser') with import { parse } from 'sqlite3-parser'.","cause":"Trying to require() the package which is ESM-only since v0.7.0.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module: /node_modules/sqlite3-parser/index.js require() of ES modules is not supported."},{"fix":"Use result.root instead of result.ast, and check result.status === 'ok' first.","cause":"Accessing result.ast in code written for pre-0.6.0 API.","error":"TypeError: result.ast is undefined"},{"fix":"Check error message and location. Use parseStmt with allowTrailing to isolate problematic statements.","cause":"Input SQL contains syntax errors or unsupported SQLite features.","error":"ParseError: unexpected token at position X"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/justjake/sqlite3-parser-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sqlite3-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}