Derive Macro scyllax_macros::ReadQuery

source ·
#[derive(ReadQuery)]
{
    // Attributes available to this derive:
    #[read_query]
}
Expand description

Apply this attribute to a struct to generate a select query.

§Single result

#[read_query(
    query = "select * from person where id = ? limit 1",
    entity_type = "PersonEntity"
)]
pub struct GetPersonById {
    pub id: Uuid,
}
executor.execute_select(GetPersonById { id }).await?;
// -> Option<PersonEntity>

§Multiple results

#[read_query(
    query = "select * from person where id in ? limit ?",
    return_type = "Vec<PersonEntity>"
)]
pub struct GetPeopleByIds {
    pub ids: Vec<Uuid>,
    pub limit: i32,
}
executor.execute_select(GetPeopleByIds { ids, limit }).await?;
// -> Vec<PersonEntity>