added get endpoint, updated state_management

This commit is contained in:
2023-07-26 00:52:12 +03:00
parent 96c7d2e37e
commit 22c754a256
27 changed files with 278 additions and 149 deletions

@ -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()
}
}