Skip to main content

DatabaseRelationExecutor

Struct DatabaseRelationExecutor 

Source
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>

Source

pub fn new<I, S>(database: &'a AnyDatabase, roles: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

创建执行器;roles 必须与主查询使用的角色集合一致,字段裁剪依赖它。

Source

pub fn new_on<I, S>(datasource: &'a Datasource, roles: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

用具名数据源创建执行器;关系查询会带上该源的事务/池身份。

Source

pub fn target(self, definition: TableDefinition) -> Self

登记关联目标表定义;加载前必须登记,否则拒绝查询。

Source

pub fn with_tenant(self, value: Value) -> Self

绑定主查询的租户值;目标表声明 tenant_key 时用于追加租户过滤。

未调用本方法且目标表声明了 tenant_key 时,查询默认 fail-closed;确需系统级 跨租户访问时必须显式调用 Self::without_tenant_scope。

Source

pub fn without_tenant_scope(self) -> Self

显式关闭目标表的租户守卫,允许跨租户加载关联行。

仅用于系统级/运维路径。默认行为是 fail-closed:目标表声明了 tenant_key 但未绑定租户值时直接返回 BaseError::ConfigError,避免泄露他租户数据。 调用本方法即表示调用方已审阅并接受跨租户读取范围。

Trait Implementations§

Source§

impl RelationBatchExecutor for DatabaseRelationExecutor<'_>

Source§

fn load_batch<'life0, 'life1, 'async_trait>( &'life0 self, batch: &'life1 RelationBatch, ) -> Pin<Box<dyn Future<Output = Result<Vec<Record>, BaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

加载当前关系的全部目标记录。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more