diff --git a/bench/usage/cornucopia_benches/generated_async.rs b/bench/usage/cornucopia_benches/generated_async.rs index 9b07dfe4..9b51c243 100644 --- a/bench/usage/cornucopia_benches/generated_async.rs +++ b/bench/usage/cornucopia_benches/generated_async.rs @@ -399,12 +399,16 @@ pub mod queries { client.execute(stmt, &[name, hair_color]).await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, InsertUserParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for InsertUserStmt @@ -414,7 +418,7 @@ pub mod queries { client: &'a C, params: &'a InsertUserParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind(client, ¶ms.name, ¶ms.hair_color)) } diff --git a/codegen_test/src/cornucopia_async.rs b/codegen_test/src/cornucopia_async.rs index 83c9efd6..f16bcea0 100644 --- a/codegen_test/src/cornucopia_async.rs +++ b/codegen_test/src/cornucopia_async.rs @@ -1304,12 +1304,16 @@ pub mod queries { .await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, InsertNightmareDomainParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for InsertNightmareDomainStmt @@ -1319,7 +1323,7 @@ pub mod queries { client: &'a C, params: &'a InsertNightmareDomainParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind( client, @@ -1713,12 +1717,16 @@ pub mod queries { client.execute(stmt, &[named]).await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, NamedComplexParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for NewNamedComplexStmt @@ -1728,7 +1736,7 @@ pub mod queries { client: &'a C, params: &'a NamedComplexParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind(client, ¶ms.named)) } @@ -1870,12 +1878,16 @@ pub mod queries { client.execute(stmt, &[texts, name, composite]).await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, NullityParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for NewNullityStmt @@ -1885,7 +1897,7 @@ pub mod queries { client: &'a C, params: &'a NullityParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite)) } @@ -2024,12 +2036,16 @@ pub mod queries { client.execute(stmt, &[author, name]).await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, InsertBookParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for InsertBookStmt @@ -2039,7 +2055,7 @@ pub mod queries { client: &'a C, params: &'a InsertBookParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind(client, ¶ms.author, ¶ms.name)) } @@ -2099,12 +2115,16 @@ pub mod queries { client.execute(stmt, &[c, a]).await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, ParamsOrderParams, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for ParamsOrderStmt @@ -2114,7 +2134,7 @@ pub mod queries { client: &'a C, params: &'a ParamsOrderParams, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind(client, ¶ms.c, ¶ms.a)) } @@ -3254,12 +3274,16 @@ pub mod queries { .await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, EverythingParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for InsertEverythingStmt @@ -3269,7 +3293,7 @@ pub mod queries { client: &'a C, params: &'a EverythingParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind( client, @@ -3480,12 +3504,16 @@ pub mod queries { .await } } - impl<'a, C: GenericClient> + impl<'a, C: GenericClient + Send + Sync> cornucopia_client::async_::Params< 'a, EverythingArrayParams<'a>, std::pin::Pin< - Box> + 'a>, + Box< + dyn futures::Future> + + Send + + 'a, + >, >, C, > for InsertEverythingArrayStmt @@ -3495,7 +3523,7 @@ pub mod queries { client: &'a C, params: &'a EverythingArrayParams<'a>, ) -> std::pin::Pin< - Box> + 'a>, + Box> + Send + 'a>, > { Box::pin(self.bind( client, diff --git a/codegen_test/src/main.rs b/codegen_test/src/main.rs index f6f77411..140ff709 100644 --- a/codegen_test/src/main.rs +++ b/codegen_test/src/main.rs @@ -8,7 +8,6 @@ use std::net::{IpAddr, Ipv4Addr}; use time::{OffsetDateTime, PrimitiveDateTime}; use uuid::Uuid; -use cornucopia_client::sync::Params; use crate::cornucopia_sync::{ queries::{ copy::{insert_clone, insert_copy, select_copy}, @@ -37,6 +36,7 @@ use crate::cornucopia_sync::{ SpongebobCharacter, }, }; +use cornucopia_client::sync::Params; pub fn main() { let client = &mut Config::new() diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index 6dd3fc7d..39d24108 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -491,19 +491,20 @@ fn gen_query_fn( }}" ); } else { - let (pre_ty, post_ty_lf, pre, post) = if is_async { + let (send_sync, pre_ty, post_ty_lf, pre, post) = if is_async { ( + "+ Send + Sync", "std::pin::Pin + 'a>>", + "> + Send + 'a>>", "Box::pin(", ")", ) } else { - ("", "", "", "") + ("", "", "", "", "") }; gen!( w, - "impl <'a, C: GenericClient> cornucopia_client::{mod_name}::Params<'a, {param_name}{lifetime}, {pre_ty}Result{post_ty_lf}, C> for {struct_name}Stmt {{ + "impl <'a, C: GenericClient {send_sync}> cornucopia_client::{mod_name}::Params<'a, {param_name}{lifetime}, {pre_ty}Result{post_ty_lf}, C> for {struct_name}Stmt {{ fn params(&'a mut self, client: &'a {client_mut} C, params: &'a {param_name}{lifetime}) -> {pre_ty}Result{post_ty_lf} {{ {pre}self.bind(client, {param_values}){post} }} diff --git a/cornucopia_client/src/async_.rs b/cornucopia_client/src/async_.rs index deeb46bd..ad9cfb25 100644 --- a/cornucopia_client/src/async_.rs +++ b/cornucopia_client/src/async_.rs @@ -9,7 +9,7 @@ use tokio_postgres::{ /// In addition, when the `deadpool` feature is enabled (default), this trait also /// abstracts over deadpool clients and transactions #[async_trait] -pub trait GenericClient { +pub trait GenericClient: Send + Sync { async fn prepare(&self, query: &str) -> Result; async fn execute( &self,