Skip to main content

FindWithRelated

Struct FindWithRelated 

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

Source

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
Source

pub fn where_cond(self, cond: impl Into<String>) -> FindWithRelated<'a>

追加 WHERE 条件(AND 连接)

Source

pub fn order_by(self, field: impl Into<String>) -> FindWithRelated<'a>

追加 ORDER BY(ASC)

Source

pub fn order_desc(self, field: impl Into<String>) -> FindWithRelated<'a>

追加 ORDER BY(DESC)

Source

pub fn limit(self, n: usize) -> FindWithRelated<'a>

设置 LIMIT

Source

pub fn offset(self, n: usize) -> FindWithRelated<'a>

设置 OFFSET

Source

pub fn build(&self) -> String

构建 SELECT SQL(JOIN 模式)

生成的 SQL 形如:

SELECT `main`.*, `related`.*
FROM `main`
LEFT JOIN `related` ON `related`.`fk` = `main`.`pk`
WHERE <conds>
ORDER BY <field> [DESC]
LIMIT <n> OFFSET <n>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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