#[derive(Updatable)]
{
// Attributes available to this derive:
#[table_name]
#[primary_key]
#[skip_update]
#[timestamps]
}
Expand description
Derive macro that generates an update() method for a struct.
All Option<T> fields are treated as partial updates — only Some values
are included in the SET clause. Non-Option fields are always included.
§Attributes
#[table_name("table")]— required#[primary_key]— marks the WHERE clause field (required, exactly one)#[skip_update]— exclude from SET clause
§Example
ⓘ
#[derive(Updatable)]
#[table_name("user")]
pub struct UpdateUser {
#[primary_key]
pub id: i64,
pub username: Option<String>,
pub email: Option<String>,
pub active: Option<bool>,
}
// Generated:
// UpdateUser { id: 42, username: Some("new"), email: None, active: None }.update(pool).await?;
// → UPDATE user SET username=? WHERE id=? (only Some fields)