Function update_role

Source
pub async fn update_role(
    pool: &Pool<MySql>,
    id: i64,
    name: Option<&str>,
    description: Option<&str>,
) -> Result<Role>
Expand description

Updates an existing role’s information.

This function modifies a role record with the provided name and/or description. It supports partial updates, allowing you to update only the fields that need changing.

§Arguments

  • pool - Database connection pool for executing the query
  • id - Unique identifier of the role to update
  • name - Optional new name for the role
  • description - Optional new description for the role

§Returns

  • Ok(Role) - Successfully updated role record
  • Err(anyhow::Error) - Failed to update role

§Dynamic Query Building

This function dynamically builds an SQL query based on which parameters are provided. Only the fields specified with Some values will be updated, while None values are ignored.

§Transaction Handling

This function uses a database transaction to ensure atomicity of the operation. If any part of the operation fails, the entire operation is rolled back.