0

I am using Actix with PostgreSQL through Sea-orm. Currently, my update function returns the entire row of data. However, I want it to return only the updated columns, in this case, "full_name" and "updated_at". Here is the function in question.

//update full_name
pub async fn update_user_full_name(db: &DatabaseConnection, user_id: i32, new_full_name: String) -> Result<users::ActiveModel, DbErr> {
    let existing_user = Users::find_by_id(user_id).one(db).await?;
    match existing_user {
        Some(user) => {
            let utc_now = Utc::now();
            let updated_at = utc_now.naive_utc();
            let mut updated_user = user.into_active_model();
            updated_user.full_name = ActiveValue::set(Option::from(new_full_name));
            updated_user.updated_at = ActiveValue::set(updated_at);
            updated_user.clone().save(db).await?;
            Ok(updated_user)
        }
        None => Err(DbErr::Custom(“User ID does not exist”.into()))
    }
}
  "users"
SET
  "full_name" = $1,
  "updated_at" = $2
WHERE
  "users"."id" = $3 RETURNING "id",
  "user_id",
  "full_name",
  "email",
  "telegram_id",
  "created_at",
  "updated_at"```

0 Answers0