Updated entities to use count method to check the existance of account/master password

This commit is contained in:
StNicolay 2023-06-13 10:39:13 +03:00
parent 4075e04ccc
commit 3389f0a63d
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 6 additions and 14 deletions

View File

@ -59,13 +59,10 @@ impl Entity {
account_name: impl Into<String>,
db: &DatabaseConnection,
) -> crate::Result<bool> {
let result = Self::find_by_id((user_id, account_name.into()))
.select_only()
.column(Column::UserId)
.into_tuple::<u64>()
.one(db)
let count = Self::find_by_id((user_id, account_name.into()))
.count(db)
.await?;
Ok(result.is_some())
Ok(count != 0)
}
/// Gets the account from the DB

View File

@ -1,6 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::{entity::prelude::*, QuerySelect};
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "master_pass")]
@ -28,13 +28,8 @@ impl Entity {
/// Checks if the master password for the user exists
#[inline]
pub async fn exists(user_id: u64, db: &DatabaseConnection) -> Result<bool, DbErr> {
let id = Self::find_by_id(user_id)
.select_only()
.column(Column::UserId)
.into_tuple::<u64>()
.one(db)
.await?;
Ok(id.is_some())
let count = Self::find_by_id(user_id).count(db).await?;
Ok(count != 0)
}
/// Removes a master password of the user from the database