mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 03:41:02 +00:00
Replace filter with find
This commit is contained in:
parent
e1797a8eb4
commit
183c61b3d2
1 changed files with 7 additions and 9 deletions
|
@ -7,7 +7,7 @@ use diesel::{
|
||||||
dsl,
|
dsl,
|
||||||
expression::{AsExpression, TypedExpressionType},
|
expression::{AsExpression, TypedExpressionType},
|
||||||
expression_methods::ExpressionMethods,
|
expression_methods::ExpressionMethods,
|
||||||
query_dsl::methods::{FilterDsl, LimitDsl},
|
query_dsl::methods::{FindDsl, LimitDsl},
|
||||||
result::Error,
|
result::Error,
|
||||||
sql_types::SqlType,
|
sql_types::SqlType,
|
||||||
AsChangeset,
|
AsChangeset,
|
||||||
|
@ -20,8 +20,8 @@ use std::hash::Hash;
|
||||||
|
|
||||||
/*Self: Send + 'static + Sized + HasTable,
|
/*Self: Send + 'static + Sized + HasTable,
|
||||||
Self::Table:
|
Self::Table:
|
||||||
FilterDsl<dsl::Eq<<Self::Table as Table>::PrimaryKey, Self::IdType>> + Send + Sized + 'static,
|
FindDsl<Self::IdType> + Send + Sized + 'static,
|
||||||
<Self::Table as FilterDsl<dsl::Eq<<Self::Table as Table>::PrimaryKey, Self::IdType>>>::Output:
|
<Self::Table as FindDsl<Self::IdType>>::Output:
|
||||||
LimitDsl + Send + Sized + 'static,
|
LimitDsl + Send + Sized + 'static,
|
||||||
<<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType,
|
<<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType,
|
||||||
<Self::Table as Table>::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/
|
<Self::Table as Table>::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/
|
||||||
|
@ -29,10 +29,9 @@ LimitDsl + Send + Sized + 'static,
|
||||||
pub trait Crud
|
pub trait Crud
|
||||||
where
|
where
|
||||||
Self: HasTable + Sized,
|
Self: HasTable + Sized,
|
||||||
Self::Table: FilterDsl<dsl::Eq<<Self::Table as Table>::PrimaryKey, Self::IdType>>,
|
Self::Table: FindDsl<Self::IdType>,
|
||||||
dsl::Filter<Self::Table, dsl::Eq<<Self::Table as Table>::PrimaryKey, Self::IdType>>:
|
dsl::Find<Self::Table, Self::IdType>: LimitDsl + Send,
|
||||||
LimitDsl + Send,
|
for<'query> dsl::Limit<dsl::Find<Self::Table, Self::IdType>>:
|
||||||
for<'query> dsl::Limit<dsl::Filter<Self::Table, dsl::Eq<<Self::Table as Table>::PrimaryKey, Self::IdType>>>:
|
|
||||||
Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query,
|
Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query,
|
||||||
<<Self as HasTable>::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
<<Self as HasTable>::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
||||||
<<<Self as HasTable>::Table as Table>::PrimaryKey as Expression>::SqlType:
|
<<<Self as HasTable>::Table as Table>::PrimaryKey as Expression>::SqlType:
|
||||||
|
@ -54,8 +53,7 @@ where
|
||||||
.await
|
.await
|
||||||
}*/
|
}*/
|
||||||
async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error> {
|
async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error> {
|
||||||
// FindDsl is not used because it uses a private trait
|
let query = Self::table().find(id);
|
||||||
let query = Self::table().filter(Self::table().primary_key().eq(id));
|
|
||||||
let conn = &mut *get_conn(pool).await?;
|
let conn = &mut *get_conn(pool).await?;
|
||||||
query.first::<Self>(conn).await
|
query.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue