Function tx_update

Source
pub async fn tx_update<T>(
    transaction: Transaction<'_>,
    entity: T,
) -> Result<(Transaction<'_>, bool), Error>
where T: SqlQuery<T> + UpdateParams + Send + Sync + 'static,
Expand description

Updates a record within a transaction.

§Arguments

  • transaction - An active transaction
  • entity - Data object containing the update information (must implement SqlQuery and UpdateParams traits)

§Return Value

  • Result<(Transaction<'_>, bool), Error> - On success, returns the transaction and whether any record was updated

§Example

#[derive(Updateable, UpdateParams)]
#[table("users")]
#[update("name, email")]
#[where_clause("id = $")]
struct UpdateUser {
    id: i64,
    name: String,
    email: String,
}

let user = UpdateUser {
    id: 1,
    name: "John Smith".to_string(),
    email: "john.smith@example.com".to_string(),
};

let transaction = transactional::begin(&client).await?;
let (transaction, updated) = transactional::tx_update(transaction, user).await?;
transaction.commit().await?;