pub struct DatabaseRelationExecutor<'a> { /* private fields */ }Expand description
基于当前 App Database 的跨后端批量关系执行器。
执行器按目标表自身的 TableDefinition 复用受保护查询层,让关联加载与主查询
使用同一套守卫:
- 目标表声明了 tenant_key 且执行器绑定了租户值时,追加该字段的等值条件;
- 目标表声明了 tenant_key 但执行器未绑定租户值时,fail-closed 返回
BaseError::ConfigError;如确需系统级跨租户查询,必须显式调用DatabaseRelationExecutor::without_tenant_scope关闭该守卫; - 目标表声明了软删字段时,自动追加软删字段
IS NULL; - 投影只保留目标关联键与当前角色可读、非隐藏的展示字段,其余展示列被裁剪。
未登记定义的目标表会 fail-closed 返回 BaseError::ConfigError,绝不退化为
绕过守卫的裸查询。
Implementations§
Source§impl<'a> DatabaseRelationExecutor<'a>
impl<'a> DatabaseRelationExecutor<'a>
Sourcepub fn new<I, S>(database: &'a AnyDatabase, roles: I) -> Self
pub fn new<I, S>(database: &'a AnyDatabase, roles: I) -> Self
创建执行器;roles 必须与主查询使用的角色集合一致,字段裁剪依赖它。
Sourcepub fn new_on<I, S>(datasource: &'a Datasource, roles: I) -> Self
pub fn new_on<I, S>(datasource: &'a Datasource, roles: I) -> Self
用具名数据源创建执行器;关系查询会带上该源的事务/池身份。
Sourcepub fn target(self, definition: TableDefinition) -> Self
pub fn target(self, definition: TableDefinition) -> Self
登记关联目标表定义;加载前必须登记,否则拒绝查询。
Sourcepub fn with_tenant(self, value: Value) -> Self
pub fn with_tenant(self, value: Value) -> Self
绑定主查询的租户值;目标表声明 tenant_key 时用于追加租户过滤。
未调用本方法且目标表声明了 tenant_key 时,查询默认 fail-closed;确需系统级
跨租户访问时必须显式调用 Self::without_tenant_scope。
Sourcepub fn without_tenant_scope(self) -> Self
pub fn without_tenant_scope(self) -> Self
显式关闭目标表的租户守卫,允许跨租户加载关联行。
仅用于系统级/运维路径。默认行为是 fail-closed:目标表声明了 tenant_key
但未绑定租户值时直接返回 BaseError::ConfigError,避免泄露他租户数据。
调用本方法即表示调用方已审阅并接受跨租户读取范围。
Trait Implementations§
Source§impl RelationBatchExecutor for DatabaseRelationExecutor<'_>
impl RelationBatchExecutor for DatabaseRelationExecutor<'_>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for DatabaseRelationExecutor<'a>
impl<'a> !UnwindSafe for DatabaseRelationExecutor<'a>
impl<'a> Forget for DatabaseRelationExecutor<'a>
impl<'a> Freeze for DatabaseRelationExecutor<'a>
impl<'a> Move for DatabaseRelationExecutor<'a>
impl<'a> Send for DatabaseRelationExecutor<'a>
impl<'a> Sync for DatabaseRelationExecutor<'a>
impl<'a> Unpin for DatabaseRelationExecutor<'a>
impl<'a> UnsafeUnpin for DatabaseRelationExecutor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more