pub struct EagerLoader { /* private fields */ }Expand description
Eager Loading 执行器
自动执行主表 + 关联表查询并组装结果,消除 N+1 查询。
Implementations§
Source§impl EagerLoader
impl EagerLoader
Sourcepub fn new(relation: RelationDef) -> Self
pub fn new(relation: RelationDef) -> Self
创建 EagerLoader
Sourcepub fn with(self, relation: RelationDef) -> Self
pub fn with(self, relation: RelationDef) -> Self
添加子级关联(多级嵌套,限 2 级)
ⓘ
EagerLoader::new(order_relation)
.with(order_item_relation) // User → Order → OrderItemSourcepub fn children_count(&self) -> usize
pub fn children_count(&self) -> usize
返回子级关联数量
Sourcepub fn child_names(&self) -> Vec<&str>
pub fn child_names(&self) -> Vec<&str>
返回子级关联名称列表
Sourcepub async fn load_many(
&self,
conn: &mut dyn Connection,
main_sql: &str,
) -> Result<Vec<EagerResult>, DbError>
pub async fn load_many( &self, conn: &mut dyn Connection, main_sql: &str, ) -> Result<Vec<EagerResult>, DbError>
执行 HasMany 双查询策略
- 执行主表 SQL → 提取主键列表
- 生成
WHERE fk IN (?, ...)批量查询 - 执行关联表查询 → 按外键分组组装
- 若有 children,递归加载子级关联(限 2 级)
Auto Trait Implementations§
impl Freeze for EagerLoader
impl RefUnwindSafe for EagerLoader
impl Send for EagerLoader
impl Sync for EagerLoader
impl Unpin for EagerLoader
impl UnsafeUnpin for EagerLoader
impl UnwindSafe for EagerLoader
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