Updated entities to use count method to check the existance of account/master password
This commit is contained in:
parent
4075e04ccc
commit
3389f0a63d
@ -59,13 +59,10 @@ impl Entity {
|
|||||||
account_name: impl Into<String>,
|
account_name: impl Into<String>,
|
||||||
db: &DatabaseConnection,
|
db: &DatabaseConnection,
|
||||||
) -> crate::Result<bool> {
|
) -> crate::Result<bool> {
|
||||||
let result = Self::find_by_id((user_id, account_name.into()))
|
let count = Self::find_by_id((user_id, account_name.into()))
|
||||||
.select_only()
|
.count(db)
|
||||||
.column(Column::UserId)
|
|
||||||
.into_tuple::<u64>()
|
|
||||||
.one(db)
|
|
||||||
.await?;
|
.await?;
|
||||||
Ok(result.is_some())
|
Ok(count != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the account from the DB
|
/// Gets the account from the DB
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
//! `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)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
#[sea_orm(table_name = "master_pass")]
|
#[sea_orm(table_name = "master_pass")]
|
||||||
@ -28,13 +28,8 @@ impl Entity {
|
|||||||
/// Checks if the master password for the user exists
|
/// Checks if the master password for the user exists
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn exists(user_id: u64, db: &DatabaseConnection) -> Result<bool, DbErr> {
|
pub async fn exists(user_id: u64, db: &DatabaseConnection) -> Result<bool, DbErr> {
|
||||||
let id = Self::find_by_id(user_id)
|
let count = Self::find_by_id(user_id).count(db).await?;
|
||||||
.select_only()
|
Ok(count != 0)
|
||||||
.column(Column::UserId)
|
|
||||||
.into_tuple::<u64>()
|
|
||||||
.one(db)
|
|
||||||
.await?;
|
|
||||||
Ok(id.is_some())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes a master password of the user from the database
|
/// Removes a master password of the user from the database
|
||||||
|
Loading…
x
Reference in New Issue
Block a user