GitHunt
SC

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


schart/FlexQL | GitHunt