pub struct FindWithRelated<'a> { /* private fields */ }Expand description
find_with_related 关联查询构造器(JOIN 模式)
适合 1:1 / N:1 关联(BelongsTo / HasOne)。
对于 1:N 关联,JOIN 会导致主表行膨胀,应使用 find_with_related_eager_sql。
Implementations§
Source§impl<'a> FindWithRelated<'a>
impl<'a> FindWithRelated<'a>
Sourcepub fn new(
dialect: &'a dyn Dialect,
main_table: impl Into<String>,
related_table: impl Into<String>,
foreign_key: impl Into<String>,
primary_key: impl Into<String>,
left_join: bool,
) -> Result<FindWithRelated<'a>, DbError>
pub fn new( dialect: &'a dyn Dialect, main_table: impl Into<String>, related_table: impl Into<String>, foreign_key: impl Into<String>, primary_key: impl Into<String>, left_join: bool, ) -> Result<FindWithRelated<'a>, DbError>
创建关联查询构造器
dialect:方言引用main_table:主表名related_table:关联表名foreign_key:外键列名(在 related_table 中,指向 main_table.primary_key)primary_key:主表主键列名left_join:true = LEFT JOIN,false = INNER JOIN
Sourcepub fn where_cond(self, cond: impl Into<String>) -> FindWithRelated<'a>
pub fn where_cond(self, cond: impl Into<String>) -> FindWithRelated<'a>
追加 WHERE 条件(AND 连接)
Sourcepub fn order_by(self, field: impl Into<String>) -> FindWithRelated<'a>
pub fn order_by(self, field: impl Into<String>) -> FindWithRelated<'a>
追加 ORDER BY(ASC)
Sourcepub fn order_desc(self, field: impl Into<String>) -> FindWithRelated<'a>
pub fn order_desc(self, field: impl Into<String>) -> FindWithRelated<'a>
追加 ORDER BY(DESC)
Sourcepub fn limit(self, n: usize) -> FindWithRelated<'a>
pub fn limit(self, n: usize) -> FindWithRelated<'a>
设置 LIMIT
Sourcepub fn offset(self, n: usize) -> FindWithRelated<'a>
pub fn offset(self, n: usize) -> FindWithRelated<'a>
设置 OFFSET
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for FindWithRelated<'a>
impl<'a> !UnwindSafe for FindWithRelated<'a>
impl<'a> Freeze for FindWithRelated<'a>
impl<'a> Send for FindWithRelated<'a>
impl<'a> Sync for FindWithRelated<'a>
impl<'a> Unpin for FindWithRelated<'a>
impl<'a> UnsafeUnpin for FindWithRelated<'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