From 183c61b3d2985a4ec5a78f363dd0e9379e66ace0 Mon Sep 17 00:00:00 2001 From: dull b Date: Mon, 24 Jul 2023 03:45:33 +0000 Subject: [PATCH] Replace filter with find --- crates/db_schema/src/traits.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 3be5a3913..61a067671 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -7,7 +7,7 @@ use diesel::{ dsl, expression::{AsExpression, TypedExpressionType}, expression_methods::ExpressionMethods, - query_dsl::methods::{FilterDsl, LimitDsl}, + query_dsl::methods::{FindDsl, LimitDsl}, result::Error, sql_types::SqlType, AsChangeset, @@ -20,8 +20,8 @@ use std::hash::Hash; /*Self: Send + 'static + Sized + HasTable, Self::Table: -FilterDsl::PrimaryKey, Self::IdType>> + Send + Sized + 'static, -::PrimaryKey, Self::IdType>>>::Output: +FindDsl + Send + Sized + 'static, +>::Output: LimitDsl + Send + Sized + 'static, <::PrimaryKey as Expression>::SqlType: SqlType, ::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/ @@ -29,10 +29,9 @@ LimitDsl + Send + Sized + 'static, pub trait Crud where Self: HasTable + Sized, - Self::Table: FilterDsl::PrimaryKey, Self::IdType>>, - dsl::Filter::PrimaryKey, Self::IdType>>: - LimitDsl + Send, - for<'query> dsl::Limit::PrimaryKey, Self::IdType>>>: + Self::Table: FindDsl, + dsl::Find: LimitDsl + Send, + for<'query> dsl::Limit>: Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query, <::Table as Table>::PrimaryKey: ExpressionMethods + Send, <<::Table as Table>::PrimaryKey as Expression>::SqlType: @@ -54,8 +53,7 @@ where .await }*/ async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result { - // FindDsl is not used because it uses a private trait - let query = Self::table().filter(Self::table().primary_key().eq(id)); + let query = Self::table().find(id); let conn = &mut *get_conn(pool).await?; query.first::(conn).await }