Registry / database / sqlite-ast

sqlite-ast

JSON →
library0.0.7jsnpmunverified

Parse SQLite SQL syntax into an abstract syntax tree (AST). Version 0.0.7 is the latest. This package provides a lightweight, typed AST for SQLite queries, built on top of a parser generated from the SQLite grammar. It supports both parsing of raw SQL and a tagged template literal for safe query construction. Requires Node.js 22+. Features type definitions included, making it suitable for TypeScript projects. The library is minimal with no runtime dependencies.

npm install sqlite-ast
INSTALL
IMPORT
SIG · SQLITE-AST
S
sqlite-ast
databasejavascriptv0.0.7
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.

parseSqlite
import { parseSqlite } from 'sqlite-ast'
const parseSqlite = require('sqlite-ast').parseSqlite
Module is ESM-only; CommonJS require will fail with ERR_REQUIRE_ESM unless using dynamic import.
sql
import { sql } from 'sqlite-ast'
The `sql` tagged template literal is used to safely interpolate values into SQL strings. Also ESM-only.
SqliteAstNode
import type { SqliteAstNode } from 'sqlite-ast'
import { SqliteAstNode } from 'sqlite-ast'
TypeScript type-only import. In some TypeScript configurations, mixing type and runtime imports may cause issues.
parseSqlite
import { parseSqlite } from 'sqlite-ast'
import parseSqlite from 'sqlite-ast'
The library does not have a default export; must use named import.

Parses a SQLite SELECT statement using the `sql` tagged template and prints the resulting AST.

import { parseSqlite, sql } from 'sqlite-ast'; const ast = parseSqlite(sql`SELECT name FROM users WHERE age > 21;`); console.log(ast); // Outputs AST object representing the parsed SQL
Debug
Known issues
breakingMissing Node.js 22+ required.
fix
Upgrade Node.js to version 22 or later.
affects: >=0.0.1
gotchaESM-only: require() will throw ERR_REQUIRE_ESM.
fix
Use dynamic import() or set type:"module" in package.json.
affects: >=0.0.1
gotchaAST structure not stable across minor versions.
fix
Pin exact version and review AST changes when upgrading.
affects: >=0.0.0
gotchasql tagged template does not escape identifiers.
fix
Use parameterized queries separately; sql only interpolates values as literals.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find package 'sqlite-ast'
Package not installed.
fix
Run `npm install sqlite-ast`
ERR_REQUIRE_ESM
Using require() on an ESM-only package.
fix
Change to import or use dynamic import().
TypeError: parseSqlite is not a constructor
Incorrect import style, e.g., using `new parseSqlite()` or default import.
fix
Use import { parseSqlite } from 'sqlite-ast' without 'new'.
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Meta
1
OpenAI (training)
1
Resources
sqlite-ast — npm install sqlite-ast · libregistry