Registry / database / sql-crafter

sql-crafter

JSON →
library0.9.1jsnpmunverified

sql-crafter is a TypeScript library for parsing, formatting, and transforming SQL queries. Currently at version 0.9.1, it is in early development (WIP). It provides structured parsing of SQL statements along with formatting and transformation utilities, inspired by dt-sql-parser. The library ships TypeScript types and is designed for Node.js environments. Key differentiators include a modular architecture separating parser, formatter, and transformer concerns, and a focus on extensibility. However, due to its early stage, APIs may change, and documentation is minimal.

npm install sql-crafter
INSTALL
IMPORT
SIG · SQL-CRAFTER
S
sql-crafter
databasejavascriptv0.9.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.

parse
import { parse } from 'sql-crafter'
const { parse } = require('sql-crafter')
ESM-only; CommonJS require will fail.
format
import { format } from 'sql-crafter'
import { sqlFormatter } from 'sql-crafter'
Named export is 'format', not 'sqlFormatter'.
transform
import { transform } from 'sql-crafter'
Direct named import.
SqlParser
import { SqlParser } from 'sql-crafter'
Class name is SqlParser, not SQLParser or sqlParser.

Parses, formats, and transforms a simple SELECT SQL query using the three main exports.

import { parse, format, transform } from 'sql-crafter'; const sql = 'SELECT a, b FROM t WHERE c=1'; const parsed = parse(sql); console.log(JSON.stringify(parsed, null, 2)); const formatted = format(sql); console.log(formatted); const rule = { where: (node) => { node.value = 'c=2'; return node; } }; const transformed = transform(sql, rule); console.log(transformed);
Debug
Known issues
breakingAPI is unstable and may change without notice
fix
Pin exact version and review changelog before upgrading.
affects: <1.0.0
gotchaparse() may throw on invalid SQL; no error recovery
fix
Wrap parse calls in try/catch.
affects: >=0.0.0
gotchaformat() output may not preserve all whitespace or comments
fix
Review formatted output for important formatting.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token: identifier
Input SQL is not valid syntax for the parser.
fix
Check SQL syntax and ensure it is supported by the parser.
TypeError: rule.apply is not a function
transform expects a rule object with function properties, but passed something else.
fix
Provide a rule object like { where: (node) => { ... } }.
Upgrade
Version history
0.9.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Meta
1
OpenAI (training)
1
Resources