This repo is a sandbox, not a product. It was written as a trial-and-error exercise to learn how to build a JQL-style query DSL — lexer, parser, AST visitor, and SQL compilation — before taking on the real implementation. Expect incomplete features and a few dead ends.
The "real thing" will be built as a separate project, informed by what was learned here.
- How to design a small grammar and express it with Chevrotain (tokens, CST parser rules, visitors).
- How to turn a parsed tree into an intermediate representation that a downstream compiler can consume.
- How to wire that into TypeORM and go from parsed query → executable SQL.
- How to auto-generate entity classes from a live database schema.
(Entity prop operator value) [And|Or (Entity prop operator value) ...]
Examples:
(User age > 18)
(User gender = "F") And (User age > 18)
Flow:
input string
→ lexer (Chevrotain tokens)
→ parser (CST)
→ visitor (normalized IR)
→ query builder (SQL string)
- Tokenizing and parsing the grammar above.
- Visiting the CST into a flat list of
VisitedStatements joined by conjunctions. - Compiling that list into a
SELECT * FROM <entity> WHERE …string. - Validating entity and property names against a supplied metadata map.
- Generating TypeORM entity classes from a database via
typeorm-model-generator.
npm install
npm test # Jasmine suite
npm run dev # Nodemon on src/index.ts
npm run tsc # Type-check + build to main/
Configure .env:
HOST=localhost
DB_NAME=my_db
USER_NAME=my_user
PASSWORD=***
DB_TYPE=mysql
OUTPUT_PATH=./src/lib/ORM/
Then:
npm run generate-types
src/
├── index.ts
└── lib/
├── lexer/ # Chevrotain tokens
├── parser/ # CST parser rules
├── visitor/ # CST → IR
└── ORM/
├── db-connector/ # TypeORM DataSource factory
├── query-builder/ # IR → SQL
├── entities/ # Generated entity classes
└── scripts/ # generate-types.js
- FilterManager — part one, the consumer of the DSL this branch was exploring.
Archived as a reference. The production implementation lives elsewhere (or will). Please don't depend on this package.