Skip to main content

Join

Struct Join 

Source
pub struct Join {
    pub join_type: JoinType,
    pub table: String,
    pub alias: Option<String>,
    pub on: Expr,
    pub lateral: bool,
    pub is_subquery: bool,
    pub subquery_params: Vec<Value>,
    pub subquery: Option<Box<SelectQuery>>,
}
Expand description

A JOIN clause.

Fields§

§join_type: JoinType

Type of join

§table: String

Table to join (table name or subquery SQL)

§alias: Option<String>

Optional table alias

§on: Expr

ON condition

§lateral: bool

Whether this is a LATERAL join (subquery can reference outer query columns).

Supported by PostgreSQL and MySQL 8.0+. Not supported by SQLite.

§is_subquery: bool

Whether the table field contains a subquery (wrapped in parentheses).

§subquery_params: Vec<Value>

Parameters from a subquery table expression.

§subquery: Option<Box<SelectQuery>>

Deferred subquery builder (dialect-aware).

Implementations§

Source§

impl Join

Source

pub fn inner(table: impl Into<String>, on: Expr) -> Self

Create an INNER JOIN.

Source

pub fn left(table: impl Into<String>, on: Expr) -> Self

Create a LEFT JOIN.

Source

pub fn right(table: impl Into<String>, on: Expr) -> Self

Create a RIGHT JOIN.

Source

pub fn full(table: impl Into<String>, on: Expr) -> Self

Create a FULL OUTER JOIN.

Source

pub fn cross(table: impl Into<String>) -> Self

Create a CROSS JOIN (no ON condition needed, but we require one for uniformity).

Source

pub fn lateral( join_type: JoinType, subquery_sql: impl Into<String>, alias: impl Into<String>, on: Expr, params: Vec<Value>, ) -> Self

Create a LATERAL JOIN with a subquery.

A LATERAL subquery can reference columns from preceding FROM items. Supported by PostgreSQL (9.3+) and MySQL (8.0.14+). Not supported by SQLite.

§Arguments
  • join_type - The join type (typically JoinType::Inner or JoinType::Left)
  • subquery_sql - The subquery SQL (without parentheses)
  • alias - Required alias for the lateral subquery
  • on - ON condition (use Expr::raw("TRUE") for implicit join)
  • params - Parameters for the subquery
Source

pub fn lateral_query( join_type: JoinType, subquery: SelectQuery, alias: impl Into<String>, on: Expr, ) -> Self

Create a LATERAL JOIN with a deferred subquery builder.

Source

pub fn left_lateral( subquery_sql: impl Into<String>, alias: impl Into<String>, on: Expr, params: Vec<Value>, ) -> Self

Create a LEFT JOIN LATERAL (most common form).

Shorthand for Join::lateral(JoinType::Left, ...).

Source

pub fn inner_lateral( subquery_sql: impl Into<String>, alias: impl Into<String>, on: Expr, params: Vec<Value>, ) -> Self

Create an INNER JOIN LATERAL.

Source

pub fn cross_lateral( subquery_sql: impl Into<String>, alias: impl Into<String>, params: Vec<Value>, ) -> Self

Create a CROSS JOIN LATERAL (no ON condition).

Source

pub fn alias(self, alias: impl Into<String>) -> Self

Set an alias for the joined table.

Source

pub fn set_lateral(self) -> Self

Mark this join as LATERAL.

Source

pub fn to_sql(&self) -> (String, Vec<Value>)

Generate SQL for this JOIN clause and collect parameters.

Returns a tuple of (sql, params) since the ON condition may contain literal values that need to be bound as parameters.

Source

pub fn to_sql_with_dialect(&self, dialect: Dialect) -> (String, Vec<Value>)

Generate SQL for this JOIN clause with a specific dialect.

Source

pub fn build(&self, params: &mut Vec<Value>, offset: usize) -> String

Generate SQL and collect parameters.

Source

pub fn build_with_dialect( &self, dialect: Dialect, params: &mut Vec<Value>, offset: usize, ) -> String

Generate SQL and collect parameters with a specific dialect.

Trait Implementations§

Source§

impl Clone for Join

Source§

fn clone(&self) -> Join

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Join

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Join

§

impl RefUnwindSafe for Join

§

impl Send for Join

§

impl Sync for Join

§

impl Unpin for Join

§

impl UnwindSafe for Join

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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