๐ฏ Vision
"If it compiles, the query is correct."
The Evolution
Era 1 SQL Strings "Trust me, this string is safe"
Era 2 ORMs "Safe, but locked to one language"
Era 3 Query Builders "Safe, but still generates strings"
Era 4 SQLx "Compile-time checked SQL โ the breakthrough"
Era 5 QAIL "Pure AST that compiles directly to wire protocol"
Acknowledgment: SQLx pioneered compile-time SQL
validation in Rust and remains the gold standard for SQL-based
database access. QAIL builds on this foundation by eliminating
strings entirely โ a natural evolution, not a replacement.
โ Completed
Done 1. First-Class Relations v0.16.0
Phase 1 ยท Runtime Registry
- โ
ref:syntax inschema.qail - โ
RelationRegistryfor runtime lookup - โ
Qail::join_on("table")โ string-based API
Phase 2 ยท Fully Typed Codegen
- โ
build.rsgeneratesschema_gen.rswith typed structs - โ
TypedColumn<T>with Rust type mapping (SQLโRust) - โ Table structs implement
Tabletrait
Phase 3 ยท Logic-Safe Relations
- โ
RelatedTo<T>trait with bidirectional impls fromref: - โ
TypedQail<T>+join_related()โ compile error if unrelated
Phase 4 ยท Compile-Time Data Governance
- โ
protectedkeyword inschema.qail - โ
TypedColumn<T, P>withPublic/Protectedmarkers - โ Compile-time policy enforcement via type system
Done 2. SaaS Multi-Tenant Isolation (RLS) v0.15.6
Phase 1 ยท Driver-Level Context
- โ
RlsContextstruct โ operator_id, agent_id, is_super_admin - โ
PgDriver.set_rls_context(ctx)โ callsset_config()
Phase 2 ยท Pool-Level RLS Acquisition
- โ
PgPool.acquire_with_rls(ctx)โ acquire + set in one call - โ
PooledConnectionauto-clears RLS on Drop โ no stale tenant leaks
Phase 3 ยท Policy Definition API
- โ
RlsPolicybuilder +AlterOp::ForceRowLevelSecurity - โ SQL transpiler for ENABLE + FORCE + CREATE POLICY
Phase 4 ยท AST-Level Query Injection
- โ
TenantRegistryauto-detects tables withoperator_id - โ
Qail::with_rls(ctx)โ GETโfilter, ADDโpayload injection - โ Super admins + unregistered tables bypass automatically
Done 3. Schema DDL โ Full PostgreSQL Coverage v0.18.5
Phase 1 ยท Core Objects
- โ CREATE/DROP EXTENSION, ENUM, SEQUENCE
- โ CREATE/ALTER/DROP TABLE with all column properties
- โ Multi-column foreign keys, expression indexes
Phase 2 ยท Programmable Objects
- โ Views + Materialized Views
- โ Functions (PL/pgSQL) + Triggers
- โ GRANT/REVOKE, COMMENT ON,
enable_rls/force_rls
Phase 3 ยท RLS Policy Definition
- โ Policy syntax in
.qailโ permissive + restrictive - โ Per-command scope: ALL, SELECT, INSERT, UPDATE, DELETE
- โ Role targeting:
to app_user
Done 4. Database Introspection โ Fully AST-Native v0.18.5
Phase 1 ยท Core Introspection
- โ
qail pull --url postgres://...โschema.qail - โ Tables, columns, types, defaults, constraints, indexes
- โ FKs with actions (CASCADE, SET NULL, RESTRICT, etc.)
Phase 2 ยท Programmable Objects
- โ Views, materialized views, functions, triggers
- โ Grants, sequences, enums, extensions
Phase 3 ยท Zero Raw SQL
- โ RLS policies via
Qail::get("pg_policies") - โ
policy_parsermodule for SQLโExpr conversion - โ Zero raw SQL in introspection โ every query is AST-native
Done 5. Migration Engine v0.15.9
Phase 1 ยท Schema Diffing
- โ
diff_schemas()โ old vs new comparison - โ
AlterOpenum with intent-aware hints: rename, transform, drop confirm - โ FK-ordered table creation (parent before child)
Phase 2 ยท CLI Commands
- โ
qail migrate apply,create,status,reset,up,down - โ
qail diff --liveโ schema drift detection
Phase 3 ยท Enterprise Features
- โ Shadow migrations โ COPY streaming, safe promote
- โ
MigrationClass: Reversible, DataLosing, Irreversible - โ
qail migrate analyzeโ scans codebase for affected queries
Done 6. Multi-Driver Unified AST v0.14.13
5,000 q/s
Prepared Statements
1.3M q/s
10-conn Pool
13%
Faster than Qdrant SDK
- โ PostgreSQL โ zero-copy wire protocol, SCRAM-SHA-256, TLS, COPY streaming
- โ Qdrant โ zero-copy gRPC, HTTP/2 batch pipelining, connection pool
- โ Redis โ native RESP3 protocol,
Qail::redis_get()/redis_set()
Done 7. CLI Toolchain v0.15.7
- โ
qail initโ project scaffold (supports--url,--deployment) - โ
qail pullโ live DB โschema.qail(fully AST-native) - โ
qail execโ type-safe execution (--json,--tx) - โ
qail diffโ schema comparison + drift detection - โ
qail typesโschema.qailโ Rust typed schema module - โ
qail checkโ validate.qailsyntax - โ
qail workerโ hybrid outbox daemon (PG โ Qdrant sync) - โ LSP server (
qail-lsp) for editor integration
๐ฎ Future
Next 8. Schema-as-Proof System
"The schema becomes a type parameter. The compiler becomes the theorem prover."
Phase 1 ยท Column Existence Proof
- โ
schema.qailโ codegen โSchematrait with associated types - โ
Qail<S: Schema>carries schema as phantom type parameter - โ Column selection proven at compile time โ no proc macros, no external provers
Phase 2 ยท Type-Safe Filters
- โ Filter comparisons proven against column types
- โ
TypedFilter<S>ensures operand type matches column type
Phase 3 ยท Join Validity Graph
- โ FK relationship graph encoded at type level
- โ N-way joins proven valid via
RelatedTo<T>chain
Phase 4 ยท RLS Proof Witness
- โ RLS-protected tables get marker trait
- โ Queries without
.with_rls()on protected tables = compile error - โ
RlsProof<T>witness type provided by middleware
"Data leakage becomes a type error, not a security incident."
Planned 9. Native Versioning (Data Virtualization)
"GitHub for Databases" โ branching at the application layer.
- โ Gateway middleware with
X-Branch-IDheader - โ Row-level branching (
WHERE _branch_id = ?) - โ Copy-on-Write strategy for writes
- โ CLI:
qail branch create,qail checkout
Planned 10. Infrastructure-Aware Compiler
Verify external resources at compile time.
- โ
schema.qailextensions:bucket,queue,topic - โ
build.rsvalidates resources exist in Terraform/AWS/GCP - โ Compile error if referencing non-existent infra
๐ Current Status
| Section | Status | Version |
|---|---|---|
| 1. First-Class Relations | โ Complete (4/4) | v0.16.0 |
| 2. SaaS RLS Isolation | โ Complete (4/4) | v0.15.6 |
| 3. Schema DDL Coverage | โ Complete (3/3) | v0.18.5 |
| 4. Database Introspection | โ Complete (3/3) | v0.18.5 |
| 5. Migration Engine | โ Complete (3/3) | v0.15.9 |
| 6. Multi-Driver AST | โ Complete | v0.14.13 |
| 7. CLI Toolchain | โ Complete | v0.15.7 |
| 8. Schema-as-Proof | โณ Planned | โ |
| 9. Data Virtualization | โณ Planned | โ |
| 10. Infra-Aware Compiler | โณ Planned | โ |
๐ก Philosophy
"QAIL eliminates SQL strings entirely. The builder API (Qail::get(), Qail::add()) is the ONLY way to construct queries. No parsing at runtime, no strings anywhere."