binsql
v0.0.2
Published
Allowlisted SQL parser and serializer for canonical PostgreSQL output
Downloads
259
Maintainers
Readme
binsql
binsql parses an allowlisted SQL dialect into its own AST and serializes that
AST into canonical PostgreSQL SQL. The original input string is never forwarded
to PostgreSQL.
The current implementation includes the first runtime slice plus early migration support:
- Chevrotain-backed lexing and statement admission.
- Pratt expression parsing for arithmetic, predicates, casts, functions, CTEs, joins, window functions, and pgvector distance operators.
- Project-schema normalization for table references.
- Migration DDL for
CREATE TABLE,CREATE INDEX,DROP TABLE, and selectedALTER TABLEhelpers. - Bun tests that validate serialized SQL with
libpg-query, including curated corpus fixtures undertest/fixtures/corpus.
API
import { compile, parse, serialize } from "binsql";
const result = compile("select id from users where email = $1", {
mode: "runtime",
projectSchema: "project_abc_main",
parameters: ["[email protected]"],
});
console.log(result.sql);Development
To install dependencies:
bun installTo test:
bun testTo typecheck:
bun run typecheckTo prepare a release:
bun run changeset
bun run version-packagesTo build the npm package locally:
bun run build:npm