pub struct TenantRepository<E, R> { /* private fields */ }Expand description
租户感知 Repository 装饰器
包装任意 Repository<E>,在查询/保存/删除时自动注入 tenant_id 条件。
§自动注入行为
| 操作 | 注入逻辑 |
|---|---|
find_by | 追加 AND tenant_id = current |
find_one_by | 追加 AND tenant_id = current |
save | 校验/填充 entity.tenant_id = current |
delete | 先按主键查找,校验 tenant_id 后删除 |
delete_by | 追加 AND tenant_id = current |
count_by | 追加 AND tenant_id = current |
Implementations§
Source§impl<E: TenantAware, R> TenantRepository<E, R>
impl<E: TenantAware, R> TenantRepository<E, R>
Trait Implementations§
Source§impl<E, R> Repository<E> for TenantRepository<E, R>
impl<E, R> Repository<E> for TenantRepository<E, R>
Source§type Key = <R as Repository<E>>::Key
type Key = <R as Repository<E>>::Key
主键类型
Source§fn find_by_id(&self, key: &Self::Key) -> RepositoryResult<Option<E>>
fn find_by_id(&self, key: &Self::Key) -> RepositoryResult<Option<E>>
按主键查找
Source§fn find_all(&self) -> RepositoryResult<Vec<E>>
fn find_all(&self) -> RepositoryResult<Vec<E>>
查询所有
Source§fn find_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<Vec<E>>
fn find_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<Vec<E>>
按条件查询
Source§fn find_one_by(
&self,
conditions: &[WhereCondition],
) -> RepositoryResult<Option<E>>
fn find_one_by( &self, conditions: &[WhereCondition], ) -> RepositoryResult<Option<E>>
按条件查询单条
Source§fn save(&self, entity: E) -> RepositoryResult<E>
fn save(&self, entity: E) -> RepositoryResult<E>
保存(INSERT 或 UPDATE) Read more
Source§fn delete_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<usize>
fn delete_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<usize>
按条件删除
Source§fn count(&self) -> RepositoryResult<u64>
fn count(&self) -> RepositoryResult<u64>
总数
Source§fn count_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<u64>
fn count_by(&self, conditions: &[WhereCondition]) -> RepositoryResult<u64>
按条件计数
Source§fn batch_update(
&self,
entities: Vec<E>,
) -> Result<BatchUpdateResult<E>, RepositoryError>
fn batch_update( &self, entities: Vec<E>, ) -> Result<BatchUpdateResult<E>, RepositoryError>
批量更新(S-1:SeaORM 对标短板补全) Read more
Source§fn paginate(
&self,
page: u64,
page_size: u64,
) -> Result<PageResult<E>, RepositoryError>where
E: Clone,
fn paginate(
&self,
page: u64,
page_size: u64,
) -> Result<PageResult<E>, RepositoryError>where
E: Clone,
分页查询
Source§fn paginate_by(
&self,
conditions: &[WhereCondition],
page: u64,
page_size: u64,
) -> Result<PageResult<E>, RepositoryError>where
E: Clone,
fn paginate_by(
&self,
conditions: &[WhereCondition],
page: u64,
page_size: u64,
) -> Result<PageResult<E>, RepositoryError>where
E: Clone,
按条件分页查询
Source§fn find_by_with_or_filter(
&self,
and: &[WhereCondition],
or_filter: &[WhereCondition],
) -> Result<Vec<E>, RepositoryError>where
E: Clone + EntityAttributes,
fn find_by_with_or_filter(
&self,
and: &[WhereCondition],
or_filter: &[WhereCondition],
) -> Result<Vec<E>, RepositoryError>where
E: Clone + EntityAttributes,
按 AND 条件查询,并对结果应用额外的 OR 过滤组 Read more
Auto Trait Implementations§
impl<E, R> Freeze for TenantRepository<E, R>
impl<E, R> RefUnwindSafe for TenantRepository<E, R>where
E: RefUnwindSafe,
R: RefUnwindSafe,
impl<E, R> Send for TenantRepository<E, R>
impl<E, R> Sync for TenantRepository<E, R>
impl<E, R> Unpin for TenantRepository<E, R>where
E: Unpin,
impl<E, R> UnsafeUnpin for TenantRepository<E, R>
impl<E, R> UnwindSafe for TenantRepository<E, R>where
R: RefUnwindSafe,
E: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.