Registry / serialization / sql-compiler

sql-compiler

JSON →
library1.0.2jsnpmunverified

A SQL compiler library for Node.js (version 1.0.2, latest) that tokenizes, parses, and generates SQL, allowing dynamic editing of the query AST. Releases are infrequent (no recent updates). Differentiators: provides a full pipeline (tokenizer, parser, code generator) and a manipulable AST, unlike pure SQL parsers. Requires Node >=15 (ESM-only). Not widely adopted; use with caution for production.

npm install sql-compiler
INSTALL
IMPORT
SIG · SQL-COMPILER
S
sql-compiler
serializationjavascriptv1.0.2
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.

tokenizer
import tokenizer from 'sql-compiler/modules/tokenizer.mjs'
import tokenizer from 'sql-compiler/tokenizer'
The package uses explicit .mjs extensions; imports must include the full path including file extension.
parser
import parser from 'sql-compiler/modules/parser/parser.mjs'
import parser from 'sql-compiler/parser'
Parser is nested under modules/parser/; common mistake is to use the wrong path.
codeGenerator
import codeGenerator from 'sql-compiler/modules/code-generator.mjs'
import codeGenerator from 'sql-compiler/code-generator'
Code generator is at modules/code-generator.mjs, not a top-level export.

Parses a SQL SELECT query, manipulates the AST to add a column, and generates the updated SQL string.

import tokenizer from 'sql-compiler/modules/tokenizer.mjs'; import parser from 'sql-compiler/modules/parser/parser.mjs'; import codeGenerator from 'sql-compiler/modules/code-generator.mjs'; const sql = `SELECT 'Leonardo' AS name, 'Dicaprio' AS lastname FROM dual l`; const tokens = tokenizer(sql); const { value: ast } = parser(tokens); ast.value.columns.push({ type: 'NUMERIC', value: '20', alias: 'age' }); const updatedSql = codeGenerator(ast); console.log(updatedSql); // Output: SELECT 'Leonardo' AS name, 'Dicaprio' AS lastname, 20 AS age FROM dual l
Debug
Known issues
gotchaImports require full file paths with .mjs extension; using shorthand paths fails.
fix
Use exact import paths like 'sql-compiler/modules/tokenizer.mjs'.
affects: >=1.0.0
gotchaParser expects a token array from tokenizer; passing raw SQL string to parser will fail.
fix
Always tokenize first: parser(tokenizer(sql)).
affects: >=1.0.0
gotchaThe AST structure is specific to this compiler; direct manipulation may break if query structure differs.
fix
Study the AST format in documentation before manipulating.
affects: >=1.0.0
gotchaOnly SELECT statements are fully supported; other SQL statements may not parse correctly.
fix
Currently limited to SELECT; avoid using for INSERT/UPDATE/DELETE.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'sql-compiler/tokenizer'
Missing full path with .mjs extension in import.
fix
import tokenizer from 'sql-compiler/modules/tokenizer.mjs';
TypeError: parser(...) is not a function or parser is undefined
Parser import path is incorrect.
fix
import parser from 'sql-compiler/modules/parser/parser.mjs';
TypeError: Cannot read properties of undefined (reading 'value')
Passing raw SQL string to parser instead of tokens.
fix
parser(tokenizer(sql)) and ensure tokenizer returns an array.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Meta
1
OpenAI (training)
1
Resources
sql-compiler — npm install sql-compiler · libregistry