Skip to main content

qail_core/
lib.rs

1//! QAIL AST Kernel.
2//!
3//! Build database intent as typed AST, not application-assembled SQL strings.
4//! The AST can then be validated, policy-checked, formatted, encoded for a
5//! driver, or inspected by tooling.
6//!
7//! Main concepts:
8//!
9//! - `Qail`: the primary command builder for `get`, `add`, `set`, `del`,
10//!   `put`, `merge_into`, CTEs, filters, projections, and returning clauses.
11//! - `access`: native table/operation/column policy checks.
12//! - `rls`: tenant/user/super-admin execution context witnesses.
13//! - `migrate`: `schema.qail` parsing, diffing, and migration model types.
14//! - `build`: source scanner helpers for stale schema references and N+1
15//!   diagnostics.
16//!
17//! ```ignore
18//! use qail_core::prelude::*;
19//!
20//! let ctx = RlsContext::tenant("018f6a60-4d5f-7a9d-9f4c-7dd8c338f1d2");
21//! let cmd = Qail::get("users")
22//!     .columns(["id", "email"])
23//!     .eq("active", true)
24//!     .with_rls(&ctx)?;
25//! ```
26
27/// Native vertical access policy checks for QAIL commands.
28pub mod access;
29#[cfg(feature = "analyzer")]
30pub mod analyzer;
31/// Abstract syntax tree types.
32pub mod ast;
33/// Schema branching.
34pub mod branch;
35/// Build-time schema validation.
36pub mod build;
37/// Code generation for typed schema modules.
38pub mod codegen;
39/// Configuration types.
40pub mod config;
41/// Error types.
42pub mod error;
43/// SQL formatter.
44pub mod fmt;
45/// Database migration types.
46pub mod migrate;
47/// Query normalization and optimizer support.
48pub mod optimizer;
49/// QAIL query parser.
50pub mod parser;
51/// Row-level security context.
52pub mod rls;
53/// AST structural sanitization for untrusted binary input.
54pub mod sanitize;
55/// Schema definitions for validation.
56pub mod schema;
57/// Filesystem schema source loader (`schema.qail` or modular `schema/`).
58pub mod schema_source;
59/// SQL transpiler (AST to SQL).
60pub mod transpiler;
61/// Typed column and table traits.
62pub mod typed;
63/// Schema validator.
64pub mod validator;
65/// Versioned AST wire codecs (text + QWB2 binary).
66pub mod wire;
67
68#[cfg(test)]
69mod proptest;
70
71pub use parser::parse;
72
73/// Ergonomic alias for Qail - the primary query builder type.
74pub type Qail = ast::Qail;
75
76/// Common re-exports for convenient wildcard imports.
77pub mod prelude {
78    pub use crate::ast::builders::{
79        // Extension traits
80        ExprExt,
81        add_expr,
82        all,
83        and,
84        and3,
85        avg,
86        binary,
87        bind,
88        boolean,
89        case_when,
90        // Expression builders
91        cast,
92        // Function builders
93        coalesce,
94        // Column builders
95        col,
96        concat,
97        cond,
98        // Aggregate builders
99        count,
100        count_distinct,
101        count_filter,
102        count_where,
103        count_where_all,
104        // Condition builders
105        eq,
106        float,
107        func,
108        gt,
109        gte,
110        ilike,
111        in_list,
112        inc,
113        int,
114        interval,
115        is_in,
116        is_not_null,
117        is_null,
118        // JSON builders
119        json,
120        json_obj,
121        json_path,
122        like,
123        lt,
124        lte,
125        max,
126        min,
127        ne,
128        not_in,
129        now,
130        now_minus,
131        now_plus,
132        null,
133        nullif,
134        param,
135        percentage,
136        // Shortcut helpers
137        recent,
138        recent_col,
139        replace,
140        star,
141        sum,
142        // Literal builders
143        text,
144    };
145    pub use crate::ast::*;
146
147    pub use crate::Qail;
148    pub use crate::access::*;
149    pub use crate::error::*;
150    pub use crate::parser::parse;
151    pub use crate::transpiler::ToSql;
152}