schart/FlexQL
FlexQL โ A powerful, secure, and extensible query language for flexible data filtering without complex SQL or ORM queries.
๐งฉ FlexQL
A lightweight yet powerful query language engine that lets you filter data without writing complex SQL or ORM queries.
๐ Overview
FlexQL provides a simple, readable, and database-agnostic way to write query filters.
Instead of writing complex SQL or ORM conditions, you can use a compact query syntax that is parsed and converted into database-specific queries.
Example Query
username==heja;age>18,status==active
Which means:
(username == "heja" AND age > 18) OR (status == "active")
โ ๏ธ Note: Spaces () cannot be used as separators in the query string.
โจ Features
- ๐ง Readable syntax โ intuitive and compact query format
- ๐ Flexible separators โ
;for AND,,for OR (customizable) - ๐ Secure parsing โ safe against SQL injection
- โ๏ธ Adapter-based architecture โ supports SQL, Sequelize, MongoDB and more
- ๐งฑ Lexer โ Parser โ Adapter pipeline โ modular and extensible
- ๐งช Validated syntax with type checking
- ๐งฐ Easy to extend โ create new adapters quickly
โ๏ธ How It Works
FlexQL processes queries through a compiler-like pipeline:
+--------+ +--------+ +------------+
| Lexer | --> | Parser | --> | Adapter(s) |
+--------+ +--------+ +------------+
| | |
Tokens N-ary AST SQL / Sequelize / Mongo
1๏ธโฃ Lexer
Breaks the raw query string into tokens.
2๏ธโฃ Parser
Validates syntax and builds an N-ary Abstract Syntax Tree (AST).
3๏ธโฃ Adapter
Converts the AST into database-specific output such as:
- Raw SQL
- Sequelize conditions
- (coming soon) MongoDB
- (coming soon) Elasticsearch
๐ณ AST Example
Query
username==heja;age>18,status==active
Generated AST (simplified)
{
"type": "OR",
"children": [
{
"type": "AND",
"children": [
{ "field": "username", "operator": "==", "value": "heja" },
{ "field": "age", "operator": ">", "value": 18 }
]
},
{ "field": "status", "operator": "==", "value": "active" }
]
}This demonstrates that FlexQL is not just a string parser, but a real query engine that constructs a structured representation of the query.
๐งฑ Adapter Outputs
๐น SQL Adapter
Query
CategoryName==Beverages ; age>10
Output
{
type: 'sql',
payload: {
conditions: 'WHERE CategoryName = ? AND age > ?',
values: ['Beverages', '10']
}
}โ Safe from SQL injection โ all values are parameterized.
๐น Sequelize Adapter
Query
username=="heja",country=="NL";score>90,rank>=5,level=="pro";created_at>="2025-01-01";updated_at<="2025-10-01",last_login>="2025-09-01";active==true,verified==true
Output
{
type: 'sequelize',
payload: {
conditions: {
where: [
{ created_at: { [Symbol(gte)]: '2025-01-01' } },
{ [Symbol(or)]: [ [Object], [Object] ] },
{ [Symbol(or)]: [ [Object], [Object], [Object] ] },
{ [Symbol(or)]: [ [Object], [Object] ] },
{ [Symbol(or)]: [ [Object], [Object] ] }
]
}
}
}This produces a fully Sequelize-compatible structure, usable directly in:
Model.findAll({ where: conditions.where });The adapter automatically groups AND (;) and OR (,) conditions.
๐ค Syntax Reference
| Element | Description | Examples |
|---|---|---|
| Identifier | Column / field name | username, age, status |
| Operator | Comparison operator | ==, !=, >, <, >=, <= |
| Logic | Combine conditions | ; (AND), , (OR), custom separators |
| Value | Value to match | "heja", 18, true |
๐งฉ Examples
Basic
username==test ; age>10
username==test , status==false
Complex Query
username=="heja",country=="NL";score>90,rank>=5;active==true,verified==true
๐ฆ Installation & Usage
Coming Soon
๐ก Why FlexQL?
- โ Readable queries even for complex filters
- ๐งฑ Unified syntax across multiple databases
- ๐ง Logical precedence support (AND > OR)
- ๐ Secure parameterized outputs
- ๐ Portable architecture via adapters
- ๐งฉ Highly modular design
๐งโ๐ป Use Cases
- Dynamic filtering in admin dashboards
- Building ORM-independent query engines
- Safe filtering in API query parameters
- Rule-based filtering systems
๐งญ Roadmap
- Sequelize adapter
- MongoDB adapter
- Elasticsearch adapter
- Parenthesis / nested query support
- Type inference
- Query optimizer
- FlexQL Playground
โ๏ธ License
MIT License
ยฉ 2025 Heja โxejaโ Arslan
