Trait typed_sql::query::select::join::Join

source ·
pub trait Join<P> {
    type Table: Table;
    type Fields: Default;
    type Join: JoinSelect;

    // Provided method
    fn join<F>(f: F) -> Self::Join
       where F: FnOnce(Self::Fields) -> Self::Join { ... }
}
Expand description
use typed_sql::{Join, Query, Table, ToSql};
use typed_sql::query::Joined;

#[derive(Table)]
struct User {
    id: i64   
}

#[derive(Table)]
struct Post {
    id: i64,
    user_id: i64
}

#[derive(Join)]
struct UserPost {
   user: User,
   post: Post
}

let join = UserPost::join(|join| UserPostJoin {
    post: Joined::new(join.user.id.eq(join.post.user_id)),
});

assert_eq!(
    join.select().to_sql(),
    "SELECT * FROM users INNER JOIN posts ON users.id = posts.user_id;"
);

Required Associated Types§

Provided Methods§

source

fn join<F>(f: F) -> Self::Joinwhere F: FnOnce(Self::Fields) -> Self::Join,

Implementors§