From 62624b81d88ae2661125f912a598d3feccddbb5b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 1 Dec 2022 16:10:37 +0100 Subject: [PATCH] Avoid using `col_expr` whenever possible ...and use the more type-safe `::set`. --- crates/collab/src/db.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index bb1bff7ff8..dce217d955 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -246,7 +246,10 @@ impl Database { self.transact(|tx| async move { user::Entity::update_many() .filter(user::Column::Id.eq(id)) - .col_expr(user::Column::Admin, is_admin.into()) + .set(user::ActiveModel { + admin: ActiveValue::set(is_admin), + ..Default::default() + }) .exec(&tx) .await?; tx.commit().await?; @@ -259,7 +262,10 @@ impl Database { self.transact(|tx| async move { user::Entity::update_many() .filter(user::Column::Id.eq(id)) - .col_expr(user::Column::ConnectedOnce, connected_once.into()) + .set(user::ActiveModel { + connected_once: ActiveValue::set(connected_once), + ..Default::default() + }) .exec(&tx) .await?; tx.commit().await?; @@ -674,7 +680,10 @@ impl Database { self.transact(|tx| async { signup::Entity::update_many() .filter(signup::Column::EmailAddress.is_in(emails.iter().copied())) - .col_expr(signup::Column::EmailConfirmationSent, true.into()) + .set(signup::ActiveModel { + email_confirmation_sent: ActiveValue::set(true), + ..Default::default() + }) .exec(&tx) .await?; tx.commit().await?; @@ -876,14 +885,20 @@ impl Database { .eq(id) .and(user::Column::InviteCode.is_null()), ) - .col_expr(user::Column::InviteCode, random_invite_code().into()) + .set(user::ActiveModel { + invite_code: ActiveValue::set(Some(random_invite_code())), + ..Default::default() + }) .exec(&tx) .await?; } user::Entity::update_many() .filter(user::Column::Id.eq(id)) - .col_expr(user::Column::InviteCount, count.into()) + .set(user::ActiveModel { + invite_count: ActiveValue::set(count as i32), + ..Default::default() + }) .exec(&tx) .await?; tx.commit().await?; @@ -1107,10 +1122,10 @@ impl Database { .and(room_participant::Column::UserId.eq(user_id)) .and(room_participant::Column::AnsweringConnectionId.is_null()), ) - .col_expr( - room_participant::Column::AnsweringConnectionId, - connection_id.0.into(), - ) + .set(room_participant::ActiveModel { + answering_connection_id: ActiveValue::set(Some(connection_id.0 as i32)), + ..Default::default() + }) .exec(&tx) .await?; if result.rows_affected == 0 {