Skip to main content

FromRow

Derive Macro FromRow 

Source
#[derive(FromRow)]
{
    // Attributes available to this derive:
    #[sentinel]
}
Expand description

Derive FromRow for a struct โ€” automatically decode a Row into the struct.

Each field is decoded by name from the row using try_get_by_name. Field types must implement FromSql. Use Option<T> for nullable columns.

ยงExample

โ“˜
use sentinel_derive::FromRow;

#[derive(FromRow)]
struct User {
    id: i32,
    name: String,
    email: Option<String>,
}

let row = conn.query_one("SELECT id, name, email FROM users WHERE id = $1", &[&1]).await?;
let user = User::from_row(&row)?;