added get endpoint, updated state_management
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use futures::Stream;
|
||||
use sea_orm::{entity::prelude::*, QueryOrder, QuerySelect};
|
||||
use sea_orm::{entity::prelude::*, QueryOrder, QuerySelect, Statement};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "account")]
|
||||
@ -86,4 +86,20 @@ impl Entity {
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets a name by a hex of a SHA256 hash of the name
|
||||
pub async fn get_name_by_hash(
|
||||
user_id: u64,
|
||||
hash: String,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<Option<String>> {
|
||||
db.query_one(Statement::from_sql_and_values(
|
||||
sea_orm::DatabaseBackend::MySql,
|
||||
"SELECT `name` FROM `account` WHERE SHA2(`name`, 256) = ? AND `user_id` = ?;",
|
||||
[hash.into(), user_id.into()],
|
||||
))
|
||||
.await?
|
||||
.map(|result| result.try_get_by_index(0))
|
||||
.transpose()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user