mool 0.2.0

A source-first Rust database toolkit for typed SQL queries, migrations, and model metadata
Documentation
use mool as db;
use mool::Model;

#[derive(Debug, Clone, db::Model)]
#[table(name = "users")]
pub struct User {
    pub id: i64,
    pub email: String,
}

#[derive(Debug, Clone, db::Model)]
#[table(name = "posts")]
pub struct Post {
    pub id: i64,
    #[column(reference = "users.id")]
    pub author_id: i64,
    pub title: String,
}

#[derive(Debug, Clone, db::Record)]
pub struct PostWithAuthor {
    #[column(flatten)]
    pub post: Post,
    #[column(reference(on(from = "author_id", to = "id")))]
    pub author: User,
}

fn main() -> Result<(), db::QueryError> {
    let posts = Post::table();
    let plan = db::from(&posts)
        .all::<PostWithAuthor>()
        .plan(db::queries::Dialect::Postgres)?;

    assert!(plan.sql.contains("JOIN users author"));
    Ok(())
}