pub trait GlobalScope {
// Required methods
fn scope_name() -> &'static str;
fn apply_scope(ctx: &HookContext) -> Option<(String, Vec<Value>)>;
}Expand description
全局查询作用域
应用到所有查询的隐式过滤条件。
典型实现:软删除作用域(deleted_at IS NULL)、多租户作用域(tenant_id = ?)。
注:此 trait 不要求实现 Model,因为作用域本身只是一个标记类型,
真正的 Model 由泛型参数 M 携带。
Required Methods§
Sourcefn scope_name() -> &'static str
fn scope_name() -> &'static str
作用域名称(用于调试)
Sourcefn apply_scope(ctx: &HookContext) -> Option<(String, Vec<Value>)>
fn apply_scope(ctx: &HookContext) -> Option<(String, Vec<Value>)>
返回需要追加的 WHERE 条件 SQL 片段
返回 None 表示无附加条件。
返回 Some((sql, params)) 表示追加 AND {sql},绑定 params。
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".