pub struct Qail {Show 39 fields
pub action: Action,
pub table: String,
pub columns: Vec<Expr>,
pub joins: Vec<Join>,
pub cages: Vec<Cage>,
pub distinct: bool,
pub index_def: Option<IndexDef>,
pub table_constraints: Vec<TableConstraint>,
pub set_ops: Vec<(SetOp, Box<Qail>)>,
pub having: Vec<Condition>,
pub group_by_mode: GroupByMode,
pub ctes: Vec<CTEDef>,
pub distinct_on: Vec<Expr>,
pub returning: Option<Vec<Expr>>,
pub on_conflict: Option<OnConflict>,
pub merge: Option<Merge>,
pub source_query: Option<Box<Qail>>,
pub channel: Option<String>,
pub payload: Option<String>,
pub savepoint_name: Option<String>,
pub from_tables: Vec<String>,
pub using_tables: Vec<String>,
pub lock_mode: Option<LockMode>,
pub skip_locked: bool,
pub fetch: Option<(u64, bool)>,
pub default_values: bool,
pub overriding: Option<OverridingKind>,
pub sample: Option<(SampleMethod, f64, Option<u64>)>,
pub only_table: bool,
pub vector: Option<Vec<f32>>,
pub score_threshold: Option<f32>,
pub vector_name: Option<String>,
pub with_vector: bool,
pub vector_size: Option<u64>,
pub distance: Option<Distance>,
pub on_disk: Option<bool>,
pub function_def: Option<FunctionDef>,
pub trigger_def: Option<TriggerDef>,
pub policy_def: Option<RlsPolicy>,
}Expand description
The core Qail AST node representing a single database operation.
Fields§
§action: ActionSQL action to perform.
table: StringTarget table name.
columns: Vec<Expr>Selected / inserted / modified columns.
joins: Vec<Join>Join clauses.
cages: Vec<Cage>Filter / sort / group / limit cages.
distinct: boolSELECT DISTINCT.
index_def: Option<IndexDef>Index definition for CREATE INDEX.
table_constraints: Vec<TableConstraint>Table-level constraints (composite UNIQUE / PK).
set_ops: Vec<(SetOp, Box<Qail>)>UNION / INTERSECT / EXCEPT operations.
having: Vec<Condition>HAVING clause conditions.
group_by_mode: GroupByModeGROUP BY mode (simple, rollup, cube, grouping sets).
ctes: Vec<CTEDef>Common table expressions (WITH).
distinct_on: Vec<Expr>DISTINCT ON columns.
returning: Option<Vec<Expr>>RETURNING clause.
on_conflict: Option<OnConflict>ON CONFLICT clause for upsert.
merge: Option<Merge>PostgreSQL MERGE specification.
source_query: Option<Box<Qail>>INSERT … SELECT source query.
channel: Option<String>LISTEN/NOTIFY channel.
payload: Option<String>NOTIFY payload.
savepoint_name: Option<String>SAVEPOINT name.
from_tables: Vec<String>UPDATE … FROM additional tables.
using_tables: Vec<String>DELETE … USING additional tables.
lock_mode: Option<LockMode>Row locking (FOR UPDATE / FOR SHARE).
skip_locked: boolSKIP LOCKED modifier for row locking (FOR UPDATE SKIP LOCKED).
fetch: Option<(u64, bool)>FETCH FIRST n ROWS [ONLY|WITH TIES].
default_values: boolINSERT with DEFAULT VALUES.
overriding: Option<OverridingKind>OVERRIDING clause for generated columns.
sample: Option<(SampleMethod, f64, Option<u64>)>TABLESAMPLE method, percentage, and optional seed.
only_table: boolSELECT FROM ONLY (exclude inheritance).
vector: Option<Vec<f32>>Search vector for similarity queries.
score_threshold: Option<f32>Minimum score threshold.
vector_name: Option<String>Named vector in multi-vector collections.
with_vector: boolInclude vector data in results.
vector_size: Option<u64>Vector dimensionality.
distance: Option<Distance>Distance metric.
on_disk: Option<bool>Store vectors on disk.
function_def: Option<FunctionDef>Function definition.
trigger_def: Option<TriggerDef>Trigger definition.
policy_def: Option<RlsPolicy>RLS policy definition.
Implementations§
Source§impl Qail
impl Qail
Sourcepub fn typed_eq<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_eq<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe equality condition.
Enforces at compile time that the value type matches the column type.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_ne<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_ne<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe not-equal condition.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_gt<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_gt<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe greater-than condition.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_lt<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_lt<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe less-than condition.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_gte<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_gte<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe greater-than-or-equal condition.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_lte<T, V>(self, col: TypedColumn<T>, value: V) -> Self
pub fn typed_lte<T, V>(self, col: TypedColumn<T>, value: V) -> Self
Type-safe less-than-or-equal condition.
§Arguments
col— Typed column descriptor.value— Value whose type must match the column’s type marker.
Sourcepub fn typed_column<T>(self, col: TypedColumn<T>) -> Self
pub fn typed_column<T>(self, col: TypedColumn<T>) -> Self
Type-safe column selection.
Sourcepub fn typed_filter<T, V>(
self,
col: TypedColumn<T>,
op: Operator,
value: V,
) -> Self
pub fn typed_filter<T, V>( self, col: TypedColumn<T>, op: Operator, value: V, ) -> Self
Type-safe filter with custom operator.
§Arguments
col— Typed column descriptor.op— Comparison operator.value— Value whose type must match the column’s type marker.
Source§impl Qail
impl Qail
Sourcepub fn column_expr(self, expr: Expr) -> Self
pub fn column_expr(self, expr: Expr) -> Self
Add a column expression.
Sourcepub fn columns_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
pub fn columns_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
Add multiple column expressions.
Sourcepub fn distinct_on<I, S>(self, cols: I) -> Self
pub fn distinct_on<I, S>(self, cols: I) -> Self
DISTINCT ON named columns.
Sourcepub fn distinct_on_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
pub fn distinct_on_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
DISTINCT ON expressions.
Sourcepub fn filter_cond(self, condition: Condition) -> Self
pub fn filter_cond(self, condition: Condition) -> Self
Add a raw Condition to the WHERE clause.
Sourcepub fn having_cond(self, condition: Condition) -> Self
pub fn having_cond(self, condition: Condition) -> Self
Add a HAVING condition.
Sourcepub fn having_conds(
self,
conditions: impl IntoIterator<Item = Condition>,
) -> Self
pub fn having_conds( self, conditions: impl IntoIterator<Item = Condition>, ) -> Self
Add multiple HAVING conditions.
Sourcepub fn update_from<I, S>(self, tables: I) -> Self
pub fn update_from<I, S>(self, tables: I) -> Self
UPDATE … FROM additional tables.
Sourcepub fn delete_using<I, S>(self, tables: I) -> Self
pub fn delete_using<I, S>(self, tables: I) -> Self
DELETE … USING additional tables.
Sourcepub fn for_update(self) -> Self
pub fn for_update(self) -> Self
FOR UPDATE row lock.
Sourcepub fn for_update_skip_locked(self) -> Self
pub fn for_update_skip_locked(self) -> Self
FOR UPDATE SKIP LOCKED row lock. Used for concurrent job claiming (e.g. outbox dispatch).
Sourcepub fn for_no_key_update(self) -> Self
pub fn for_no_key_update(self) -> Self
FOR NO KEY UPDATE row lock.
FOR SHARE row lock.
FOR KEY SHARE row lock.
Sourcepub fn fetch_first(self, count: u64) -> Self
pub fn fetch_first(self, count: u64) -> Self
FETCH FIRST n ROWS ONLY.
Sourcepub fn fetch_with_ties(self, count: u64) -> Self
pub fn fetch_with_ties(self, count: u64) -> Self
FETCH FIRST n ROWS WITH TIES.
Sourcepub fn default_values(self) -> Self
pub fn default_values(self) -> Self
INSERT with DEFAULT VALUES.
Sourcepub fn overriding_system_value(self) -> Self
pub fn overriding_system_value(self) -> Self
OVERRIDING SYSTEM VALUE.
Sourcepub fn overriding_user_value(self) -> Self
pub fn overriding_user_value(self) -> Self
OVERRIDING USER VALUE.
Sourcepub fn tablesample_bernoulli(self, percent: f64) -> Self
pub fn tablesample_bernoulli(self, percent: f64) -> Self
TABLESAMPLE BERNOULLI(percent).
Sourcepub fn tablesample_system(self, percent: f64) -> Self
pub fn tablesample_system(self, percent: f64) -> Self
TABLESAMPLE SYSTEM(percent).
Sourcepub fn repeatable(self, seed: u64) -> Self
pub fn repeatable(self, seed: u64) -> Self
REPEATABLE(seed) for TABLESAMPLE.
Sourcepub fn left_join_as(
self,
table: impl AsRef<str>,
alias: impl AsRef<str>,
left_col: impl AsRef<str>,
right_col: impl AsRef<str>,
) -> Self
pub fn left_join_as( self, table: impl AsRef<str>, alias: impl AsRef<str>, left_col: impl AsRef<str>, right_col: impl AsRef<str>, ) -> Self
LEFT JOIN with alias.
Sourcepub fn inner_join_as(
self,
table: impl AsRef<str>,
alias: impl AsRef<str>,
left_col: impl AsRef<str>,
right_col: impl AsRef<str>,
) -> Self
pub fn inner_join_as( self, table: impl AsRef<str>, alias: impl AsRef<str>, left_col: impl AsRef<str>, right_col: impl AsRef<str>, ) -> Self
INNER JOIN with alias.
Sourcepub fn join_conds(
self,
kind: JoinKind,
table: impl AsRef<str>,
conditions: Vec<Condition>,
) -> Self
pub fn join_conds( self, kind: JoinKind, table: impl AsRef<str>, conditions: Vec<Condition>, ) -> Self
JOIN with multiple ON conditions.
The table string may include an alias (e.g. "inventory inv").
§Example
use qail_core::ast::builders::{eq, col};
use qail_core::ast::{Condition, Operator, Expr, Value};
// LEFT JOIN odyssey_leg_inventory inv
// ON inv.leg_id = ol.id AND inv.service_date = '2024-01-15'
.left_join_conds("odyssey_leg_inventory inv", vec![
Condition { left: Expr::Named("inv.leg_id".into()), op: Operator::Eq,
value: Value::Column("ol.id".into()), is_array_unnest: false },
Condition { left: Expr::Named("inv.service_date".into()), op: Operator::Eq,
value: Value::String("2024-01-15".into()), is_array_unnest: false },
])Sourcepub fn left_join_conds(
self,
table: impl AsRef<str>,
conditions: Vec<Condition>,
) -> Self
pub fn left_join_conds( self, table: impl AsRef<str>, conditions: Vec<Condition>, ) -> Self
LEFT JOIN with multiple ON conditions.
Sourcepub fn inner_join_conds(
self,
table: impl AsRef<str>,
conditions: Vec<Condition>,
) -> Self
pub fn inner_join_conds( self, table: impl AsRef<str>, conditions: Vec<Condition>, ) -> Self
INNER JOIN with multiple ON conditions.
Sourcepub fn table_alias(self, alias: impl AsRef<str>) -> Self
pub fn table_alias(self, alias: impl AsRef<str>) -> Self
Set an alias for the FROM table.
Sourcepub fn order_by_expr(self, expr: Expr, order: SortOrder) -> Self
pub fn order_by_expr(self, expr: Expr, order: SortOrder) -> Self
ORDER BY an expression.
Sourcepub fn group_by_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
pub fn group_by_expr<I>(self, exprs: I) -> Selfwhere
I: IntoIterator<Item = Expr>,
GROUP BY expressions.
Source§impl Qail
impl Qail
Sourcepub fn merge_into(table: impl Into<String>) -> Self
pub fn merge_into(table: impl Into<String>) -> Self
MERGE — conditionally insert, update, delete, or do nothing.
Sourcepub fn explain_analyze(table: impl Into<String>) -> Self
pub fn explain_analyze(table: impl Into<String>) -> Self
EXPLAIN ANALYZE — show query plan with execution stats.
Sourcepub fn create_materialized_view(name: impl Into<String>, query: Qail) -> Self
pub fn create_materialized_view(name: impl Into<String>, query: Qail) -> Self
CREATE MATERIALIZED VIEW.
Sourcepub fn refresh_materialized_view(name: impl Into<String>) -> Self
pub fn refresh_materialized_view(name: impl Into<String>) -> Self
REFRESH MATERIALIZED VIEW.
Sourcepub fn drop_materialized_view(name: impl Into<String>) -> Self
pub fn drop_materialized_view(name: impl Into<String>) -> Self
DROP MATERIALIZED VIEW.
Sourcepub fn session_show(key: impl Into<String>) -> Self
pub fn session_show(key: impl Into<String>) -> Self
Sourcepub fn session_reset(key: impl Into<String>) -> Self
pub fn session_reset(key: impl Into<String>) -> Self
Sourcepub fn create_database(name: impl Into<String>) -> Self
pub fn create_database(name: impl Into<String>) -> Self
Create a CREATE DATABASE command.
Sourcepub fn drop_database(name: impl Into<String>) -> Self
pub fn drop_database(name: impl Into<String>) -> Self
Create a DROP DATABASE command.
Source§impl Qail
impl Qail
Sourcepub fn to_cte(self, name: impl Into<String>) -> CTEDef
pub fn to_cte(self, name: impl Into<String>) -> CTEDef
Convert this query into a reusable CTE definition.
Sourcepub fn with(self, name: impl Into<String>, query: Qail) -> Self
pub fn with(self, name: impl Into<String>, query: Qail) -> Self
Add an inline CTE from another query.
Sourcepub fn recursive(self, recursive_part: Qail) -> Self
pub fn recursive(self, recursive_part: Qail) -> Self
Mark the last CTE as recursive and attach the recursive query.
Sourcepub fn from_cte(self, cte_name: impl Into<String>) -> Self
pub fn from_cte(self, cte_name: impl Into<String>) -> Self
Set the source table of the last CTE.
Sourcepub fn select_from_cte(self, columns: &[&str]) -> Self
pub fn select_from_cte(self, columns: &[&str]) -> Self
Replace the column list with named columns (for selecting from a CTE).
Source§impl Qail
impl Qail
Sourcepub fn target_alias(self, alias: impl Into<String>) -> Self
pub fn target_alias(self, alias: impl Into<String>) -> Self
Set a target alias for MERGE INTO.
Sourcepub fn using_table(self, table: impl Into<String>) -> Self
pub fn using_table(self, table: impl Into<String>) -> Self
Set a table source for MERGE USING.
Sourcepub fn using_table_as(
self,
table: impl Into<String>,
alias: impl Into<String>,
) -> Self
pub fn using_table_as( self, table: impl Into<String>, alias: impl Into<String>, ) -> Self
Set an aliased table source for MERGE USING.
Sourcepub fn using_query_as(self, query: Qail, alias: impl Into<String>) -> Self
pub fn using_query_as(self, query: Qail, alias: impl Into<String>) -> Self
Set an aliased query source for MERGE USING.
Sourcepub fn merge_on_column(
self,
left: impl Into<String>,
op: Operator,
right: impl Into<String>,
) -> Self
pub fn merge_on_column( self, left: impl Into<String>, op: Operator, right: impl Into<String>, ) -> Self
Add an ON condition comparing the target side to a source column.
Sourcepub fn merge_on_condition(self, condition: Condition) -> Self
pub fn merge_on_condition(self, condition: Condition) -> Self
Add an arbitrary ON condition.
Sourcepub fn when_matched_update<S>(self, assignments: &[(S, Expr)]) -> Self
pub fn when_matched_update<S>(self, assignments: &[(S, Expr)]) -> Self
Add WHEN MATCHED THEN UPDATE SET ....
Sourcepub fn when_matched_update_if<S>(
self,
condition: Vec<Condition>,
assignments: &[(S, Expr)],
) -> Self
pub fn when_matched_update_if<S>( self, condition: Vec<Condition>, assignments: &[(S, Expr)], ) -> Self
Add WHEN MATCHED AND ... THEN UPDATE SET ....
Sourcepub fn when_matched_delete(self) -> Self
pub fn when_matched_delete(self) -> Self
Add WHEN MATCHED THEN DELETE.
Sourcepub fn when_matched_do_nothing(self) -> Self
pub fn when_matched_do_nothing(self) -> Self
Add WHEN MATCHED THEN DO NOTHING.
Sourcepub fn when_not_matched_insert<S>(self, columns: &[S], values: &[Expr]) -> Self
pub fn when_not_matched_insert<S>(self, columns: &[S], values: &[Expr]) -> Self
Add WHEN NOT MATCHED [BY TARGET] THEN INSERT (...) VALUES (...).
Sourcepub fn when_not_matched_insert_if<S>(
self,
condition: Vec<Condition>,
columns: &[S],
values: &[Expr],
) -> Self
pub fn when_not_matched_insert_if<S>( self, condition: Vec<Condition>, columns: &[S], values: &[Expr], ) -> Self
Add WHEN NOT MATCHED [BY TARGET] AND ... THEN INSERT (...) VALUES (...).
Sourcepub fn when_not_matched_do_nothing(self) -> Self
pub fn when_not_matched_do_nothing(self) -> Self
Add WHEN NOT MATCHED [BY TARGET] THEN DO NOTHING.
Sourcepub fn when_not_matched_by_source_delete(self) -> Self
pub fn when_not_matched_by_source_delete(self) -> Self
Add WHEN NOT MATCHED BY SOURCE THEN DELETE.
Sourcepub fn when_not_matched_by_source_update<S>(
self,
assignments: &[(S, Expr)],
) -> Self
pub fn when_not_matched_by_source_update<S>( self, assignments: &[(S, Expr)], ) -> Self
Add WHEN NOT MATCHED BY SOURCE THEN UPDATE SET ....
Sourcepub fn when_not_matched_by_source_do_nothing(self) -> Self
pub fn when_not_matched_by_source_do_nothing(self) -> Self
Add WHEN NOT MATCHED BY SOURCE THEN DO NOTHING.
Source§impl Qail
impl Qail
Sourcepub fn select_all(self) -> Self
pub fn select_all(self) -> Self
SELECT * (all columns).
Sourcepub fn select_expr(self, expr: impl Into<Expr>) -> Self
pub fn select_expr(self, expr: impl Into<Expr>) -> Self
Add a computed expression as a SELECT column.
Use this for subqueries, aggregates, CASE WHEN, COALESCE, etc.
§Example
use qail_core::ast::builders::{subquery, coalesce, col, text};
use qail_core::ast::builders::ExprExt;
Qail::get("orders")
.columns(&["id", "status"])
.select_expr(
subquery(Qail::get("order_items")
.column("sum(amount)")
.eq("order_id", col("orders.id")))
.with_alias("total_amount")
)
.select_expr(
coalesce([col("nickname"), col("first_name"), text("Guest")])
.alias("display_name")
)Sourcepub fn select_exprs<I, E>(self, exprs: I) -> Self
pub fn select_exprs<I, E>(self, exprs: I) -> Self
Sourcepub fn filter(
self,
column: impl AsRef<str>,
op: Operator,
value: impl Into<Value>,
) -> Self
pub fn filter( self, column: impl AsRef<str>, op: Operator, value: impl Into<Value>, ) -> Self
Add a WHERE filter with an operator and value.
Sourcepub fn or_filter(
self,
column: impl AsRef<str>,
op: Operator,
value: impl Into<Value>,
) -> Self
pub fn or_filter( self, column: impl AsRef<str>, op: Operator, value: impl Into<Value>, ) -> Self
Add an OR filter condition.
Sourcepub fn where_eq(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn where_eq(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column = value.
Sourcepub fn eq(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn eq(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column = value (alias for where_eq).
Sourcepub fn ne(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn ne(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column != value.
Sourcepub fn gt(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn gt(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column > value.
Sourcepub fn gte(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn gte(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column >= value.
Sourcepub fn lt(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn lt(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column < value
Sourcepub fn lte(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn lte(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Filter: column <= value.
Sourcepub fn is_not_null(self, column: impl AsRef<str>) -> Self
pub fn is_not_null(self, column: impl AsRef<str>) -> Self
Filter: column IS NOT NULL.
Sourcepub fn like(self, column: impl AsRef<str>, pattern: impl Into<Value>) -> Self
pub fn like(self, column: impl AsRef<str>, pattern: impl Into<Value>) -> Self
Filter: column LIKE pattern.
Sourcepub fn ilike(self, column: impl AsRef<str>, pattern: impl Into<Value>) -> Self
pub fn ilike(self, column: impl AsRef<str>, pattern: impl Into<Value>) -> Self
Filter: column ILIKE pattern.
Sourcepub fn array_elem_contained_in_text(
self,
array_column: impl AsRef<str>,
text: impl Into<Value>,
) -> Self
pub fn array_elem_contained_in_text( self, array_column: impl AsRef<str>, text: impl Into<Value>, ) -> Self
Filter: does text contain any element from array_column?
Generates an EXISTS (SELECT 1 FROM unnest(array_column) _el WHERE ...)
predicate with case-insensitive matching.
Sourcepub fn in_vals<I, V>(self, column: impl AsRef<str>, values: I) -> Self
pub fn in_vals<I, V>(self, column: impl AsRef<str>, values: I) -> Self
Filter: column IN (values).
§Arguments
column— Column name to filter on.values— Iterable of values for the IN list.
Sourcepub fn order_desc(self, column: impl AsRef<str>) -> Self
pub fn order_desc(self, column: impl AsRef<str>) -> Self
ORDER BY column DESC.
Sourcepub fn distinct_on_all(self) -> Self
pub fn distinct_on_all(self) -> Self
SELECT DISTINCT (all columns).
Sourcepub fn join(
self,
kind: JoinKind,
table: impl AsRef<str>,
left_col: impl AsRef<str>,
right_col: impl AsRef<str>,
) -> Self
pub fn join( self, kind: JoinKind, table: impl AsRef<str>, left_col: impl AsRef<str>, right_col: impl AsRef<str>, ) -> Self
Add a JOIN clause.
Sourcepub fn left_join(
self,
table: impl AsRef<str>,
left_col: impl AsRef<str>,
right_col: impl AsRef<str>,
) -> Self
pub fn left_join( self, table: impl AsRef<str>, left_col: impl AsRef<str>, right_col: impl AsRef<str>, ) -> Self
LEFT JOIN.
Sourcepub fn inner_join(
self,
table: impl AsRef<str>,
left_col: impl AsRef<str>,
right_col: impl AsRef<str>,
) -> Self
pub fn inner_join( self, table: impl AsRef<str>, left_col: impl AsRef<str>, right_col: impl AsRef<str>, ) -> Self
INNER JOIN.
Sourcepub fn join_on(self, related_table: impl AsRef<str>) -> QailBuildResult<Self>
pub fn join_on(self, related_table: impl AsRef<str>) -> QailBuildResult<Self>
Join a related table using schema-defined foreign key relationship.
This is the “First-Class Relations” API - it automatically infers
the join condition from the schema’s ref: definitions.
§Example
// Schema: posts.user_id UUID ref:users.id
// Instead of:
Qail::get("users").left_join("posts", "users.id", "posts.user_id")
// Simply:
Qail::get("users").join_on("posts")?Returns an error when no relation is found or relation metadata is
ambiguous. Use Qail::join_on_optional for a no-op fallback.
Sourcepub fn join_on_optional(self, related_table: impl AsRef<str>) -> Self
pub fn join_on_optional(self, related_table: impl AsRef<str>) -> Self
Join a related table if relation exists, otherwise no-op.
This is the panic-free variant of join_on().
On ambiguous relation metadata it logs and returns self unchanged.
Sourcepub fn returning_all(self) -> Self
pub fn returning_all(self) -> Self
RETURNING * (all columns).
Sourcepub fn set_value(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
pub fn set_value(self, column: impl AsRef<str>, value: impl Into<Value>) -> Self
Set a column = value pair for UPDATE or INSERT.
Sourcepub fn set_opt<T>(self, column: impl AsRef<str>, value: Option<T>) -> Self
pub fn set_opt<T>(self, column: impl AsRef<str>, value: Option<T>) -> Self
Set value only if Some, skip entirely if None This is ergonomic for optional fields - the column is not included in the INSERT at all if None
Sourcepub fn set_coalesce_opt<T>(
self,
column: impl AsRef<str>,
value: Option<T>,
) -> Self
pub fn set_coalesce_opt<T>( self, column: impl AsRef<str>, value: Option<T>, ) -> Self
Set column to COALESCE(new_value, existing_column) only if value is Some.
Combines set_coalesce() with optional handling - if None, still adds the COALESCE with NULL as the first argument (so existing value is kept).
Sourcepub fn on_conflict_update<S>(
self,
conflict_cols: &[S],
updates: &[(S, Expr)],
) -> Self
pub fn on_conflict_update<S>( self, conflict_cols: &[S], updates: &[(S, Expr)], ) -> Self
Source§impl Qail
impl Qail
Sourcepub fn with_rls(self, ctx: &RlsContext) -> QailBuildResult<Self>
pub fn with_rls(self, ctx: &RlsContext) -> QailBuildResult<Self>
Apply tenant-scope isolation based on the query action.
- GET/SET/DEL → injects
WHERE tenant_col = $value - ADD/Upsert → auto-sets
tenant_colin payload - Global context → injects
tenant_col IS NULL(or payloadtenant_col = NULL) - Super admins → no-op (bypasses isolation)
- Unregistered tables → no-op (not a tenant table)
- DDL/etc → no-op
§Example
let ctx = RlsContext::tenant("tenant-uuid");
let query = Qail::get("orders").with_rls(&ctx)?;Source§impl Qail
impl Qail
Sourcepub fn vector(self, embedding: Vec<f32>) -> Self
pub fn vector(self, embedding: Vec<f32>) -> Self
Set the query vector for similarity search.
§Example
use qail_core::prelude::*;
let embedding = vec![0.1, 0.2, 0.3, 0.4];
let cmd = Qail::search("products").vector(embedding);
assert!(cmd.vector.is_some());Sourcepub fn score_threshold(self, threshold: f32) -> Self
pub fn score_threshold(self, threshold: f32) -> Self
Set minimum similarity score threshold.
Points with similarity below this threshold will be filtered out.
§Example
use qail_core::prelude::*;
let cmd = Qail::search("products")
.vector(vec![0.1, 0.2])
.score_threshold(0.8);
assert_eq!(cmd.score_threshold, Some(0.8));Sourcepub fn vector_name(self, name: &str) -> Self
pub fn vector_name(self, name: &str) -> Self
Specify which named vector to search (for multi-vector collections).
§Example
use qail_core::prelude::*;
// Collection with separate "title" and "content" vectors
let title_embedding = vec![0.1, 0.2, 0.3];
let cmd = Qail::search("articles")
.vector_name("title")
.vector(title_embedding);Sourcepub fn with_vectors(self) -> Self
pub fn with_vectors(self) -> Self
Include vectors in search results.
§Example
use qail_core::prelude::*;
let embedding = vec![0.1, 0.2, 0.3];
let cmd = Qail::search("products")
.vector(embedding)
.with_vectors();
assert!(cmd.with_vector);Source§impl Qail
impl Qail
Sourcepub fn typed<T: Table + Into<String>>(table: T) -> TypedQail<T>
pub fn typed<T: Table + Into<String>>(table: T) -> TypedQail<T>
Create a typed query builder that carries the table type.
This enables join_related() with compile-time relationship checking.
Qail::typed(users::table)
.join_related(posts::table) // Compiles ✓
.typed_eq(users::age(), 25)
.build()