[][src]Struct orma::JoinBuilder

pub struct JoinBuilder<'a, A, B> where
    A: DbData + Serialize + DeserializeOwned,
    B: DbData + Serialize + DeserializeOwned
{ /* fields omitted */ }

This is the builder for a DbJoin If you need to relate two different entities, DbJoin<DbData> is used to get entities related to the specified DbData.
You need to use JoinBuilder to create a DbJoin relation, and you can define both simple joins and table joins for M to N relations.

Simple join example:

async fn office_users(
    user: &DbEntity<Office>,
    db_conn: &Connection,
) -> Result<DbJoin<User>, DbError> {
    JoinBuilder::new(user)
        .with_source_fk("id_office")
        .with_target(User::table_name())
        .with_sorting(&["data->>'name'"])
        .build(db_conn)
        .await
}

M to N join example:

async fn user_groups(
    user: &DbEntity<User>,
    db_conn: &Connection,
) -> Result<DbJoin<Group>, DbError> {
    JoinBuilder::new(user)
        .with_join_table("intrared.r_user_group", "id_user", "id_group")
        .with_target(Group::table_name())
        .with_sorting(&["data->>'name'"])
        .build(db_conn)
        .await
}

Methods

impl<'a, A, B> JoinBuilder<'a, A, B> where
    A: DbData + Serialize + DeserializeOwned,
    B: DbData + Serialize + DeserializeOwned
[src]

pub fn new(source: &'a DbEntity<A>) -> Self[src]

Defines the source DbEntity of the DbJoin

pub fn with_target(self, target_table: &'a str) -> Self[src]

Provides the name of the table where DbJoin items are mapped to

pub fn with_source_fk(self, source_fk: &'a str) -> Self[src]

The name of the source foreign key in the items table when you want to represents a simple join ( 1 to n )

pub fn with_join_table(
    self,
    join_table: &'a str,
    source_fk: &'a str,
    items_fk: &'a str
) -> Self
[src]

If you want to map a m2n join, you provide the name of the db table with name of the source foreign key and the foreign key of the items table

pub fn with_sorting(self, sorting: &'a [&'a str]) -> Self[src]

DbJoin sorting attribute used to provide a sorting method on data fetching.

vec!["data->>'first_name'", "data->>'last_name' DESC"];

pub async fn build<'_>(
    &'_ self,
    conn: &'a Connection
) -> Result<DbJoin<B>, DbError>
[src]

Creates the DbJoin object and fetches the data

Auto Trait Implementations

impl<'a, A, B> RefUnwindSafe for JoinBuilder<'a, A, B> where
    A: RefUnwindSafe,
    B: RefUnwindSafe

impl<'a, A, B> Send for JoinBuilder<'a, A, B> where
    A: Sync,
    B: Send

impl<'a, A, B> Sync for JoinBuilder<'a, A, B> where
    A: Sync,
    B: Sync

impl<'a, A, B> Unpin for JoinBuilder<'a, A, B> where
    B: Unpin

impl<'a, A, B> UnwindSafe for JoinBuilder<'a, A, B> where
    A: RefUnwindSafe,
    B: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,