From d04305433f79143b4f2dfbffb0831b2ff28550fd Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Fri, 10 Feb 2023 12:43:49 +0100 Subject: [PATCH] server: use the new into_tuple from sea_orm --- server/src/domain/sql_opaque_handler.rs | 10 +++------- server/src/infra/sql_backend_handler.rs | 16 +++++----------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/server/src/domain/sql_opaque_handler.rs b/server/src/domain/sql_opaque_handler.rs index b2ded01..5a5667b 100644 --- a/server/src/domain/sql_opaque_handler.rs +++ b/server/src/domain/sql_opaque_handler.rs @@ -8,7 +8,7 @@ use super::{ }; use async_trait::async_trait; use lldap_auth::opaque; -use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, FromQueryResult, QuerySelect}; +use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, QuerySelect}; use secstr::SecUtf8; use tracing::{debug, instrument}; @@ -50,18 +50,14 @@ impl SqlBackendHandler { #[instrument(skip_all, level = "debug", err)] async fn get_password_file_for_user(&self, user_id: UserId) -> Result>> { - #[derive(FromQueryResult)] - struct OnlyPasswordHash { - password_hash: Option>, - } // Fetch the previously registered password file from the DB. Ok(model::User::find_by_id(user_id) .select_only() .column(UserColumn::PasswordHash) - .into_model::() + .into_tuple::<(Option>,)>() .one(&self.sql_pool) .await? - .and_then(|u| u.password_hash)) + .and_then(|u| u.0)) } } diff --git a/server/src/infra/sql_backend_handler.rs b/server/src/infra/sql_backend_handler.rs index 16e3f1a..54ca857 100644 --- a/server/src/infra/sql_backend_handler.rs +++ b/server/src/infra/sql_backend_handler.rs @@ -8,8 +8,7 @@ use crate::domain::{ use async_trait::async_trait; use sea_orm::{ sea_query::{Cond, Expr}, - ActiveModelTrait, ColumnTrait, EntityTrait, FromQueryResult, IntoActiveModel, QueryFilter, - QuerySelect, + ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect, }; use std::collections::HashSet; use tracing::{debug, instrument}; @@ -24,11 +23,6 @@ fn gen_random_string(len: usize) -> String { .collect() } -#[derive(FromQueryResult)] -struct OnlyJwtHash { - jwt_hash: i64, -} - #[async_trait] impl TcpBackendHandler for SqlBackendHandler { #[instrument(skip_all, level = "debug")] @@ -37,11 +31,11 @@ impl TcpBackendHandler for SqlBackendHandler { .select_only() .column(JwtStorageColumn::JwtHash) .filter(JwtStorageColumn::Blacklisted.eq(true)) - .into_model::() + .into_tuple::<(i64,)>() .all(&self.sql_pool) .await? .into_iter() - .map(|m| m.jwt_hash as u64) + .map(|m| m.0 as u64) .collect::>()) } @@ -91,11 +85,11 @@ impl TcpBackendHandler for SqlBackendHandler { .add(JwtStorageColumn::UserId.eq(user)) .add(JwtStorageColumn::Blacklisted.eq(false)), ) - .into_model::() + .into_tuple::<(i64,)>() .all(&self.sql_pool) .await? .into_iter() - .map(|t| t.jwt_hash as u64) + .map(|t| t.0 as u64) .collect::>(); model::JwtStorage::update_many() .col_expr(JwtStorageColumn::Blacklisted, Expr::value(true))