Rust

hook

Module

Hooks: code a builder runs while compiling, to scope every query (Filter, JoinFilter) or map attribute names to columns (Attribute). Tenant and Map are the hooks the library ships.

Contents

use utopia_query::hook::Hook;
Rust
pub struct Hook

A hook a builder accepts: one object may filter, resolve attributes and filter joins at once (as Tenant filters both tables and joins).

Also implements From.
use utopia_query::hook::JoinCondition;
Rust
pub struct JoinCondition

A join filter's condition and where it goes.

use utopia_query::hook::Map;
Rust
pub struct Map

Maps attribute names to columns through a table; other names stay as they are.

Rust
use utopia_query::hook::{Attribute, Map};

let map = Map::new([("$id", "_uid")]);
assert_eq!(map.resolve("$id")?, "_uid");
assert_eq!(map.resolve("name")?, "name");
use utopia_query::hook::Tenant;
Rust
pub struct Tenant

Scopes every query, and every joined table, to tenants: column IN (?, ...) (in a left or right join's ON, elsewhere in the WHERE).

Rust
use utopia_query::builder::MySql;
use utopia_query::hook::Tenant;

let statement = MySql::new().from("docs", "").add_hook(Tenant::new(["7"], "tenant_id")?)?.build()?;
assert_eq!(statement.query, "SELECT * FROM `docs` WHERE tenant_id IN (?)");
use utopia_query::hook::Placement;
Rust
pub enum Placement

Where a join filter's condition goes.

use utopia_query::hook::Attribute;
Rust
pub trait Attribute: Send + Sync

Maps an attribute name to the column it is stored in.

Implemented byMap
use utopia_query::hook::Filter;
Rust
pub trait Filter: Send + Sync

Adds a condition to the WHERE of every query on a table (tenancy, permissions).

Implemented byTenant
use utopia_query::hook::JoinFilter;
Rust
pub trait JoinFilter: Send + Sync

Scopes a joined table: a condition for the join, placed in its ON or in the WHERE, or nothing.

Implemented byTenant
use utopia_query::hook::Write;
Rust
pub trait Write: Send + Sync

Decorates rows before they are written and observes writes, for the database layer.