✨ Replaced async_trait with async in traits from 2024 edition
This commit is contained in:
@ -9,6 +9,6 @@ pub(crate) struct PrimaryKey {
|
||||
|
||||
pub(crate) fn return_type(output: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
std::pin::Pin<Box<dyn core::future::Future<Output = Result<#output, lib::diesel_crud_trait::CrudError>> + Send + 'async_trait>>
|
||||
Result<#output, lib::diesel_crud_trait::CrudError>
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{common, Attributes};
|
||||
use crate::{Attributes, common};
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn derive_diesel_crud_create_impl(
|
||||
@ -16,37 +16,24 @@ pub(crate) fn derive_diesel_crud_create_impl(
|
||||
#[automatically_derived]
|
||||
impl lib::diesel_crud_trait::DieselCrudCreate<#table::table> for #struct_ident {
|
||||
type Insert = #insert;
|
||||
fn insert<'a, 'async_trait>(insert: Self::Insert, conn: &'a mut diesel_async::AsyncPgConnection) -> #return_type
|
||||
where
|
||||
Self: Sized + Sync + 'a,
|
||||
'a: 'async_trait,
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::dsl::insert_into(#table::table::table()).values(insert),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
async fn insert(insert: Self::Insert, conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::dsl::insert_into(#table::table::table()).values(insert),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
fn insert_many<'a, 'b, 'async_trait>(insert: &'a [Self::Insert], conn: &'b mut diesel_async::AsyncPgConnection) -> #many_return_type
|
||||
where
|
||||
Self: Sized + Sync + 'async_trait,
|
||||
'a: 'async_trait,
|
||||
'b: 'async_trait,
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_results(
|
||||
diesel::dsl::insert_into(#table::table::table()).values(insert),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
async fn insert_many(insert: &[Self::Insert], conn: &mut diesel_async::AsyncPgConnection) -> #many_return_type {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_results(
|
||||
diesel::dsl::insert_into(#table::table::table()).values(insert),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{common, Attributes, PrimaryKey};
|
||||
use crate::{Attributes, PrimaryKey, common};
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn derive_diesel_crud_delete_impl(
|
||||
@ -22,24 +22,18 @@ pub(crate) fn derive_diesel_crud_delete_impl(
|
||||
#[automatically_derived]
|
||||
impl lib::diesel_crud_trait::DieselCrudDelete for #struct_ident {
|
||||
type PK = #pk_type;
|
||||
fn delete<'a, 'async_trait>(pk: Self::PK, conn: &'a mut diesel_async::AsyncPgConnection) -> #return_type
|
||||
where
|
||||
Self: Sized + Sync + 'a,
|
||||
'a: 'async_trait,
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::QueryDsl;
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::delete(
|
||||
#table::table
|
||||
.filter(diesel::expression_methods::ExpressionMethods::eq(#table::#pk_ident, pk))
|
||||
),
|
||||
conn,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
async fn delete(pk: Self::PK, conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
|
||||
use diesel::QueryDsl;
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::delete(
|
||||
#table::table
|
||||
.filter(diesel::expression_methods::ExpressionMethods::eq(#table::#pk_ident, pk))
|
||||
),
|
||||
conn,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{common, Attributes};
|
||||
use crate::{Attributes, common};
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn derive_diesel_crud_list_impl(
|
||||
@ -13,15 +13,9 @@ pub(crate) fn derive_diesel_crud_list_impl(
|
||||
quote! {
|
||||
#[automatically_derived]
|
||||
impl lib::diesel_crud_trait::DieselCrudList for #struct_ident {
|
||||
fn list<'a, 'async_trait>(conn: &'a mut diesel_async::AsyncPgConnection) -> #return_type
|
||||
where
|
||||
Self: Sized + Sync + 'a,
|
||||
'a: 'async_trait
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_results(#table::table::table(), conn).await.map_err(Into::into)
|
||||
})
|
||||
async fn list(conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_results(#table::table::table(), conn).await.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::common::PrimaryKey;
|
||||
use crate::{common, Attributes};
|
||||
use crate::{Attributes, common};
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn derive_diesel_crud_read_impl(
|
||||
@ -20,20 +20,14 @@ pub(crate) fn derive_diesel_crud_read_impl(
|
||||
#[automatically_derived]
|
||||
impl lib::diesel_crud_trait::DieselCrudRead for #struct_ident {
|
||||
type PK = #pk_type;
|
||||
fn read<'a, 'async_trait>(pk: Self::PK, conn: &'a mut diesel_async::AsyncPgConnection) -> #return_type
|
||||
where
|
||||
Self: Sized + Sync + 'a,
|
||||
'a: 'async_trait
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::QueryDsl::find(#table::table::table(), pk),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
async fn read(pk: Self::PK, conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::QueryDsl::find(#table::table::table(), pk),
|
||||
conn
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{common, Attributes};
|
||||
use crate::{Attributes, common};
|
||||
use quote::quote;
|
||||
|
||||
pub(crate) fn derive_diesel_crud_update_impl(
|
||||
@ -15,20 +15,14 @@ pub(crate) fn derive_diesel_crud_update_impl(
|
||||
#[automatically_derived]
|
||||
impl lib::diesel_crud_trait::DieselCrudUpdate for #struct_ident {
|
||||
type Update = #update;
|
||||
fn update<'a, 'async_trait>(update: Self::Update, conn: &'a mut diesel_async::AsyncPgConnection) -> #return_type
|
||||
where
|
||||
Self: Sized + Sync + 'a,
|
||||
'a: 'async_trait,
|
||||
{
|
||||
Box::pin(async move {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::dsl::update(#table::table::table()).set(update),
|
||||
conn,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
})
|
||||
async fn update(update: Self::Update, conn: &mut diesel_async::AsyncPgConnection) -> #return_type {
|
||||
use diesel::associations::HasTable;
|
||||
diesel_async::RunQueryDsl::get_result(
|
||||
diesel::dsl::update(#table::table::table()).set(update),
|
||||
conn,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user