Derive Macro Select

Source
#[derive(Select)]
Expand description

Derive Select to create a new *Select struct.

This *Select struct will implement the IntoSelect trait and can be used with Query::into_vec or Transaction::query_one.

Usage can also be nested.

Example:

#[rust_query::migration::schema(Schema)]
pub mod vN {
    pub struct Thing {
        pub details: Details,
        pub beta: f64,
        pub seconds: i64,
    }
    pub struct Details {
        pub name: String,
    }
}
use v0::*;
use rust_query::{Table, Select, Transaction};

#[derive(Select)]
struct MyData {
    seconds: i64,
    is_it_real: bool,
    name: String,
    other: OtherData
}

#[derive(Select)]
struct OtherData {
    alpha: f64,
    beta: f64,
}

fn do_query(db: &Transaction<Schema>) -> Vec<MyData> {
    db.query(|rows| {
        let thing = rows.join(Thing);

        rows.into_vec(MyDataSelect {
            seconds: thing.seconds(),
            is_it_real: thing.seconds().lt(100),
            name: thing.details().name(),
            other: OtherDataSelect {
                alpha: thing.beta().add(2.0),
                beta: thing.beta(),
            },
        })
    })
}