qail 0.2.0

The Horizontal Query Language β€” Stop writing strings. Hook your data.
Documentation

πŸͺ QAIL β€” The Horizontal Query Language

Stop writing strings. Hook your data.

Crates.io License Rust


The Manifesto

SQL is vertical, verbose, and clunky inside modern codebases.

QAIL is horizontal, dense, and composable. It treats database queries like a pipeline, using symbols to hook data and pull it into your application.

-- The Old Way (SQL)
SELECT id, email, role FROM users WHERE active = true LIMIT 1;
# The QAIL Way
get::usersβ€’@id@email@role[active=true][lim=1]

One line. Zero ceremony. Maximum velocity.


πŸ“– Quick Reference

Symbol Name Function SQL Equivalent
:: The Gate Defines the action SELECT, INSERT, UPDATE
β€’ The Pivot Connects action to table FROM table
@ The Hook Selects specific columns col1, col2
[] The Cage Constraints & Filters WHERE, LIMIT, SET
~ The Fuse Fuzzy / Partial Match ILIKE '%val%'
| The Split Logical OR OR
& The Bind Logical AND AND
^! The Peak Sort Descending ORDER BY ... DESC
^ The Rise Sort Ascending ORDER BY ... ASC
* The Star All / Wildcard *
[*] The Deep Array Unnest UNNEST(arr)
$ The Var Parameter Injection $1, $2

πŸš€ Installation

CLI (Recommended)

cargo install qail

As a Library

# Cargo.toml
[dependencies]
qail = "0.1"

πŸ’‘ Usage

CLI β€” The qail Command

# Fetch all users
qail 'get::usersβ€’@*'

# Get specific columns with filter
qail 'get::ordersβ€’@id@total@status[user_id=$1][lim=10]' --bind 42

# Update a record
qail 'set::usersβ€’[verified=true][id=$1]' --bind 7

# Delete with condition
qail 'del::sessionsβ€’[expired_at<now]'

# Transpile only (don't execute)
qail 'get::usersβ€’@*[active=true]' --dry-run

As a Library

use qail::prelude::*;

#[tokio::main]
async fn main() -> Result<(), QailError> {
    let db = QailDB::connect("postgres://localhost/mydb").await?;

    // Parse and execute
    let users: Vec<User> = db
        .query("get::usersβ€’@id@email@role[active=true][lim=10]")
        .fetch_all()
        .await?;

    // Or use the builder for type-safe composition
    let query = qail::get("users")
        .hook(&["id", "email", "role"])
        .cage("active", true)
        .limit(10);

    let users: Vec<User> = db.run(query).fetch_all().await?;

    Ok(())
}

πŸ“š Syntax Deep Dive

A. Simple Fetch (get::)

-- SQL
SELECT id, email, role FROM users WHERE active = true LIMIT 1;
# QAIL
get::usersβ€’@id@email@role[active=true][lim=1]

B. Mutation (set::)

-- SQL
UPDATE user_verifications SET consumed_at = now() WHERE id = $1;
# QAIL
set::user_verificationsβ€’[consumed_at=now][id=$1]

Note: In set:: mode, the first [] is the payload (SET), the second [] is the filter (WHERE).


C. Deletion (del::)

-- SQL
DELETE FROM sessions WHERE expired_at < now();
# QAIL
del::sessionsβ€’[expired_at<now]

D. Complex Search with Fuzzy Match

-- SQL
SELECT * FROM ai_knowledge_base 
WHERE active = true 
AND (topic ILIKE $1 OR question ILIKE $1 OR EXISTS (SELECT 1 FROM unnest(keywords) k WHERE k ILIKE $1))
ORDER BY created_at DESC
LIMIT 5;
# QAIL
get::ai_knowledge_baseβ€’@*[active=true][topic~$1|question~$1|keywords[*]~$1][^!created_at][lim=5]

# Or multi-line for readability:
get::ai_knowledge_baseβ€’@*
  [active=true]
  [topic~$1 | question~$1 | keywords[*]~$1]
  [^!created_at]
  [lim=5]

E. Joins (Coming Soon)

# Inner join
get::ordersβ€’@*>>users.id=orders.user_idβ€’@users.email[status=paid]

# Left join
get::productsβ€’@*>|categories.id=products.cat_idβ€’@categories.name

βš™οΈ Configuration

Create a .qailrc or qail.toml in your project root:

[connection]
driver = "postgres"           # postgres | mysql | sqlite
url = "postgres://localhost/mydb"

[output]
format = "table"              # table | json | csv
color = true

[safety]
confirm_mutations = true      # Prompt before UPDATE/DELETE
dry_run_default = false

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      QAIL Pipeline                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                             β”‚
β”‚   "get::usersβ€’@*[active=true]"                              β”‚
β”‚              β”‚                                              β”‚
β”‚              β–Ό                                              β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
β”‚   β”‚   Parser (nom)      β”‚  β†’ Tokenize symbols               β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
β”‚             β”‚                                               β”‚
β”‚             β–Ό                                               β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
β”‚   β”‚   AST (QailCmd)     β”‚  β†’ Structured representation      β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
β”‚             β”‚                                               β”‚
β”‚             β–Ό                                               β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
β”‚   β”‚ Transpiler (SQL)    β”‚  β†’ Generate valid SQL             β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
β”‚             β”‚                                               β”‚
β”‚             β–Ό                                               β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
β”‚   β”‚ Engine (sqlx)       β”‚  β†’ Execute against DB             β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
β”‚                                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Structs

pub struct QailCmd {
    pub action: Action,         // GET, SET, DEL, ADD
    pub table: String,
    pub columns: Vec<Column>,
    pub cages: Vec<Cage>,       // Filters, limits, sorts
    pub bindings: Vec<Value>,
}

pub enum Action {
    Get,    // SELECT
    Set,    // UPDATE
    Del,    // DELETE
    Add,    // INSERT
}

pub struct Cage {
    pub kind: CageKind,         // Filter, Limit, Sort, Payload
    pub conditions: Vec<Condition>,
}

pub struct Condition {
    pub column: String,
    pub op: Operator,           // Eq, Ne, Gt, Lt, Fuzzy, In
    pub value: Value,
}

πŸ—ΊοΈ Roadmap

Phase 1: Parser βœ…

  • Lexer for QAIL symbols
  • nom parser combinators
  • AST generation

Phase 2: Transpiler 🚧

  • PostgreSQL codegen
  • MySQL codegen
  • SQLite codegen
  • Query optimization hints

Phase 3: Engine πŸ”œ

  • Async execution (sqlx)
  • Connection pooling
  • Transaction support
  • Prepared statement caching

Phase 4: Ecosystem πŸ“‹

  • VS Code extension (syntax highlighting)
  • Language server (LSP)
  • REPL mode
  • Schema introspection

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

# Clone the repo
git clone https://github.com/your-username/qail.git
cd qail

# Run tests
cargo test

# Run with example
cargo run -- "get::usersβ€’@*[lim=5]" --dry-run

πŸ“„ License

MIT Β© 2025 QAIL Contributors