Perform last member removal check on the database.
This commit is contained in:
@@ -62,34 +62,6 @@ where
|
||||
.map_err(DatabaseError::from)
|
||||
}
|
||||
|
||||
/// Like [`get_by_id`], but also locks the account row until the end of the transaction, so the
|
||||
/// executor must be a transaction. Callers locking the same account are serialized, while
|
||||
/// inserting members into the account is not blocked.
|
||||
pub async fn get_by_id_locking<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
id: Uuid,
|
||||
) -> Result<Option<AccountRow>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
sqlx::query_as!(
|
||||
AccountRow,
|
||||
r#"
|
||||
SELECT id, name
|
||||
FROM accounts
|
||||
WHERE id IN (SELECT id FROM accessible_accounts($1))
|
||||
AND id = $2
|
||||
FOR NO KEY UPDATE
|
||||
"#,
|
||||
user_id,
|
||||
id,
|
||||
)
|
||||
.fetch_optional(executor)
|
||||
.await
|
||||
.map_err(DatabaseError::from)
|
||||
}
|
||||
|
||||
pub async fn get_by_ids<'e, E>(
|
||||
executor: E,
|
||||
user_id: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user