hook
ModuleHooks: 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;pub struct HookA hook a builder accepts: one object may filter, resolve attributes and
filter joins at once (as Tenant filters both tables and joins).
From.use utopia_query::hook::JoinCondition;pub struct JoinConditionA join filter's condition and where it goes.
use utopia_query::hook::Map;pub struct MapMaps attribute names to columns through a table; other names stay as they are.
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;pub struct TenantScopes every query, and every joined table, to tenants: column IN (?, ...)
(in a left or right join's ON, elsewhere in the WHERE).
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;pub enum PlacementWhere a join filter's condition goes.
use utopia_query::hook::Attribute;pub trait Attribute: Send + SyncMaps an attribute name to the column it is stored in.
use utopia_query::hook::Filter;pub trait Filter: Send + SyncAdds a condition to the WHERE of every query on a table (tenancy,
permissions).
use utopia_query::hook::JoinFilter;pub trait JoinFilter: Send + SyncScopes a joined table: a condition for the join, placed in its ON or in
the WHERE, or nothing.
use utopia_query::hook::Write;pub trait Write: Send + SyncDecorates rows before they are written and observes writes, for the database layer.