Fix lifetime for everything except Crud::delete

This commit is contained in:
dull b 2023-07-25 02:35:35 +00:00
parent 3129cd0fc3
commit c1ad7a161b

View file

@ -26,25 +26,19 @@ use std::hash::Hash;
/// Returned by `diesel::delete` /// Returned by `diesel::delete`
pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>; pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>;
/*Self: Send + 'static + Sized + HasTable, pub type Find<'a, T> = dsl::Find<<T as HasTable>::Table, <T as Crud<'a>>::IdType>;
Self::Table:
FindDsl<Self::IdType> + Send + Sized + 'static,
<Self::Table as FindDsl<Self::IdType>>::Output:
LimitDsl + Send + Sized + 'static,
<<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType,
<Self::Table as Table>::PrimaryKey: ExpressionMethods + Send + Sized + 'static,*/
#[async_trait] #[async_trait]
pub trait Crud<'a> pub trait Crud<'a>
where where
Self: HasTable + Sized, Self: HasTable + Sized,
Self::Table: FindDsl<Self::IdType> + 'static, for<'b> Self::Table: FindDsl<<Self as Crud<'b>>::IdType> + 'static,
dsl::Find<Self::Table, Self::IdType>: LimitDsl + Send + IntoUpdateTarget, for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'b,
for<'query> dsl::Limit<dsl::Find<Self::Table, Self::IdType>>: for<'b, 'query> dsl::Limit<Find<'b, Self>>:
Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query, Send + LoadQuery<'query, AsyncPgConnection, Self> + 'query,
<<Self as HasTable>::Table as Table>::PrimaryKey: ExpressionMethods + Send, <Self::Table as Table>::PrimaryKey: ExpressionMethods + Send,
<<<Self as HasTable>::Table as Table>::PrimaryKey as Expression>::SqlType: <<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType,
SqlType + TypedExpressionType, for<'b> Delete<Find<'b, Self>>: ExecuteDsl<AsyncPgConnection> + Send + 'b,
for<'a> Delete<dsl::Find<Self::Table, Self::IdType>>: ExecuteDsl<AsyncPgConnection> + 'a + Send,
{ {
/*for<'a> &'a Self::InsertForm: Insertable<Self::Table>, /*for<'a> &'a Self::InsertForm: Insertable<Self::Table>,
for<'a> InsertStatement<Self::Table, <&'a Self::InsertForm as Insertable<Self::Table>>::Values>: for<'a> InsertStatement<Self::Table, <&'a Self::InsertForm as Insertable<Self::Table>>::Values>:
@ -57,13 +51,18 @@ where
+ Sized + Sized
+ Send + Send
+ AsExpression<<<Self::Table as Table>::PrimaryKey as Expression>::SqlType>; + AsExpression<<<Self::Table as Table>::PrimaryKey as Expression>::SqlType>;
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error>; async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error>
where
'a: 'async_trait;
/*{ /*{
let query = insert_into(Self::table()).values(form); let query = insert_into(Self::table()).values(form);
let conn = &mut *get_conn(pool).await?; let conn = &mut *get_conn(pool).await?;
query.get_result::<Self>(conn).await query.get_result::<Self>(conn).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>
where
'a: 'async_trait,
{
let query = Self::table().find(id); let query = Self::table().find(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
@ -73,7 +72,9 @@ where
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
id: Self::IdType, id: Self::IdType,
form: &'a Self::UpdateForm, form: &'a Self::UpdateForm,
) -> Result<Self, Error>; ) -> Result<Self, Error>
where
'a: 'async_trait;
/*{ /*{
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
diesel::update(Self::table().find(id)) diesel::update(Self::table().find(id))
@ -81,7 +82,10 @@ where
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await .await
}*/ }*/
async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error> { async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<usize, Error>
where
'a: 'async_trait,
{
let query = diesel::delete(Self::table().find(id)); let query = diesel::delete(Self::table().find(id));
let conn = &mut *get_conn(pool).await?; let conn = &mut *get_conn(pool).await?;
query.execute(conn).await query.execute(conn).await