{"id":26425,"library":"sql-compiler","title":"sql-compiler","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/leoelias023/sql-compiler","tags":["javascript","sql","compiler","parser"],"install":[{"cmd":"npm install sql-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add sql-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-compiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package uses explicit .mjs extensions; imports must include the full path including file extension.","wrong":"import tokenizer from 'sql-compiler/tokenizer'","symbol":"tokenizer","correct":"import tokenizer from 'sql-compiler/modules/tokenizer.mjs'"},{"note":"Parser is nested under modules/parser/; common mistake is to use the wrong path.","wrong":"import parser from 'sql-compiler/parser'","symbol":"parser","correct":"import parser from 'sql-compiler/modules/parser/parser.mjs'"},{"note":"Code generator is at modules/code-generator.mjs, not a top-level export.","wrong":"import codeGenerator from 'sql-compiler/code-generator'","symbol":"codeGenerator","correct":"import codeGenerator from 'sql-compiler/modules/code-generator.mjs'"}],"quickstart":{"code":"import tokenizer from 'sql-compiler/modules/tokenizer.mjs';\nimport parser from 'sql-compiler/modules/parser/parser.mjs';\nimport codeGenerator from 'sql-compiler/modules/code-generator.mjs';\n\nconst sql = `SELECT 'Leonardo' AS name, 'Dicaprio' AS lastname FROM dual l`;\nconst tokens = tokenizer(sql);\nconst { value: ast } = parser(tokens);\nast.value.columns.push({ type: 'NUMERIC', value: '20', alias: 'age' });\nconst updatedSql = codeGenerator(ast);\nconsole.log(updatedSql);\n// Output: SELECT 'Leonardo' AS name, 'Dicaprio' AS lastname, 20 AS age FROM dual l","lang":"javascript","description":"Parses a SQL SELECT query, manipulates the AST to add a column, and generates the updated SQL string."},"warnings":[{"fix":"Use exact import paths like 'sql-compiler/modules/tokenizer.mjs'.","message":"Imports require full file paths with .mjs extension; using shorthand paths fails.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always tokenize first: parser(tokenizer(sql)).","message":"Parser expects a token array from tokenizer; passing raw SQL string to parser will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Study the AST format in documentation before manipulating.","message":"The AST structure is specific to this compiler; direct manipulation may break if query structure differs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Currently limited to SELECT; avoid using for INSERT/UPDATE/DELETE.","message":"Only SELECT statements are fully supported; other SQL statements may not parse correctly.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"import tokenizer from 'sql-compiler/modules/tokenizer.mjs';","cause":"Missing full path with .mjs extension in import.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'sql-compiler/tokenizer'"},{"fix":"import parser from 'sql-compiler/modules/parser/parser.mjs';","cause":"Parser import path is incorrect.","error":"TypeError: parser(...) is not a function or parser is undefined"},{"fix":"parser(tokenizer(sql)) and ensure tokenizer returns an array.","cause":"Passing raw SQL string to parser instead of tokens.","error":"TypeError: Cannot read properties of undefined (reading 'value')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}