Try to fix Crud::create

pull/3707/head
dull b 2023-07-26 03:27:03 +00:00
parent 1ec33ce502
commit eec238496c
1 changed files with 14 additions and 9 deletions

View File

@ -41,7 +41,7 @@ pub type InsertValues<'a, 'b, T> =
#[async_trait] #[async_trait]
pub trait Crud<'a> pub trait Crud<'a>
where where
Self: HasTable + Sized, Self: HasTable + Sized + Send,
for<'b> Self::Table: FindDsl<<Self as Crud<'b>>::IdType> + 'static, for<'b> Self::Table: FindDsl<<Self as Crud<'b>>::IdType> + 'static,
for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'static, for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'static,
for<'b> dsl::Limit<Find<'b, Self>>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static, for<'b> dsl::Limit<Find<'b, Self>>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static,
@ -52,8 +52,8 @@ where
for<'b> <Find<'b, Self> as HasTable>::Table: 'static + Send, for<'b> <Find<'b, Self> as HasTable>::Table: 'static + Send,
for<'b> &'a <Self as Crud<'b>>::InsertForm: Insertable<Self::Table>, for<'b> &'a <Self as Crud<'b>>::InsertForm: Insertable<Self::Table>,
for<'b> InsertValues<'a, 'b, Self>: 'a, for<'b> InsertValues<'a, 'b, Self>: 'a,
for<'b, 'query> InsertStatement<Self::Table, InsertValues<'query, 'b, Self>>: for<'b> InsertStatement<Self::Table, InsertValues<'a, 'b, Self>>:
LoadQuery<'query, AsyncPgConnection, Self> + 'query + Send, LoadQuery<'a, AsyncPgConnection, Self> + 'a + Send,
{ {
type InsertForm: 'static + Send + Sync; type InsertForm: 'static + Send + Sync;
type UpdateForm: 'static + Send + Sync; type UpdateForm: 'static + Send + Sync;
@ -63,18 +63,23 @@ 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<'life0, 'life1>( fn create<'life0, 'life1, 'async_trait>(
pool: &'life0 mut DbPool<'life1>, pool: &'life0 mut DbPool<'life1>,
form: &'a Self::InsertForm, form: &'a Self::InsertForm,
) -> Result<Self, Error> ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
//Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where where
'a: 'async_trait, 'a: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sized + '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
//Box::pin(get_conn(pool).and_then(move |mut conn| query.get_result::<Self>(&mut *conn))) Box::pin(
get_conn(pool)
.and_then(move |mut conn| async move { query.get_result::<Self>(&mut *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 where