A real query compiler — not a string parser

WRITE
FILTERS.
COMPILE TO
ANY DB.

FlexQL takes untrusted filter strings through a Validation → Lexer → Parser → AST → Adapter pipeline and emits injection-safe queries for SQL, Sequelize, MongoDB, and Prisma.

100%
TypeScript
N-ary
AST Engine
4
Adapters
0
Raw Strings
Input Query String
username==heja;age>18,status==active
validation + lexical analysis
Validation
Check types · Reject invalid chars · Normalize params
tokenize
Lexer — Token Stream
username=="heja" AND age>18 OR status=="active"
parse → N-ary AST
Parser — AST
OR
├─ AND
│  ├─ username=="heja"
│  └─ age>18
└─ status=="active"
compile output
Adapter — Safe Output
WHERE username = ? AND age > ? OR status = ?
values: ["heja", 18, "active"]
Design Philosophy

A COMPILER,
NOT AN INTERPRETER

Most query helpers evaluate filter logic at runtime. FlexQL compiles it — the distinction matters deeply for safety, portability, and predictability.

❌ Interpreter Approach

Reads the filter string and directly executes it against data. Runtime and logic are coupled — you can't separate "what" from "how".

  • Evaluates input at runtime — hard to audit
  • Injection risk if any path allows raw passthrough
  • Tied to one execution model — can't retarget backends
  • No intermediate representation to validate or optimize

✅ FlexQL — Compiler Approach

Transforms the filter string into a backend-specific query structure. Input is never executed — it's compiled.

  • Input → Tokens → AST → Target output. Fully auditable pipeline
  • Values always bound as parameters, never concatenated
  • Swap adapters without touching filter logic
  • AST can be validated, cached, or optimized before compilation
Architecture

THE FULL
PIPELINE

Every query passes through a deterministic, layered compilation pipeline. No step is skipped, no raw input reaches any backend.

1
Developer's App
A UserRequest arrives via HTTP / query params. The developer's application passes the raw query string into the FlexQL function — one call in, compiled output out.
2
Lexical Analysis
Before any parsing, the raw string is validated and tokenized. Invalid input is rejected here — nothing malformed ever reaches the parser.
Validation
Rejects invalid chars, checks types, normalizes parameters. Pipeline stops immediately on failure.
Lexer
Converts the validated string into a strict token stream: identifiers, operators, values, separators.
3
Parser — AST Construction
The parser detects whether the input is natural language or structured syntax, routes accordingly, and produces a Normalized AST Tree. The AST-Flatter unifies both paths into a single flat structure.
NLP?
Detect: free-form natural language input, or structured FlexQL syntax?
AI-AST-Parser
Natural language queries. AI model converts free-form text into a Normalized AST Tree (NAT).
Structured-AST-Parser
Standard FlexQL syntax. Builds N-ary AST directly from the token stream.
AST-FLATTER
Both paths converge here. Flatter normalizes both NATs into a single unified flat AST — adapters see one consistent format regardless of input type.
4
Router — Mapper
The Router dispatches the flat AST to the Mapper, which performs database-specific query mapping for each target adapter. Each adapter receives a mapping tailored to its own query model.
5
Adapters — Compiled Output
Each adapter walks the mapped AST and emits fully parameterized, database-specific query structures. Values are always bound — no raw strings ever emitted.
SQL
Live
Sequelize
Live
MongoDB
Coming soon
Prisma
Coming soon
Live Demo

ONE QUERY,
TWO BACKENDS

See how the same FlexQL expression compiles to SQL and Sequelize — both injection-safe and ready to use directly in your codebase.

FlexQL Input
QUERY STRING
username=="heja";age>18,status=="active"
PARSED LOGIC
( username == "heja" AND age > 18 )
OR
( status == "active" )
; = AND  ·  , = OR  ·  AND binds tighter than OR
Compiled Output
Language Reference

SYNTAX
REFERENCE

FlexQL's syntax is intentionally compact. Every token has a defined role in the compilation pipeline.

ElementRole in PipelineExamplesNotes
Identifier Field name — becomes IDENTIFIER token in lexer username, age, created_at No spaces allowed
Operator Comparison — mapped per adapter in output == != > < >= <= All 6 supported
; AND separator — higher precedence name==x;age>18 Default, configurable
, OR separator — lower precedence status==a,status==b Default, configurable
Value Literal — always bound as a parameter, never concatenated "heja", 18, true, 2025-01-01 String, number, boolean, date
Spaces cannot be used as separators. Use ; for AND and , for OR. Both are configurable.
Roadmap

WHAT'S BUILT.
WHAT'S NEXT.

The core compiler pipeline ships production-ready. The roadmap expands adapter coverage and adds NLP-powered natural language querying.

Core Compiler PipelineValidation → Lexer → Parser → N-ary AST → Adapter architecture in TypeScript
Shipped
SQL AdapterParameterized WHERE clause — safe from injection by construction
Shipped
Sequelize AdapterORM-compatible Op.or / Op.and condition objects, usable directly in Model.findAll()
Shipped
MongoDB AdapterNative $or / $and filter objects for MongoDB driver and Mongoose
Coming Soon
Prisma AdapterPrisma-compatible where clause generation for type-safe ORM integration
Coming Soon
AI-AST-Parser (NLP Path)Accept natural language — "users older than 18 who are active" — and compile to the same AST
Coming Soon
Elasticsearch AdapterQuery DSL output for full-text and structured search
Planned
Parenthesis & Nested ExpressionsExplicit grouping for complex multi-level logic
Planned
Type Inference & Schema ValidationValidate field types against your schema at compile time
Planned
Query OptimizerSimplify and deduplicate redundant conditions in the AST before compilation
Planned
Interactive FlexQL PlaygroundBrowser-based live compiler with real-time adapter output across all targets
Planned

START COMPILING

A real query compiler for modern APIs. Safe, portable, and extensible by design.