From 099846da340c874a7592bf903ae9338685ac840a Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 01:06:41 +0100 Subject: [PATCH 1/7] Bind client earlier --- bench/usage/cornucopia_benches/generated.rs | 355 +-- bench/usage/cornucopia_benches/mod.rs | 65 +- clients/async/src/lib.rs | 4 +- clients/sync/src/lib.rs | 4 +- codegen_test/src/cornucopia.rs | 2388 ++++++++++--------- codegen_test/src/main.rs | 183 +- cornucopia/src/codegen.rs | 32 +- examples/auto_build/src/cornucopia.rs | 24 +- examples/auto_build/src/main.rs | 2 +- examples/basic_async/src/cornucopia.rs | 190 +- examples/basic_async/src/main.rs | 33 +- examples/basic_sync/src/cornucopia.rs | 197 +- examples/basic_sync/src/main.rs | 35 +- 13 files changed, 1850 insertions(+), 1662 deletions(-) diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs index 33f68dd2..823b0864 100644 --- a/bench/usage/cornucopia_benches/generated.rs +++ b/bench/usage/cornucopia_benches/generated.rs @@ -343,19 +343,19 @@ pub mod queries { Ok(it) } } - pub fn users() -> UsersStmt { - UsersStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM users")) - } - pub struct UsersStmt(cornucopia_sync::private::Stmt); - impl UsersStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> UserQuery<'a, C, super::User, 0> { + pub fn users<'a, C: GenericClient>(client: &'a mut C) -> UsersStmt<'a, C> { + UsersStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM users"), + ) + } + pub struct UsersStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> UsersStmt<'a, C> { + pub fn bind(&'a mut self) -> UserQuery<'a, C, super::User, 0> { UserQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -365,26 +365,26 @@ pub mod queries { } } } - pub fn insert_user() -> InsertUserStmt { - InsertUserStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO users (name, hair_color) VALUES ($1, $2)", - )) - } - pub struct InsertUserStmt(cornucopia_sync::private::Stmt); - impl InsertUserStmt { - pub fn bind< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - >( + pub fn insert_user<'a, C: GenericClient>(client: &'a mut C) -> InsertUserStmt<'a, C> { + InsertUserStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO users (name, hair_color) VALUES ($1, $2)", + ), + ) + } + pub struct InsertUserStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertUserStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[name, hair_color]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[name, hair_color]) } } impl< @@ -397,30 +397,28 @@ pub mod queries { 'a, super::InsertUserParams, Result, - C, - > for InsertUserStmt + > for InsertUserStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::InsertUserParams, ) -> Result { - self.bind(client, ¶ms.name, ¶ms.hair_color) + self.bind(¶ms.name, ¶ms.hair_color) } } - pub fn posts() -> PostsStmt { - PostsStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM posts")) + pub fn posts<'a, C: GenericClient>(client: &'a mut C) -> PostsStmt<'a, C> { + PostsStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM posts"), + ) } - pub struct PostsStmt(cornucopia_sync::private::Stmt); - impl PostsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> PostQuery<'a, C, super::Post, 0> { + pub struct PostsStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> PostsStmt<'a, C> { + pub fn bind(&'a mut self) -> PostQuery<'a, C, super::Post, 0> { PostQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -431,22 +429,29 @@ pub mod queries { } } } - pub fn post_by_user_ids() -> PostByUserIdsStmt { - PostByUserIdsStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM posts WHERE user_id = ANY($1)", - )) - } - pub struct PostByUserIdsStmt(cornucopia_sync::private::Stmt); - impl PostByUserIdsStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( + pub fn post_by_user_ids<'a, C: GenericClient>( + client: &'a mut C, + ) -> PostByUserIdsStmt<'a, C> { + PostByUserIdsStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM posts WHERE user_id = ANY($1)", + ), + ) + } + pub struct PostByUserIdsStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> PostByUserIdsStmt<'a, C> { + pub fn bind>( &'a mut self, - client: &'a mut C, ids: &'a T1, ) -> PostQuery<'a, C, super::Post, 1> { PostQuery { - client, + client: self.0, params: [ids], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -457,21 +462,22 @@ pub mod queries { } } } - pub fn comments() -> CommentsStmt { - CommentsStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM comments", - )) + pub fn comments<'a, C: GenericClient>(client: &'a mut C) -> CommentsStmt<'a, C> { + CommentsStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM comments"), + ) } - pub struct CommentsStmt(cornucopia_sync::private::Stmt); - impl CommentsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> CommentQuery<'a, C, super::Comment, 0> { + pub struct CommentsStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> CommentsStmt<'a, C> { + pub fn bind(&'a mut self) -> CommentQuery<'a, C, super::Comment, 0> { CommentQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -481,22 +487,29 @@ pub mod queries { } } } - pub fn comments_by_post_id() -> CommentsByPostIdStmt { - CommentsByPostIdStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM comments WHERE post_id = ANY($1)", - )) - } - pub struct CommentsByPostIdStmt(cornucopia_sync::private::Stmt); - impl CommentsByPostIdStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( + pub fn comments_by_post_id<'a, C: GenericClient>( + client: &'a mut C, + ) -> CommentsByPostIdStmt<'a, C> { + CommentsByPostIdStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM comments WHERE post_id = ANY($1)", + ), + ) + } + pub struct CommentsByPostIdStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> CommentsByPostIdStmt<'a, C> { + pub fn bind>( &'a mut self, - client: &'a mut C, ids: &'a T1, ) -> CommentQuery<'a, C, super::Comment, 1> { CommentQuery { - client, + client: self.0, params: [ids], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -506,19 +519,21 @@ pub mod queries { } } } - pub fn select_complex() -> SelectComplexStmt { - SelectComplexStmt(cornucopia_sync :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) - } - pub struct SelectComplexStmt(cornucopia_sync::private::Stmt); - impl SelectComplexStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { + pub fn select_complex<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectComplexStmt<'a, C> { + SelectComplexStmt(client, cornucopia_sync :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) + } + pub struct SelectComplexStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectComplexStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { SelectComplexQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), @@ -757,19 +772,19 @@ pub mod queries { Ok(it) } } - pub fn users() -> UsersStmt { - UsersStmt(cornucopia_async::private::Stmt::new("SELECT * FROM users")) + pub fn users<'a, C: GenericClient>(client: &'a C) -> UsersStmt<'a, C> { + UsersStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM users"), + ) } - pub struct UsersStmt(cornucopia_async::private::Stmt); - impl UsersStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> UserQuery<'a, C, super::User, 0> { + pub struct UsersStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> UsersStmt<'a, C> { + pub fn bind(&'a mut self) -> UserQuery<'a, C, super::User, 0> { UserQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -779,26 +794,26 @@ pub mod queries { } } } - pub fn insert_user() -> InsertUserStmt { - InsertUserStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO users (name, hair_color) VALUES ($1, $2)", - )) + pub fn insert_user<'a, C: GenericClient>(client: &'a C) -> InsertUserStmt<'a, C> { + InsertUserStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO users (name, hair_color) VALUES ($1, $2)", + ), + ) } - pub struct InsertUserStmt(cornucopia_async::private::Stmt); - impl InsertUserStmt { + pub struct InsertUserStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> InsertUserStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, >( &'a mut self, - client: &'a C, name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[name, hair_color]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[name, hair_color]).await } } impl< @@ -817,12 +832,10 @@ pub mod queries { + 'a, >, >, - C, - > for InsertUserStmt + > for InsertUserStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::InsertUserParams, ) -> std::pin::Pin< Box< @@ -831,22 +844,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(client, ¶ms.name, ¶ms.hair_color)) + Box::pin(self.bind(¶ms.name, ¶ms.hair_color)) } } - pub fn posts() -> PostsStmt { - PostsStmt(cornucopia_async::private::Stmt::new("SELECT * FROM posts")) + pub fn posts<'a, C: GenericClient>(client: &'a C) -> PostsStmt<'a, C> { + PostsStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM posts"), + ) } - pub struct PostsStmt(cornucopia_async::private::Stmt); - impl PostsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> PostQuery<'a, C, super::Post, 0> { + pub struct PostsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> PostsStmt<'a, C> { + pub fn bind(&'a mut self) -> PostQuery<'a, C, super::Post, 0> { PostQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -857,22 +870,29 @@ pub mod queries { } } } - pub fn post_by_user_ids() -> PostByUserIdsStmt { - PostByUserIdsStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM posts WHERE user_id = ANY($1)", - )) - } - pub struct PostByUserIdsStmt(cornucopia_async::private::Stmt); - impl PostByUserIdsStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( + pub fn post_by_user_ids<'a, C: GenericClient>( + client: &'a C, + ) -> PostByUserIdsStmt<'a, C> { + PostByUserIdsStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM posts WHERE user_id = ANY($1)", + ), + ) + } + pub struct PostByUserIdsStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> PostByUserIdsStmt<'a, C> { + pub fn bind>( &'a mut self, - client: &'a C, ids: &'a T1, ) -> PostQuery<'a, C, super::Post, 1> { PostQuery { - client, + client: self.0, params: [ids], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -883,21 +903,19 @@ pub mod queries { } } } - pub fn comments() -> CommentsStmt { - CommentsStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM comments", - )) + pub fn comments<'a, C: GenericClient>(client: &'a C) -> CommentsStmt<'a, C> { + CommentsStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM comments"), + ) } - pub struct CommentsStmt(cornucopia_async::private::Stmt); - impl CommentsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> CommentQuery<'a, C, super::Comment, 0> { + pub struct CommentsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> CommentsStmt<'a, C> { + pub fn bind(&'a mut self) -> CommentQuery<'a, C, super::Comment, 0> { CommentQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -907,22 +925,29 @@ pub mod queries { } } } - pub fn comments_by_post_id() -> CommentsByPostIdStmt { - CommentsByPostIdStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM comments WHERE post_id = ANY($1)", - )) - } - pub struct CommentsByPostIdStmt(cornucopia_async::private::Stmt); - impl CommentsByPostIdStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( + pub fn comments_by_post_id<'a, C: GenericClient>( + client: &'a C, + ) -> CommentsByPostIdStmt<'a, C> { + CommentsByPostIdStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM comments WHERE post_id = ANY($1)", + ), + ) + } + pub struct CommentsByPostIdStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> CommentsByPostIdStmt<'a, C> { + pub fn bind>( &'a mut self, - client: &'a C, ids: &'a T1, ) -> CommentQuery<'a, C, super::Comment, 1> { CommentQuery { - client, + client: self.0, params: [ids], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -932,19 +957,19 @@ pub mod queries { } } } - pub fn select_complex() -> SelectComplexStmt { - SelectComplexStmt(cornucopia_async :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) + pub fn select_complex<'a, C: GenericClient>(client: &'a C) -> SelectComplexStmt<'a, C> { + SelectComplexStmt(client, cornucopia_async :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) } - pub struct SelectComplexStmt(cornucopia_async::private::Stmt); - impl SelectComplexStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { + pub struct SelectComplexStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectComplexStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { SelectComplexQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), diff --git a/bench/usage/cornucopia_benches/mod.rs b/bench/usage/cornucopia_benches/mod.rs index d81081f7..1b082282 100644 --- a/bench/usage/cornucopia_benches/mod.rs +++ b/bench/usage/cornucopia_benches/mod.rs @@ -12,15 +12,14 @@ use self::generated::queries::bench::{ mod generated; pub fn bench_trivial_query(b: &mut Bencher, client: &Client) { - let mut stmt = users(); - b.iter(|| block_on(async { stmt.bind(client).all().await.unwrap() })) + b.iter(move || block_on(async { users(client).bind().all().await.unwrap() })) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { - let mut stmt = select_complex(); b.iter(|| { block_on(async { - stmt.bind(client) + select_complex(client) + .bind() .map(|it| { ( User { @@ -44,18 +43,14 @@ pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { - let mut stmt = insert_user(); b.iter(|| { block_on(async { let mut tx = client.transaction().await.unwrap(); for x in 0..size { - stmt.bind( - &mut tx, - &format!("User {}", x).as_str(), - &Some("hair_color"), - ) - .await - .unwrap(); + insert_user(&mut tx) + .bind(&format!("User {}", x).as_str(), &Some("hair_color")) + .await + .unwrap(); } tx.commit().await.unwrap(); }) @@ -63,21 +58,19 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { } pub fn loading_associations_sequentially(b: &mut Bencher, client: &Client) { - let mut user_stmt = users(); - let mut post_stmt = post_by_user_ids(); - let mut comment_stmt = comments_by_post_id(); b.iter(|| { + let mut user_stmt = users(client); block_on(async { - let users = user_stmt.bind(client).all().await.unwrap(); + let users = user_stmt.bind().all().await.unwrap(); let users_ids: Vec = users.iter().map(|it| it.id).collect(); - let posts = post_stmt - .bind(client, &users_ids.as_slice()) + let posts = post_by_user_ids(client) + .bind(&users_ids.as_slice()) .all() .await .unwrap(); let posts_ids: Vec = posts.iter().map(|it| it.id).collect(); - let comments = comment_stmt - .bind(client, &posts_ids.as_slice()) + let comments = comments_by_post_id(client) + .bind(&posts_ids.as_slice()) .all() .await .unwrap(); @@ -123,14 +116,13 @@ pub mod sync { Comment, Post, User, }; pub fn bench_trivial_query(b: &mut Bencher, client: &mut Client) { - let mut stmt = users(); - b.iter(|| stmt.bind(client).all().unwrap()) + b.iter(|| users(client).bind().all().unwrap()) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &mut Client) { - let mut stmt = select_complex(); b.iter(|| { - stmt.bind(client) + select_complex(client) + .bind() .map(|it| { ( User { @@ -152,33 +144,28 @@ pub mod sync { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { - let mut stmt = insert_user(); b.iter(|| { let mut tx = client.transaction().unwrap(); for x in 0..size { - stmt.bind( - &mut tx, - &format!("User {}", x).as_str(), - &Some("hair_color"), - ) - .unwrap(); + insert_user(&mut tx) + .bind(&format!("User {}", x).as_str(), &Some("hair_color")) + .unwrap(); } tx.commit().unwrap(); }) } pub fn loading_associations_sequentially(b: &mut Bencher, client: &mut Client) { - let mut user_stmt = users(); - let mut post_stmt = post_by_user_ids(); - let mut comment_stmt = comments_by_post_id(); - b.iter(|| { - let users = user_stmt.bind(client).all().unwrap(); + let users = users(client).bind().all().unwrap(); let users_ids: Vec = users.iter().map(|it| it.id).collect(); - let posts = post_stmt.bind(client, &users_ids.as_slice()).all().unwrap(); + let posts = post_by_user_ids(client) + .bind(&users_ids.as_slice()) + .all() + .unwrap(); let posts_ids: Vec = posts.iter().map(|it| it.id).collect(); - let comments = comment_stmt - .bind(client, &posts_ids.as_slice()) + let comments = comments_by_post_id(client) + .bind(&posts_ids.as_slice()) .all() .unwrap(); diff --git a/clients/async/src/lib.rs b/clients/async/src/lib.rs index ddded593..63403884 100644 --- a/clients/async/src/lib.rs +++ b/clients/async/src/lib.rs @@ -13,6 +13,6 @@ mod generic_client; /// This trait allows you to bind parameters to a query using a single /// struct, rather than passing each bind parameter as a function parameter. -pub trait Params<'a, P, O, C> { - fn params(&'a mut self, client: &'a C, params: &'a P) -> O; +pub trait Params<'a, P, O> { + fn params(&'a mut self, params: &'a P) -> O; } diff --git a/clients/sync/src/lib.rs b/clients/sync/src/lib.rs index 84c4c7f5..0e2d5fc2 100644 --- a/clients/sync/src/lib.rs +++ b/clients/sync/src/lib.rs @@ -8,6 +8,6 @@ pub use cornucopia_client_core::JsonSql; /// This trait allows you to bind parameters to a query using a single /// struct, rather than passing each bind parameter as a function parameter. -pub trait Params<'a, P, O, C> { - fn params(&'a mut self, client: &'a mut C, params: &'a P) -> O; +pub trait Params<'a, P, O> { + fn params(&'a mut self, params: &'a P) -> O; } diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs index 38df419d..7e4ad16f 100644 --- a/codegen_test/src/cornucopia.rs +++ b/codegen_test/src/cornucopia.rs @@ -1370,30 +1370,40 @@ pub mod queries { Ok(it) } } - pub fn insert_clone() -> InsertCloneStmt { - InsertCloneStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO clone (composite) VALUES ($1)", - )) - } - pub struct InsertCloneStmt(cornucopia_sync::private::Stmt); - impl InsertCloneStmt { - pub fn bind<'a, C: GenericClient>( + pub fn insert_clone<'a, C: GenericClient>(client: &'a mut C) -> InsertCloneStmt<'a, C> { + InsertCloneStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO clone (composite) VALUES ($1)", + ), + ) + } + pub struct InsertCloneStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertCloneStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[composite]) } } - pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) + pub fn select_clone<'a, C: GenericClient>(client: &'a mut C) -> SelectCloneStmt<'a, C> { + SelectCloneStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM clone"), + ) } - pub struct SelectCloneStmt(cornucopia_sync::private::Stmt); - impl SelectCloneStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCloneStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectCloneStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -1401,38 +1411,46 @@ pub mod queries { 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_copy() -> InsertCopyStmt { - InsertCopyStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO copy (composite) VALUES ($1)", - )) + pub fn insert_copy<'a, C: GenericClient>(client: &'a mut C) -> InsertCopyStmt<'a, C> { + InsertCopyStmt( + client, + cornucopia_sync::private::Stmt::new("INSERT INTO copy (composite) VALUES ($1)"), + ) } - pub struct InsertCopyStmt(cornucopia_sync::private::Stmt); - impl InsertCopyStmt { - pub fn bind<'a, C: GenericClient>( + pub struct InsertCopyStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertCopyStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[composite]) } } - pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM copy")) + pub fn select_copy<'a, C: GenericClient>(client: &'a mut C) -> SelectCopyStmt<'a, C> { + SelectCopyStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM copy"), + ) } - pub struct SelectCopyStmt(cornucopia_sync::private::Stmt); - impl SelectCopyStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCopyStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectCopyStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> PublicCopyCompositeQuery< 'a, C, @@ -1440,9 +1458,9 @@ pub mod queries { 0, > { PublicCopyCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -1567,30 +1585,40 @@ pub mod queries { Ok(it) } } - pub fn insert_clone() -> InsertCloneStmt { - InsertCloneStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO clone (composite) VALUES ($1)", - )) + pub fn insert_clone<'a, C: GenericClient>(client: &'a C) -> InsertCloneStmt<'a, C> { + InsertCloneStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO clone (composite) VALUES ($1)", + ), + ) } - pub struct InsertCloneStmt(cornucopia_async::private::Stmt); - impl InsertCloneStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct InsertCloneStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> InsertCloneStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[composite]).await } } - pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) + pub fn select_clone<'a, C: GenericClient>(client: &'a C) -> SelectCloneStmt<'a, C> { + SelectCloneStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM clone"), + ) } - pub struct SelectCloneStmt(cornucopia_async::private::Stmt); - impl SelectCloneStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCloneStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectCloneStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -1598,38 +1626,42 @@ pub mod queries { 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_copy() -> InsertCopyStmt { - InsertCopyStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO copy (composite) VALUES ($1)", - )) + pub fn insert_copy<'a, C: GenericClient>(client: &'a C) -> InsertCopyStmt<'a, C> { + InsertCopyStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO copy (composite) VALUES ($1)", + ), + ) } - pub struct InsertCopyStmt(cornucopia_async::private::Stmt); - impl InsertCopyStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct InsertCopyStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> InsertCopyStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[composite]).await } } - pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt(cornucopia_async::private::Stmt::new("SELECT * FROM copy")) + pub fn select_copy<'a, C: GenericClient>(client: &'a C) -> SelectCopyStmt<'a, C> { + SelectCopyStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM copy"), + ) } - pub struct SelectCopyStmt(cornucopia_async::private::Stmt); - impl SelectCopyStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCopyStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> SelectCopyStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> PublicCopyCompositeQuery< 'a, C, @@ -1637,9 +1669,9 @@ pub mod queries { 0, > { PublicCopyCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -1840,22 +1872,29 @@ pub mod queries { Ok(it) } } - pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt(cornucopia_sync::private::Stmt::new( - "SELECT txt, json, nb, arr FROM nightmare_domain", - )) + pub fn select_nightmare_domain<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectNightmareDomainStmt<'a, C> { + SelectNightmareDomainStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT txt, json, nb, arr FROM nightmare_domain", + ), + ) } - pub struct SelectNightmareDomainStmt(cornucopia_sync::private::Stmt); - impl SelectNightmareDomainStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareDomainStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareDomainStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> { SelectNightmareDomainQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -1866,21 +1905,23 @@ pub mod queries { } } } - pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { - InsertNightmareDomainStmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) - } - pub struct InsertNightmareDomainStmt(cornucopia_sync::private::Stmt); - impl InsertNightmareDomainStmt { + pub fn insert_nightmare_domain<'a, C: GenericClient>( + client: &'a mut C, + ) -> InsertNightmareDomainStmt<'a, C> { + InsertNightmareDomainStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) + } + pub struct InsertNightmareDomainStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertNightmareDomainStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::JsonSql, T3: cornucopia_sync::JsonSql, T4: cornucopia_sync::ArraySql, >( &'a mut self, - client: &'a mut C, txt: &'a T1, json: &'a T2, nb: &'a i32, @@ -1889,8 +1930,8 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( + let stmt = self.1.prepare(self.0)?; + self.0.execute( stmt, &[ &cornucopia_sync::private::Domain(txt), @@ -1916,16 +1957,13 @@ pub mod queries { 'a, super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, Result, - C, - > for InsertNightmareDomainStmt + > for InsertNightmareDomainStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, ) -> Result { self.bind( - client, ¶ms.txt, ¶ms.json, ¶ms.nb, @@ -1934,22 +1972,27 @@ pub mod queries { ) } } - pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM nightmare_domain", - )) + pub fn select_nightmare_domain_null<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectNightmareDomainNullStmt<'a, C> { + SelectNightmareDomainNullStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM nightmare_domain"), + ) } - pub struct SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt); - impl SelectNightmareDomainNullStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareDomainNullStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareDomainNullStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> { SelectNightmareDomainNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -2076,22 +2119,29 @@ pub mod queries { Ok(it) } } - pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt(cornucopia_async::private::Stmt::new( - "SELECT txt, json, nb, arr FROM nightmare_domain", - )) + pub fn select_nightmare_domain<'a, C: GenericClient>( + client: &'a C, + ) -> SelectNightmareDomainStmt<'a, C> { + SelectNightmareDomainStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT txt, json, nb, arr FROM nightmare_domain", + ), + ) } - pub struct SelectNightmareDomainStmt(cornucopia_async::private::Stmt); - impl SelectNightmareDomainStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareDomainStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareDomainStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> { SelectNightmareDomainQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -2102,21 +2152,23 @@ pub mod queries { } } } - pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { - InsertNightmareDomainStmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) - } - pub struct InsertNightmareDomainStmt(cornucopia_async::private::Stmt); - impl InsertNightmareDomainStmt { + pub fn insert_nightmare_domain<'a, C: GenericClient>( + client: &'a C, + ) -> InsertNightmareDomainStmt<'a, C> { + InsertNightmareDomainStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) + } + pub struct InsertNightmareDomainStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> InsertNightmareDomainStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::JsonSql, T3: cornucopia_async::JsonSql, T4: cornucopia_async::ArraySql, >( &'a mut self, - client: &'a C, txt: &'a T1, json: &'a T2, nb: &'a i32, @@ -2125,8 +2177,8 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = self.0.prepare(client).await?; - client + let stmt = self.1.prepare(self.0).await?; + self.0 .execute( stmt, &[ @@ -2160,12 +2212,10 @@ pub mod queries { + 'a, >, >, - C, - > for InsertNightmareDomainStmt + > for InsertNightmareDomainStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, ) -> std::pin::Pin< Box< @@ -2175,7 +2225,6 @@ pub mod queries { >, > { Box::pin(self.bind( - client, ¶ms.txt, ¶ms.json, ¶ms.nb, @@ -2184,22 +2233,27 @@ pub mod queries { )) } } - pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM nightmare_domain", - )) + pub fn select_nightmare_domain_null<'a, C: GenericClient>( + client: &'a C, + ) -> SelectNightmareDomainNullStmt<'a, C> { + SelectNightmareDomainNullStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM nightmare_domain"), + ) } - pub struct SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt); - impl SelectNightmareDomainNullStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareDomainNullStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareDomainNullStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> { SelectNightmareDomainNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -2432,87 +2486,99 @@ pub mod queries { Ok(it) } } - pub fn new_named_visible() -> NewNamedVisibleStmt { - NewNamedVisibleStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", - )) + pub fn new_named_visible<'a, C: GenericClient>( + client: &'a mut C, + ) -> NewNamedVisibleStmt<'a, C> { + NewNamedVisibleStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", + ), + ) } - pub struct NewNamedVisibleStmt(cornucopia_sync::private::Stmt); - impl NewNamedVisibleStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct NewNamedVisibleStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedVisibleStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a T1, price: &'a Option, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>, C> - for NewNamedVisibleStmt + cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> + for NewNamedVisibleStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn new_named_hidden() -> NewNamedHiddenStmt { - NewNamedHiddenStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn new_named_hidden<'a, C: GenericClient>( + client: &'a mut C, + ) -> NewNamedHiddenStmt<'a, C> { + NewNamedHiddenStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NewNamedHiddenStmt(cornucopia_sync::private::Stmt); - impl NewNamedHiddenStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct NewNamedHiddenStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedHiddenStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, price: &'a Option, name: &'a T1, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client, + client: self.0, params: [price, name], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>, C> - for NewNamedHiddenStmt + cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> + for NewNamedHiddenStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(client, ¶ms.price, ¶ms.name) + self.bind(¶ms.price, ¶ms.name) } } - pub fn named() -> NamedStmt { - NamedStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM named")) + pub fn named<'a, C: GenericClient>(client: &'a mut C) -> NamedStmt<'a, C> { + NamedStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM named"), + ) } - pub struct NamedStmt(cornucopia_sync::private::Stmt); - impl NamedStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> NamedQuery<'a, C, super::Named, 0> { + pub struct NamedStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> NamedStmt<'a, C> { + pub fn bind(&'a mut self) -> NamedQuery<'a, C, super::Named, 0> { NamedQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2523,22 +2589,22 @@ pub mod queries { } } } - pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM named WHERE id = $1", - )) + pub fn named_by_id<'a, C: GenericClient>(client: &'a mut C) -> NamedByIdStmt<'a, C> { + NamedByIdStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM named WHERE id = $1"), + ) } - pub struct NamedByIdStmt(cornucopia_sync::private::Stmt); - impl NamedByIdStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - id: &'a i32, - ) -> NamedQuery<'a, C, super::Named, 1> { + pub struct NamedByIdStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NamedByIdStmt<'a, C> { + pub fn bind(&'a mut self, id: &'a i32) -> NamedQuery<'a, C, super::Named, 1> { NamedQuery { - client, + client: self.0, params: [id], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2549,23 +2615,30 @@ pub mod queries { } } } - pub fn new_named_complex() -> NewNamedComplexStmt { - NewNamedComplexStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", - )) + pub fn new_named_complex<'a, C: GenericClient>( + client: &'a mut C, + ) -> NewNamedComplexStmt<'a, C> { + NewNamedComplexStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", + ), + ) } - pub struct NewNamedComplexStmt(cornucopia_sync::private::Stmt); - impl NewNamedComplexStmt { - pub fn bind<'a, C: GenericClient>( + pub struct NewNamedComplexStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedComplexStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, named: &'a super::super::super::types::public::NamedCompositeBorrowed<'a>, named_with_dot: &'a Option< super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[named, named_with_dot]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[named, named_with_dot]) } } impl<'a, C: GenericClient> @@ -2573,32 +2646,33 @@ pub mod queries { 'a, super::NamedComplexParams<'a>, Result, - C, - > for NewNamedComplexStmt + > for NewNamedComplexStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::NamedComplexParams<'a>, ) -> Result { - self.bind(client, ¶ms.named, ¶ms.named_with_dot) + self.bind(¶ms.named, ¶ms.named_with_dot) } } - pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM named_complex", - )) + pub fn named_complex<'a, C: GenericClient>( + client: &'a mut C, + ) -> NamedComplexStmt<'a, C> { + NamedComplexStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM named_complex"), + ) } - pub struct NamedComplexStmt(cornucopia_sync::private::Stmt); - impl NamedComplexStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { + pub struct NamedComplexStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NamedComplexStmt<'a, C> { + pub fn bind(&'a mut self) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { NamedComplexQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -2774,95 +2848,99 @@ pub mod queries { Ok(it) } } - pub fn new_named_visible() -> NewNamedVisibleStmt { - NewNamedVisibleStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", - )) + pub fn new_named_visible<'a, C: GenericClient>( + client: &'a C, + ) -> NewNamedVisibleStmt<'a, C> { + NewNamedVisibleStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", + ), + ) } - pub struct NewNamedVisibleStmt(cornucopia_async::private::Stmt); - impl NewNamedVisibleStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct NewNamedVisibleStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedVisibleStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, name: &'a T1, price: &'a Option, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params< - 'a, - super::NamedParams, - IdQuery<'a, C, super::Id, 2>, - C, - > for NewNamedVisibleStmt + cornucopia_async::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> + for NewNamedVisibleStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn new_named_hidden() -> NewNamedHiddenStmt { - NewNamedHiddenStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn new_named_hidden<'a, C: GenericClient>( + client: &'a C, + ) -> NewNamedHiddenStmt<'a, C> { + NewNamedHiddenStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NewNamedHiddenStmt(cornucopia_async::private::Stmt); - impl NewNamedHiddenStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct NewNamedHiddenStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedHiddenStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, price: &'a Option, name: &'a T1, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client, + client: self.0, params: [price, name], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params< - 'a, - super::NamedParams, - IdQuery<'a, C, super::Id, 2>, - C, - > for NewNamedHiddenStmt + cornucopia_async::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> + for NewNamedHiddenStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(client, ¶ms.price, ¶ms.name) + self.bind(¶ms.price, ¶ms.name) } } - pub fn named() -> NamedStmt { - NamedStmt(cornucopia_async::private::Stmt::new("SELECT * FROM named")) + pub fn named<'a, C: GenericClient>(client: &'a C) -> NamedStmt<'a, C> { + NamedStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM named"), + ) } - pub struct NamedStmt(cornucopia_async::private::Stmt); - impl NamedStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> NamedQuery<'a, C, super::Named, 0> { + pub struct NamedStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> NamedStmt<'a, C> { + pub fn bind(&'a mut self) -> NamedQuery<'a, C, super::Named, 0> { NamedQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2873,22 +2951,19 @@ pub mod queries { } } } - pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM named WHERE id = $1", - )) + pub fn named_by_id<'a, C: GenericClient>(client: &'a C) -> NamedByIdStmt<'a, C> { + NamedByIdStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM named WHERE id = $1"), + ) } - pub struct NamedByIdStmt(cornucopia_async::private::Stmt); - impl NamedByIdStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - id: &'a i32, - ) -> NamedQuery<'a, C, super::Named, 1> { + pub struct NamedByIdStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> NamedByIdStmt<'a, C> { + pub fn bind(&'a mut self, id: &'a i32) -> NamedQuery<'a, C, super::Named, 1> { NamedQuery { - client, + client: self.0, params: [id], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2899,23 +2974,30 @@ pub mod queries { } } } - pub fn new_named_complex() -> NewNamedComplexStmt { - NewNamedComplexStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", - )) + pub fn new_named_complex<'a, C: GenericClient>( + client: &'a C, + ) -> NewNamedComplexStmt<'a, C> { + NewNamedComplexStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", + ), + ) } - pub struct NewNamedComplexStmt(cornucopia_async::private::Stmt); - impl NewNamedComplexStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct NewNamedComplexStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NewNamedComplexStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, named: &'a super::super::super::types::public::NamedCompositeBorrowed<'a>, named_with_dot: &'a Option< super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[named, named_with_dot]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[named, named_with_dot]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -2929,12 +3011,10 @@ pub mod queries { + 'a, >, >, - C, - > for NewNamedComplexStmt + > for NewNamedComplexStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::NamedComplexParams<'a>, ) -> std::pin::Pin< Box< @@ -2943,24 +3023,25 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(client, ¶ms.named, ¶ms.named_with_dot)) + Box::pin(self.bind(¶ms.named, ¶ms.named_with_dot)) } } - pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM named_complex", - )) + pub fn named_complex<'a, C: GenericClient>(client: &'a C) -> NamedComplexStmt<'a, C> { + NamedComplexStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM named_complex"), + ) } - pub struct NamedComplexStmt(cornucopia_async::private::Stmt); - impl NamedComplexStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { + pub struct NamedComplexStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NamedComplexStmt<'a, C> { + pub fn bind(&'a mut self) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { NamedComplexQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -3062,30 +3143,33 @@ pub mod queries { Ok(it) } } - pub fn new_nullity() -> NewNullityStmt { - NewNullityStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", - )) + pub fn new_nullity<'a, C: GenericClient>(client: &'a mut C) -> NewNullityStmt<'a, C> { + NewNullityStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", + ), + ) } - pub struct NewNullityStmt(cornucopia_sync::private::Stmt); - impl NewNullityStmt { + pub struct NewNullityStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NewNullityStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::ArraySql>, T3: cornucopia_sync::StringSql, >( &'a mut self, - client: &'a mut C, texts: &'a T2, name: &'a T3, composite: &'a Option< super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[texts, name, composite]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[texts, name, composite]) } } impl< @@ -3099,30 +3183,28 @@ pub mod queries { 'a, super::NullityParams<'a, T1, T2, T3>, Result, - C, - > for NewNullityStmt + > for NewNullityStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::NullityParams<'a, T1, T2, T3>, ) -> Result { - self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite) + self.bind(¶ms.texts, ¶ms.name, ¶ms.composite) } } - pub fn nullity() -> NullityStmt { - NullityStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM nullity")) + pub fn nullity<'a, C: GenericClient>(client: &'a mut C) -> NullityStmt<'a, C> { + NullityStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM nullity"), + ) } - pub struct NullityStmt(cornucopia_sync::private::Stmt); - impl NullityStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> NullityQuery<'a, C, super::Nullity, 0> { + pub struct NullityStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> NullityStmt<'a, C> { + pub fn bind(&'a mut self) -> NullityQuery<'a, C, super::Nullity, 0> { NullityQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3192,30 +3274,30 @@ pub mod queries { Ok(it) } } - pub fn new_nullity() -> NewNullityStmt { - NewNullityStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", - )) + pub fn new_nullity<'a, C: GenericClient>(client: &'a C) -> NewNullityStmt<'a, C> { + NewNullityStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", + ), + ) } - pub struct NewNullityStmt(cornucopia_async::private::Stmt); - impl NewNullityStmt { + pub struct NewNullityStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> NewNullityStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::ArraySql>, T3: cornucopia_async::StringSql, >( &'a mut self, - client: &'a C, texts: &'a T2, name: &'a T3, composite: &'a Option< super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[texts, name, composite]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[texts, name, composite]).await } } impl< @@ -3235,12 +3317,10 @@ pub mod queries { + 'a, >, >, - C, - > for NewNullityStmt + > for NewNullityStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::NullityParams<'a, T1, T2, T3>, ) -> std::pin::Pin< Box< @@ -3249,24 +3329,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite)) + Box::pin(self.bind(¶ms.texts, ¶ms.name, ¶ms.composite)) } } - pub fn nullity() -> NullityStmt { - NullityStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM nullity", - )) + pub fn nullity<'a, C: GenericClient>(client: &'a C) -> NullityStmt<'a, C> { + NullityStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM nullity"), + ) } - pub struct NullityStmt(cornucopia_async::private::Stmt); - impl NullityStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> NullityQuery<'a, C, super::Nullity, 0> { + pub struct NullityStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> NullityStmt<'a, C> { + pub fn bind(&'a mut self) -> NullityQuery<'a, C, super::Nullity, 0> { NullityQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3430,26 +3508,26 @@ pub mod queries { Ok(it) } } - pub fn insert_book() -> InsertBookStmt { - InsertBookStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO book (author, name) VALUES ($1, $2)", - )) + pub fn insert_book<'a, C: GenericClient>(client: &'a mut C) -> InsertBookStmt<'a, C> { + InsertBookStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO book (author, name) VALUES ($1, $2)", + ), + ) } - pub struct InsertBookStmt(cornucopia_sync::private::Stmt); - impl InsertBookStmt { - pub fn bind< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - >( + pub struct InsertBookStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertBookStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, author: &'a Option, name: &'a T2, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[author, name]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[author, name]) } } impl< @@ -3462,30 +3540,31 @@ pub mod queries { 'a, super::InsertBookParams, Result, - C, - > for InsertBookStmt + > for InsertBookStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::InsertBookParams, ) -> Result { - self.bind(client, ¶ms.author, ¶ms.name) + self.bind(¶ms.author, ¶ms.name) } } - pub fn select_book() -> SelectBookStmt { - SelectBookStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM book")) + pub fn select_book<'a, C: GenericClient>(client: &'a mut C) -> SelectBookStmt<'a, C> { + SelectBookStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM book"), + ) } - pub struct SelectBookStmt(cornucopia_sync::private::Stmt); - impl SelectBookStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SelectBookQuery<'a, C, super::SelectBook, 0> { + pub struct SelectBookStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectBookStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectBookQuery<'a, C, super::SelectBook, 0> { SelectBookQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3494,27 +3573,28 @@ pub mod queries { } } } - pub fn find_books() -> FindBooksStmt { - FindBooksStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM book WHERE name = ANY ($1)", - )) + pub fn find_books<'a, C: GenericClient>(client: &'a mut C) -> FindBooksStmt<'a, C> { + FindBooksStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM book WHERE name = ANY ($1)"), + ) } - pub struct FindBooksStmt(cornucopia_sync::private::Stmt); - impl FindBooksStmt { + pub struct FindBooksStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> FindBooksStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::ArraySql, >( &'a mut self, - client: &'a mut C, title: &'a T2, ) -> FindBooksQuery<'a, C, super::FindBooks, 1> { FindBooksQuery { - client, + client: self.0, params: [title], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3523,53 +3603,56 @@ pub mod queries { } } } - pub fn params_use_twice() -> ParamsUseTwiceStmt { - ParamsUseTwiceStmt(cornucopia_sync::private::Stmt::new( - "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", - )) + pub fn params_use_twice<'a, C: GenericClient>( + client: &'a mut C, + ) -> ParamsUseTwiceStmt<'a, C> { + ParamsUseTwiceStmt( + client, + cornucopia_sync::private::Stmt::new( + "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", + ), + ) } - pub struct ParamsUseTwiceStmt(cornucopia_sync::private::Stmt); - impl ParamsUseTwiceStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct ParamsUseTwiceStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> ParamsUseTwiceStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a T1, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[name]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[name]) } } - pub fn params_order() -> ParamsOrderStmt { - ParamsOrderStmt(cornucopia_sync::private::Stmt::new( - "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", - )) + pub fn params_order<'a, C: GenericClient>(client: &'a mut C) -> ParamsOrderStmt<'a, C> { + ParamsOrderStmt( + client, + cornucopia_sync::private::Stmt::new( + "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", + ), + ) } - pub struct ParamsOrderStmt(cornucopia_sync::private::Stmt); - impl ParamsOrderStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - c: &'a i32, - a: &'a i32, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[c, a]) + pub struct ParamsOrderStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> ParamsOrderStmt<'a, C> { + pub fn bind(&'a mut self, c: &'a i32, a: &'a i32) -> Result { + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[c, a]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::ParamsOrderParams, - Result, - C, - > for ParamsOrderStmt + cornucopia_sync::Params<'a, super::ParamsOrderParams, Result> + for ParamsOrderStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::ParamsOrderParams, ) -> Result { - self.bind(client, ¶ms.c, ¶ms.a) + self.bind(¶ms.c, ¶ms.a) } } } @@ -3687,26 +3770,26 @@ pub mod queries { Ok(it) } } - pub fn insert_book() -> InsertBookStmt { - InsertBookStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO book (author, name) VALUES ($1, $2)", - )) + pub fn insert_book<'a, C: GenericClient>(client: &'a C) -> InsertBookStmt<'a, C> { + InsertBookStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO book (author, name) VALUES ($1, $2)", + ), + ) } - pub struct InsertBookStmt(cornucopia_async::private::Stmt); - impl InsertBookStmt { + pub struct InsertBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> InsertBookStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, >( &'a mut self, - client: &'a C, author: &'a Option, name: &'a T2, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[author, name]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[author, name]).await } } impl< @@ -3725,12 +3808,10 @@ pub mod queries { + 'a, >, >, - C, - > for InsertBookStmt + > for InsertBookStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::InsertBookParams, ) -> std::pin::Pin< Box< @@ -3739,22 +3820,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(client, ¶ms.author, ¶ms.name)) + Box::pin(self.bind(¶ms.author, ¶ms.name)) } } - pub fn select_book() -> SelectBookStmt { - SelectBookStmt(cornucopia_async::private::Stmt::new("SELECT * FROM book")) + pub fn select_book<'a, C: GenericClient>(client: &'a C) -> SelectBookStmt<'a, C> { + SelectBookStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM book"), + ) } - pub struct SelectBookStmt(cornucopia_async::private::Stmt); - impl SelectBookStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SelectBookQuery<'a, C, super::SelectBook, 0> { + pub struct SelectBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> SelectBookStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectBookQuery<'a, C, super::SelectBook, 0> { SelectBookQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3763,27 +3844,27 @@ pub mod queries { } } } - pub fn find_books() -> FindBooksStmt { - FindBooksStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM book WHERE name = ANY ($1)", - )) + pub fn find_books<'a, C: GenericClient>(client: &'a C) -> FindBooksStmt<'a, C> { + FindBooksStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM book WHERE name = ANY ($1)", + ), + ) } - pub struct FindBooksStmt(cornucopia_async::private::Stmt); - impl FindBooksStmt { + pub struct FindBooksStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> FindBooksStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::ArraySql, >( &'a mut self, - client: &'a C, title: &'a T2, ) -> FindBooksQuery<'a, C, super::FindBooks, 1> { FindBooksQuery { - client, + client: self.0, params: [title], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3792,37 +3873,49 @@ pub mod queries { } } } - pub fn params_use_twice() -> ParamsUseTwiceStmt { - ParamsUseTwiceStmt(cornucopia_async::private::Stmt::new( - "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", - )) + pub fn params_use_twice<'a, C: GenericClient>( + client: &'a C, + ) -> ParamsUseTwiceStmt<'a, C> { + ParamsUseTwiceStmt( + client, + cornucopia_async::private::Stmt::new( + "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", + ), + ) } - pub struct ParamsUseTwiceStmt(cornucopia_async::private::Stmt); - impl ParamsUseTwiceStmt { - pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct ParamsUseTwiceStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> ParamsUseTwiceStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, name: &'a T1, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[name]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[name]).await } } - pub fn params_order() -> ParamsOrderStmt { - ParamsOrderStmt(cornucopia_async::private::Stmt::new( - "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", - )) + pub fn params_order<'a, C: GenericClient>(client: &'a C) -> ParamsOrderStmt<'a, C> { + ParamsOrderStmt( + client, + cornucopia_async::private::Stmt::new( + "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", + ), + ) } - pub struct ParamsOrderStmt(cornucopia_async::private::Stmt); - impl ParamsOrderStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct ParamsOrderStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> ParamsOrderStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, c: &'a i32, a: &'a i32, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[c, a]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[c, a]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -3836,12 +3929,10 @@ pub mod queries { + 'a, >, >, - C, - > for ParamsOrderStmt + > for ParamsOrderStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::ParamsOrderParams, ) -> std::pin::Pin< Box< @@ -3850,7 +3941,7 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(client, ¶ms.c, ¶ms.a)) + Box::pin(self.bind(¶ms.c, ¶ms.a)) } } } @@ -4808,24 +4899,29 @@ pub mod queries { Ok(it) } } - pub fn select_everything() -> SelectEverythingStmt { - SelectEverythingStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_everything<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectEverythingStmt<'a, C> { + SelectEverythingStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM Everything", - )) + ), + ) } - pub struct SelectEverythingStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> EverythingQuery<'a, C, super::Everything, 0> { + pub struct SelectEverythingStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingStmt<'a, C> { + pub fn bind(&'a mut self) -> EverythingQuery<'a, C, super::Everything, 0> { EverythingQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -4866,24 +4962,29 @@ FROM } } } - pub fn select_everything_null() -> SelectEverythingNullStmt { - SelectEverythingNullStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_everything_null<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectEverythingNullStmt<'a, C> { + SelectEverythingNullStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM Everything", - )) + ), + ) } - pub struct SelectEverythingNullStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { + pub struct SelectEverythingNullStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingNullStmt<'a, C> { + pub fn bind(&'a mut self) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { EverythingNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -4924,15 +5025,18 @@ FROM } } } - pub fn insert_everything() -> InsertEverythingStmt { - InsertEverythingStmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + pub fn insert_everything<'a, C: GenericClient>( + client: &'a mut C, + ) -> InsertEverythingStmt<'a, C> { + InsertEverythingStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)")) } - pub struct InsertEverythingStmt(cornucopia_sync::private::Stmt); - impl InsertEverythingStmt { + pub struct InsertEverythingStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertEverythingStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::StringSql, T3: cornucopia_sync::BytesSql, @@ -4940,7 +5044,6 @@ FROM T5: cornucopia_sync::JsonSql, >( &'a mut self, - client: &'a mut C, bool_: &'a bool, boolean_: &'a bool, char_: &'a i8, @@ -4976,8 +5079,8 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( + let stmt = self.1.prepare(self.0)?; + self.0.execute( stmt, &[ bool_, @@ -5031,16 +5134,13 @@ FROM 'a, super::EverythingParams, Result, - C, - > for InsertEverythingStmt + > for InsertEverythingStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::EverythingParams, ) -> Result { self.bind( - client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -5078,24 +5178,31 @@ FROM ) } } - pub fn select_everything_array() -> SelectEverythingArrayStmt { - SelectEverythingArrayStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_everything_array<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectEverythingArrayStmt<'a, C> { + SelectEverythingArrayStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM EverythingArray", - )) + ), + ) } - pub struct SelectEverythingArrayStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingArrayStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectEverythingArrayStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingArrayStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { EverythingArrayQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5130,25 +5237,32 @@ FROM } } } - pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { - SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_everything_array_null<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectEverythingArrayNullStmt<'a, C> { + SelectEverythingArrayNullStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM EverythingArray", - )) + ), + ) } - pub struct SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingArrayNullStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectEverythingArrayNullStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingArrayNullStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> { EverythingArrayNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5183,15 +5297,18 @@ FROM } } } - pub fn insert_everything_array() -> InsertEverythingArrayStmt { - InsertEverythingArrayStmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + pub fn insert_everything_array<'a, C: GenericClient>( + client: &'a mut C, + ) -> InsertEverythingArrayStmt<'a, C> { + InsertEverythingArrayStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)")) } - pub struct InsertEverythingArrayStmt(cornucopia_sync::private::Stmt); - impl InsertEverythingArrayStmt { + pub struct InsertEverythingArrayStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertEverythingArrayStmt<'a, C> { pub fn bind< - 'a, - C: GenericClient, T1: cornucopia_sync::ArraySql, T2: cornucopia_sync::ArraySql, T3: cornucopia_sync::ArraySql, @@ -5227,7 +5344,6 @@ FROM T33: cornucopia_sync::ArraySql, >( &'a mut self, - client: &'a mut C, bool_: &'a T1, boolean_: &'a T2, char_: &'a T3, @@ -5257,8 +5373,8 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( + let stmt = self.1.prepare(self.0)?; + self.0.execute( stmt, &[ bool_, @@ -5368,12 +5484,10 @@ FROM T33, >, Result, - C, - > for InsertEverythingArrayStmt + > for InsertEverythingArrayStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::EverythingArrayParams< T1, T2, @@ -5411,7 +5525,6 @@ FROM >, ) -> Result { self.bind( - client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -5443,19 +5556,26 @@ FROM ) } } - pub fn select_nightmare() -> SelectNightmareStmt { - SelectNightmareStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_nightmare<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectNightmareStmt<'a, C> { + SelectNightmareStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM nightmare", - )) + ), + ) } - pub struct SelectNightmareStmt(cornucopia_sync::private::Stmt); - impl SelectNightmareStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> PublicNightmareCompositeQuery< 'a, C, @@ -5463,29 +5583,36 @@ FROM 0, > { PublicNightmareCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_nightmare() -> InsertNightmareStmt { - InsertNightmareStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO nightmare (composite) + pub fn insert_nightmare<'a, C: GenericClient>( + client: &'a mut C, + ) -> InsertNightmareStmt<'a, C> { + InsertNightmareStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO nightmare (composite) VALUES ($1)", - )) + ), + ) } - pub struct InsertNightmareStmt(cornucopia_sync::private::Stmt); - impl InsertNightmareStmt { - pub fn bind<'a, C: GenericClient>( + pub struct InsertNightmareStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> InsertNightmareStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[composite]) } } } @@ -5771,24 +5898,29 @@ FROM Ok(it) } } - pub fn select_everything() -> SelectEverythingStmt { - SelectEverythingStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_everything<'a, C: GenericClient>( + client: &'a C, + ) -> SelectEverythingStmt<'a, C> { + SelectEverythingStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM Everything", - )) + ), + ) } - pub struct SelectEverythingStmt(cornucopia_async::private::Stmt); - impl SelectEverythingStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> EverythingQuery<'a, C, super::Everything, 0> { + pub struct SelectEverythingStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingStmt<'a, C> { + pub fn bind(&'a mut self) -> EverythingQuery<'a, C, super::Everything, 0> { EverythingQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5829,24 +5961,29 @@ FROM } } } - pub fn select_everything_null() -> SelectEverythingNullStmt { - SelectEverythingNullStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_everything_null<'a, C: GenericClient>( + client: &'a C, + ) -> SelectEverythingNullStmt<'a, C> { + SelectEverythingNullStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM Everything", - )) + ), + ) } - pub struct SelectEverythingNullStmt(cornucopia_async::private::Stmt); - impl SelectEverythingNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { + pub struct SelectEverythingNullStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingNullStmt<'a, C> { + pub fn bind(&'a mut self) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { EverythingNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5887,15 +6024,18 @@ FROM } } } - pub fn insert_everything() -> InsertEverythingStmt { - InsertEverythingStmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + pub fn insert_everything<'a, C: GenericClient>( + client: &'a C, + ) -> InsertEverythingStmt<'a, C> { + InsertEverythingStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)")) } - pub struct InsertEverythingStmt(cornucopia_async::private::Stmt); - impl InsertEverythingStmt { + pub struct InsertEverythingStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> InsertEverythingStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, T3: cornucopia_async::BytesSql, @@ -5903,7 +6043,6 @@ FROM T5: cornucopia_async::JsonSql, >( &'a mut self, - client: &'a C, bool_: &'a bool, boolean_: &'a bool, char_: &'a i8, @@ -5939,8 +6078,8 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = self.0.prepare(client).await?; - client + let stmt = self.1.prepare(self.0).await?; + self.0 .execute( stmt, &[ @@ -6002,12 +6141,10 @@ FROM + 'a, >, >, - C, - > for InsertEverythingStmt + > for InsertEverythingStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::EverythingParams, ) -> std::pin::Pin< Box< @@ -6017,7 +6154,6 @@ FROM >, > { Box::pin(self.bind( - client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -6055,24 +6191,31 @@ FROM )) } } - pub fn select_everything_array() -> SelectEverythingArrayStmt { - SelectEverythingArrayStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_everything_array<'a, C: GenericClient>( + client: &'a C, + ) -> SelectEverythingArrayStmt<'a, C> { + SelectEverythingArrayStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM EverythingArray", - )) + ), + ) } - pub struct SelectEverythingArrayStmt(cornucopia_async::private::Stmt); - impl SelectEverythingArrayStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectEverythingArrayStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingArrayStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { EverythingArrayQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6107,25 +6250,32 @@ FROM } } } - pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { - SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_everything_array_null<'a, C: GenericClient>( + client: &'a C, + ) -> SelectEverythingArrayNullStmt<'a, C> { + SelectEverythingArrayNullStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM EverythingArray", - )) + ), + ) } - pub struct SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt); - impl SelectEverythingArrayNullStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectEverythingArrayNullStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectEverythingArrayNullStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> { EverythingArrayNullQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6160,15 +6310,18 @@ FROM } } } - pub fn insert_everything_array() -> InsertEverythingArrayStmt { - InsertEverythingArrayStmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + pub fn insert_everything_array<'a, C: GenericClient>( + client: &'a C, + ) -> InsertEverythingArrayStmt<'a, C> { + InsertEverythingArrayStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)")) } - pub struct InsertEverythingArrayStmt(cornucopia_async::private::Stmt); - impl InsertEverythingArrayStmt { + pub struct InsertEverythingArrayStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> InsertEverythingArrayStmt<'a, C> { pub async fn bind< - 'a, - C: GenericClient, T1: cornucopia_async::ArraySql, T2: cornucopia_async::ArraySql, T3: cornucopia_async::ArraySql, @@ -6204,7 +6357,6 @@ FROM T33: cornucopia_async::ArraySql, >( &'a mut self, - client: &'a C, bool_: &'a T1, boolean_: &'a T2, char_: &'a T3, @@ -6234,8 +6386,8 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = self.0.prepare(client).await?; - client + let stmt = self.1.prepare(self.0).await?; + self.0 .execute( stmt, &[ @@ -6353,12 +6505,10 @@ FROM + 'a, >, >, - C, - > for InsertEverythingArrayStmt + > for InsertEverythingArrayStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::EverythingArrayParams< T1, T2, @@ -6402,7 +6552,6 @@ FROM >, > { Box::pin(self.bind( - client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -6434,19 +6583,26 @@ FROM )) } } - pub fn select_nightmare() -> SelectNightmareStmt { - SelectNightmareStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_nightmare<'a, C: GenericClient>( + client: &'a C, + ) -> SelectNightmareStmt<'a, C> { + SelectNightmareStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM nightmare", - )) + ), + ) } - pub struct SelectNightmareStmt(cornucopia_async::private::Stmt); - impl SelectNightmareStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectNightmareStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectNightmareStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> PublicNightmareCompositeQuery< 'a, C, @@ -6454,29 +6610,36 @@ FROM 0, > { PublicNightmareCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_nightmare() -> InsertNightmareStmt { - InsertNightmareStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO nightmare (composite) + pub fn insert_nightmare<'a, C: GenericClient>( + client: &'a C, + ) -> InsertNightmareStmt<'a, C> { + InsertNightmareStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO nightmare (composite) VALUES ($1)", - )) + ), + ) } - pub struct InsertNightmareStmt(cornucopia_async::private::Stmt); - impl InsertNightmareStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct InsertNightmareStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> InsertNightmareStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[composite]).await } } } @@ -6840,14 +7003,21 @@ FROM Ok(it) } } - pub fn select_compact() -> SelectCompactStmt { - SelectCompactStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) + pub fn select_compact<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectCompactStmt<'a, C> { + SelectCompactStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM clone"), + ) } - pub struct SelectCompactStmt(cornucopia_sync::private::Stmt); - impl SelectCompactStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCompactStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -6855,24 +7025,29 @@ FROM 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(cornucopia_sync::private::Stmt::new( - " SELECT * FROM clone ", - )) + pub fn select_spaced<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectSpacedStmt<'a, C> { + SelectSpacedStmt( + client, + cornucopia_sync::private::Stmt::new(" SELECT * FROM clone "), + ) } - pub struct SelectSpacedStmt(cornucopia_sync::private::Stmt); - impl SelectSpacedStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectSpacedStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -6880,31 +7055,38 @@ FROM 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn implicit_compact() -> ImplicitCompactStmt { - ImplicitCompactStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn implicit_compact<'a, C: GenericClient>( + client: &'a mut C, + ) -> ImplicitCompactStmt<'a, C> { + ImplicitCompactStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct ImplicitCompactStmt(cornucopia_sync::private::Stmt); - impl ImplicitCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct ImplicitCompactStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> ImplicitCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -6915,34 +7097,39 @@ FROM 'a, super::ImplicitCompactParams, Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitCompactStmt + > for ImplicitCompactStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::ImplicitCompactParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn implicit_spaced() -> ImplicitSpacedStmt { - ImplicitSpacedStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn implicit_spaced<'a, C: GenericClient>( + client: &'a mut C, + ) -> ImplicitSpacedStmt<'a, C> { + ImplicitSpacedStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct ImplicitSpacedStmt(cornucopia_sync::private::Stmt); - impl ImplicitSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct ImplicitSpacedStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> ImplicitSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -6953,68 +7140,77 @@ FROM 'a, super::ImplicitSpacedParams, Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitSpacedStmt + > for ImplicitSpacedStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::ImplicitSpacedParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn named_compact() -> NamedCompactStmt { - NamedCompactStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn named_compact<'a, C: GenericClient>( + client: &'a mut C, + ) -> NamedCompactStmt<'a, C> { + NamedCompactStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NamedCompactStmt(cornucopia_sync::private::Stmt); - impl NamedCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct NamedCompactStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NamedCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a T1, price: &'a f64, ) -> RowQuery<'a, C, super::Row, 2> { RowQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>, C> - for NamedCompactStmt + cornucopia_sync::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>> + for NamedCompactStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::Params, ) -> RowQuery<'a, C, super::Row, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn named_spaced() -> NamedSpacedStmt { - NamedSpacedStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn named_spaced<'a, C: GenericClient>(client: &'a mut C) -> NamedSpacedStmt<'a, C> { + NamedSpacedStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NamedSpacedStmt(cornucopia_sync::private::Stmt); - impl NamedSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct NamedSpacedStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> NamedSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, name: &'a T1, price: &'a f64, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { RowSpaceQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -7025,336 +7221,308 @@ FROM 'a, super::ParamsSpace, RowSpaceQuery<'a, C, super::RowSpace, 2>, - C, - > for NamedSpacedStmt + > for NamedSpacedStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::ParamsSpace, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn tricky_sql() -> TrickySqlStmt { - TrickySqlStmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) + pub fn tricky_sql<'a, C: GenericClient>(client: &'a mut C) -> TrickySqlStmt<'a, C> { + TrickySqlStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) } - pub struct TrickySqlStmt(cornucopia_sync::private::Stmt); - impl TrickySqlStmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySqlStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySqlStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySqlParams, Result, C> - for TrickySqlStmt + cornucopia_sync::Params<'a, super::TrickySqlParams, Result> + for TrickySqlStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySqlParams, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql1() -> TrickySql1Stmt { - TrickySql1Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) + pub fn tricky_sql1<'a, C: GenericClient>(client: &'a mut C) -> TrickySql1Stmt<'a, C> { + TrickySql1Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) } - pub struct TrickySql1Stmt(cornucopia_sync::private::Stmt); - impl TrickySql1Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql1Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql1Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql1Params, - Result, - C, - > for TrickySql1Stmt + cornucopia_sync::Params<'a, super::TrickySql1Params, Result> + for TrickySql1Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql1Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql2() -> TrickySql2Stmt { - TrickySql2Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql2<'a, C: GenericClient>(client: &'a mut C) -> TrickySql2Stmt<'a, C> { + TrickySql2Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) } - pub struct TrickySql2Stmt(cornucopia_sync::private::Stmt); - impl TrickySql2Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql2Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql2Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql2Params, - Result, - C, - > for TrickySql2Stmt + cornucopia_sync::Params<'a, super::TrickySql2Params, Result> + for TrickySql2Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql2Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql3() -> TrickySql3Stmt { - TrickySql3Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) + pub fn tricky_sql3<'a, C: GenericClient>(client: &'a mut C) -> TrickySql3Stmt<'a, C> { + TrickySql3Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) } - pub struct TrickySql3Stmt(cornucopia_sync::private::Stmt); - impl TrickySql3Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql3Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql3Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql3Params, - Result, - C, - > for TrickySql3Stmt + cornucopia_sync::Params<'a, super::TrickySql3Params, Result> + for TrickySql3Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql3Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql4() -> TrickySql4Stmt { - TrickySql4Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) + pub fn tricky_sql4<'a, C: GenericClient>(client: &'a mut C) -> TrickySql4Stmt<'a, C> { + TrickySql4Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) } - pub struct TrickySql4Stmt(cornucopia_sync::private::Stmt); - impl TrickySql4Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql4Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql4Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql4Params, - Result, - C, - > for TrickySql4Stmt + cornucopia_sync::Params<'a, super::TrickySql4Params, Result> + for TrickySql4Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql4Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql6() -> TrickySql6Stmt { - TrickySql6Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql6<'a, C: GenericClient>(client: &'a mut C) -> TrickySql6Stmt<'a, C> { + TrickySql6Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) } - pub struct TrickySql6Stmt(cornucopia_sync::private::Stmt); - impl TrickySql6Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql6Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql6Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql6Params, - Result, - C, - > for TrickySql6Stmt + cornucopia_sync::Params<'a, super::TrickySql6Params, Result> + for TrickySql6Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql6Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql7() -> TrickySql7Stmt { - TrickySql7Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) + pub fn tricky_sql7<'a, C: GenericClient>(client: &'a mut C) -> TrickySql7Stmt<'a, C> { + TrickySql7Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) } - pub struct TrickySql7Stmt(cornucopia_sync::private::Stmt); - impl TrickySql7Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql7Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql7Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql7Params, - Result, - C, - > for TrickySql7Stmt + cornucopia_sync::Params<'a, super::TrickySql7Params, Result> + for TrickySql7Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql7Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql8() -> TrickySql8Stmt { - TrickySql8Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql8<'a, C: GenericClient>(client: &'a mut C) -> TrickySql8Stmt<'a, C> { + TrickySql8Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) } - pub struct TrickySql8Stmt(cornucopia_sync::private::Stmt); - impl TrickySql8Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql8Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql8Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql8Params, - Result, - C, - > for TrickySql8Stmt + cornucopia_sync::Params<'a, super::TrickySql8Params, Result> + for TrickySql8Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql8Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql9() -> TrickySql9Stmt { - TrickySql9Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql9<'a, C: GenericClient>(client: &'a mut C) -> TrickySql9Stmt<'a, C> { + TrickySql9Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) } - pub struct TrickySql9Stmt(cornucopia_sync::private::Stmt); - impl TrickySql9Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql9Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql9Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql9Params, - Result, - C, - > for TrickySql9Stmt + cornucopia_sync::Params<'a, super::TrickySql9Params, Result> + for TrickySql9Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql9Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql10() -> TrickySql10Stmt { - TrickySql10Stmt(cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) + pub fn tricky_sql10<'a, C: GenericClient>(client: &'a mut C) -> TrickySql10Stmt<'a, C> { + TrickySql10Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) } - pub struct TrickySql10Stmt(cornucopia_sync::private::Stmt); - impl TrickySql10Stmt { - pub fn bind<'a, C: GenericClient>( + pub struct TrickySql10Stmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql10Stmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params< - 'a, - super::TrickySql10Params, - Result, - C, - > for TrickySql10Stmt + cornucopia_sync::Params<'a, super::TrickySql10Params, Result> + for TrickySql10Stmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a super::TrickySql10Params, ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) + self.bind(¶ms.r#async, ¶ms.r#enum) } } - pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM syntax")) + pub fn r#typeof<'a, C: GenericClient>(client: &'a mut C) -> RTypeofStmt<'a, C> { + RTypeofStmt( + client, + cornucopia_sync::private::Stmt::new("SELECT * FROM syntax"), + ) } - pub struct RTypeofStmt(cornucopia_sync::private::Stmt); - impl RTypeofStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> TypeofQuery<'a, C, super::Typeof, 0> { + pub struct RTypeofStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> RTypeofStmt<'a, C> { + pub fn bind(&'a mut self) -> TypeofQuery<'a, C, super::Typeof, 0> { TypeofQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), @@ -7641,14 +7809,19 @@ FROM Ok(it) } } - pub fn select_compact() -> SelectCompactStmt { - SelectCompactStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) + pub fn select_compact<'a, C: GenericClient>(client: &'a C) -> SelectCompactStmt<'a, C> { + SelectCompactStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM clone"), + ) } - pub struct SelectCompactStmt(cornucopia_async::private::Stmt); - impl SelectCompactStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectCompactStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7656,24 +7829,27 @@ FROM 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(cornucopia_async::private::Stmt::new( - " SELECT * FROM clone ", - )) + pub fn select_spaced<'a, C: GenericClient>(client: &'a C) -> SelectSpacedStmt<'a, C> { + SelectSpacedStmt( + client, + cornucopia_async::private::Stmt::new(" SELECT * FROM clone "), + ) } - pub struct SelectSpacedStmt(cornucopia_async::private::Stmt); - impl SelectSpacedStmt { - pub fn bind<'a, C: GenericClient>( + pub struct SelectSpacedStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7681,31 +7857,38 @@ FROM 0, > { PublicCloneCompositeQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn implicit_compact() -> ImplicitCompactStmt { - ImplicitCompactStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn implicit_compact<'a, C: GenericClient>( + client: &'a C, + ) -> ImplicitCompactStmt<'a, C> { + ImplicitCompactStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct ImplicitCompactStmt(cornucopia_async::private::Stmt); - impl ImplicitCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct ImplicitCompactStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> ImplicitCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -7716,34 +7899,39 @@ FROM 'a, super::ImplicitCompactParams, Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitCompactStmt + > for ImplicitCompactStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::ImplicitCompactParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn implicit_spaced() -> ImplicitSpacedStmt { - ImplicitSpacedStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn implicit_spaced<'a, C: GenericClient>( + client: &'a C, + ) -> ImplicitSpacedStmt<'a, C> { + ImplicitSpacedStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct ImplicitSpacedStmt(cornucopia_async::private::Stmt); - impl ImplicitSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct ImplicitSpacedStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> ImplicitSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it, } @@ -7754,68 +7942,75 @@ FROM 'a, super::ImplicitSpacedParams, Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitSpacedStmt + > for ImplicitSpacedStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::ImplicitSpacedParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn named_compact() -> NamedCompactStmt { - NamedCompactStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn named_compact<'a, C: GenericClient>(client: &'a C) -> NamedCompactStmt<'a, C> { + NamedCompactStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NamedCompactStmt(cornucopia_async::private::Stmt); - impl NamedCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct NamedCompactStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NamedCompactStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, name: &'a T1, price: &'a f64, ) -> RowQuery<'a, C, super::Row, 2> { RowQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>, C> - for NamedCompactStmt + cornucopia_async::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>> + for NamedCompactStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::Params, ) -> RowQuery<'a, C, super::Row, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn named_spaced() -> NamedSpacedStmt { - NamedSpacedStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - )) + pub fn named_spaced<'a, C: GenericClient>(client: &'a C) -> NamedSpacedStmt<'a, C> { + NamedSpacedStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + ), + ) } - pub struct NamedSpacedStmt(cornucopia_async::private::Stmt); - impl NamedSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct NamedSpacedStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> NamedSpacedStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, name: &'a T1, price: &'a f64, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { RowSpaceQuery { - client, + client: self.0, params: [name, price], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -7826,30 +8021,27 @@ FROM 'a, super::ParamsSpace, RowSpaceQuery<'a, C, super::RowSpace, 2>, - C, - > for NamedSpacedStmt + > for NamedSpacedStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::ParamsSpace, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { - self.bind(client, ¶ms.name, ¶ms.price) + self.bind(¶ms.name, ¶ms.price) } } - pub fn tricky_sql() -> TrickySqlStmt { - TrickySqlStmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) + pub fn tricky_sql<'a, C: GenericClient>(client: &'a C) -> TrickySqlStmt<'a, C> { + TrickySqlStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) } - pub struct TrickySqlStmt(cornucopia_async::private::Stmt); - impl TrickySqlStmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySqlStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySqlStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7863,12 +8055,10 @@ FROM + 'a, >, >, - C, - > for TrickySqlStmt + > for TrickySqlStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySqlParams, ) -> std::pin::Pin< Box< @@ -7877,22 +8067,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql1() -> TrickySql1Stmt { - TrickySql1Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) + pub fn tricky_sql1<'a, C: GenericClient>(client: &'a C) -> TrickySql1Stmt<'a, C> { + TrickySql1Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) } - pub struct TrickySql1Stmt(cornucopia_async::private::Stmt); - impl TrickySql1Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql1Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql1Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7906,12 +8095,10 @@ FROM + 'a, >, >, - C, - > for TrickySql1Stmt + > for TrickySql1Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql1Params, ) -> std::pin::Pin< Box< @@ -7920,22 +8107,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql2() -> TrickySql2Stmt { - TrickySql2Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql2<'a, C: GenericClient>(client: &'a C) -> TrickySql2Stmt<'a, C> { + TrickySql2Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) } - pub struct TrickySql2Stmt(cornucopia_async::private::Stmt); - impl TrickySql2Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql2Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql2Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7949,12 +8135,10 @@ FROM + 'a, >, >, - C, - > for TrickySql2Stmt + > for TrickySql2Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql2Params, ) -> std::pin::Pin< Box< @@ -7963,22 +8147,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql3() -> TrickySql3Stmt { - TrickySql3Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) + pub fn tricky_sql3<'a, C: GenericClient>(client: &'a C) -> TrickySql3Stmt<'a, C> { + TrickySql3Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) } - pub struct TrickySql3Stmt(cornucopia_async::private::Stmt); - impl TrickySql3Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql3Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql3Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7992,12 +8175,10 @@ FROM + 'a, >, >, - C, - > for TrickySql3Stmt + > for TrickySql3Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql3Params, ) -> std::pin::Pin< Box< @@ -8006,22 +8187,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql4() -> TrickySql4Stmt { - TrickySql4Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) + pub fn tricky_sql4<'a, C: GenericClient>(client: &'a C) -> TrickySql4Stmt<'a, C> { + TrickySql4Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) } - pub struct TrickySql4Stmt(cornucopia_async::private::Stmt); - impl TrickySql4Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql4Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql4Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8035,12 +8215,10 @@ FROM + 'a, >, >, - C, - > for TrickySql4Stmt + > for TrickySql4Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql4Params, ) -> std::pin::Pin< Box< @@ -8049,22 +8227,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql6() -> TrickySql6Stmt { - TrickySql6Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql6<'a, C: GenericClient>(client: &'a C) -> TrickySql6Stmt<'a, C> { + TrickySql6Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) } - pub struct TrickySql6Stmt(cornucopia_async::private::Stmt); - impl TrickySql6Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql6Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql6Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8078,12 +8255,10 @@ FROM + 'a, >, >, - C, - > for TrickySql6Stmt + > for TrickySql6Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql6Params, ) -> std::pin::Pin< Box< @@ -8092,22 +8267,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql7() -> TrickySql7Stmt { - TrickySql7Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) + pub fn tricky_sql7<'a, C: GenericClient>(client: &'a C) -> TrickySql7Stmt<'a, C> { + TrickySql7Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) } - pub struct TrickySql7Stmt(cornucopia_async::private::Stmt); - impl TrickySql7Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql7Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql7Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8121,12 +8295,10 @@ FROM + 'a, >, >, - C, - > for TrickySql7Stmt + > for TrickySql7Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql7Params, ) -> std::pin::Pin< Box< @@ -8135,22 +8307,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql8() -> TrickySql8Stmt { - TrickySql8Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql8<'a, C: GenericClient>(client: &'a C) -> TrickySql8Stmt<'a, C> { + TrickySql8Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) } - pub struct TrickySql8Stmt(cornucopia_async::private::Stmt); - impl TrickySql8Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql8Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql8Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8164,12 +8335,10 @@ FROM + 'a, >, >, - C, - > for TrickySql8Stmt + > for TrickySql8Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql8Params, ) -> std::pin::Pin< Box< @@ -8178,22 +8347,21 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql9() -> TrickySql9Stmt { - TrickySql9Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql9<'a, C: GenericClient>(client: &'a C) -> TrickySql9Stmt<'a, C> { + TrickySql9Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) } - pub struct TrickySql9Stmt(cornucopia_async::private::Stmt); - impl TrickySql9Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql9Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> TrickySql9Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8207,12 +8375,10 @@ FROM + 'a, >, >, - C, - > for TrickySql9Stmt + > for TrickySql9Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql9Params, ) -> std::pin::Pin< Box< @@ -8221,22 +8387,24 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql10() -> TrickySql10Stmt { - TrickySql10Stmt(cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) + pub fn tricky_sql10<'a, C: GenericClient>(client: &'a C) -> TrickySql10Stmt<'a, C> { + TrickySql10Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) } - pub struct TrickySql10Stmt(cornucopia_async::private::Stmt); - impl TrickySql10Stmt { - pub async fn bind<'a, C: GenericClient>( + pub struct TrickySql10Stmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> TrickySql10Stmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8250,12 +8418,10 @@ FROM + 'a, >, >, - C, - > for TrickySql10Stmt + > for TrickySql10Stmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a super::TrickySql10Params, ) -> std::pin::Pin< Box< @@ -8264,22 +8430,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) } } - pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt(cornucopia_async::private::Stmt::new("SELECT * FROM syntax")) + pub fn r#typeof<'a, C: GenericClient>(client: &'a C) -> RTypeofStmt<'a, C> { + RTypeofStmt( + client, + cornucopia_async::private::Stmt::new("SELECT * FROM syntax"), + ) } - pub struct RTypeofStmt(cornucopia_async::private::Stmt); - impl RTypeofStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> TypeofQuery<'a, C, super::Typeof, 0> { + pub struct RTypeofStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> RTypeofStmt<'a, C> { + pub fn bind(&'a mut self) -> TypeofQuery<'a, C, super::Typeof, 0> { TypeofQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), diff --git a/codegen_test/src/main.rs b/codegen_test/src/main.rs index 8e5d3e5f..e1e0dcb1 100644 --- a/codegen_test/src/main.rs +++ b/codegen_test/src/main.rs @@ -80,18 +80,18 @@ pub fn moving(_item: T) {} pub fn test_params(client: &mut Client) { assert_eq!( 1, - insert_book() - .bind(client, &None::<&str>, &"Necronomicon") + insert_book(client) + .bind(&None::<&str>, &"Necronomicon") .unwrap() ); assert_eq!( 1, - insert_book() - .bind(client, &Some("Marcel Proust"), &"In Search of Lost Time") + insert_book(client) + .bind(&Some("Marcel Proust"), &"In Search of Lost Time") .unwrap() ); assert_eq!( - select_book().bind(client).all().unwrap(), + select_book(client).bind().all().unwrap(), &[ SelectBook { author: None, @@ -103,66 +103,61 @@ pub fn test_params(client: &mut Client) { } ] ); - params_use_twice().bind(client, &"name").unwrap(); + params_use_twice(client).bind(&"name").unwrap(); } pub fn test_trait_sql(client: &mut Client) { let str = "hello world"; - insert_book().bind(client, &Some(str), &str).unwrap(); - find_books().bind(client, &[str].as_slice()).all().unwrap(); + insert_book(client).bind(&Some(str), &str).unwrap(); + find_books(client).bind(&[str].as_slice()).all().unwrap(); let string = str.to_string(); - insert_book() - .bind(client, &Some(string.clone()), &string) + insert_book(client) + .bind(&Some(string.clone()), &string) .unwrap(); - find_books() - .bind(client, &vec![string.clone()]) + find_books(client) + .bind(&vec![string.clone()]) .all() .unwrap(); - let boxed = string.clone().into_boxed_str(); - insert_book() - .bind(client, &Some(boxed.clone()), &boxed) + let boxed = string.into_boxed_str(); + insert_book(client) + .bind(&Some(boxed.clone()), &boxed) .unwrap(); - find_books().bind(client, &vec![boxed]).all().unwrap(); + find_books(client).bind(&vec![boxed]).all().unwrap(); let cow = Cow::Borrowed(str); - insert_book() - .bind(client, &Some(cow.clone()), &cow) - .unwrap(); - find_books().bind(client, &vec![cow]).all().unwrap(); + insert_book(client).bind(&Some(cow.clone()), &cow).unwrap(); + find_books(client).bind(&vec![cow]).all().unwrap(); let map: HashMap<&str, &str> = HashMap::from_iter([("one", "1"), ("two", "2"), ("three", "3")].into_iter()); // Old way with allocation let vec: Vec<_> = map.values().collect(); - find_books().bind(client, &vec.as_slice()).all().unwrap(); + find_books(client).bind(&vec.as_slice()).all().unwrap(); // A little more ergonomic - find_books().bind(client, &vec).all().unwrap(); + find_books(client).bind(&vec).all().unwrap(); // Zero allocation - find_books() - .bind(client, &IterSql(|| map.values())) + find_books(client) + .bind(&IterSql(|| map.values())) .all() .unwrap(); } pub fn test_nullity(client: &mut Client) { - new_nullity() - .params( - client, - &NullityParams { - composite: Some(NullityCompositeParams { - jsons: Some(&[None]), - id: 42, - }), - name: "James Bond", - texts: [Some("Hello"), Some("world"), None].as_slice(), - }, - ) + new_nullity(client) + .params(&NullityParams { + composite: Some(NullityCompositeParams { + jsons: Some(&[None]), + id: 42, + }), + name: "James Bond", + texts: [Some("Hello"), Some("world"), None].as_slice(), + }) .unwrap(); assert_eq!( - nullity().bind(client).one().unwrap(), + nullity(client).bind().one().unwrap(), Nullity { composite: Some(NullityComposite { jsons: Some(vec![None]), @@ -175,35 +170,29 @@ pub fn test_nullity(client: &mut Client) { } pub fn test_named(client: &mut Client) { - let hidden_id = new_named_hidden() - .params( - client, - &NamedParams { - name: "secret", - price: Some(42.0), - }, - ) + let hidden_id = new_named_hidden(client) + .params(&NamedParams { + name: "secret", + price: Some(42.0), + }) .one() .unwrap() .id; - let visible_id = new_named_visible() - .params( - client, - &NamedParams { - name: "stuff", - price: Some(84.0), - }, - ) + let visible_id = new_named_visible(client) + .params(&NamedParams { + name: "stuff", + price: Some(84.0), + }) .one() .unwrap() .id; - let last_id = new_named_visible() - .bind(client, &"can't by me", &None) + let last_id = new_named_visible(client) + .bind(&"can't by me", &None) .one() .unwrap() .id; assert_eq!( - named().bind(client).all().unwrap(), + named(client).bind().all().unwrap(), &[ Named { id: hidden_id, @@ -226,7 +215,7 @@ pub fn test_named(client: &mut Client) { ] ); assert_eq!( - named_by_id().bind(client, &hidden_id).one().unwrap(), + named_by_id(client).bind(&hidden_id).one().unwrap(), Named { id: hidden_id, name: "secret".into(), @@ -235,7 +224,7 @@ pub fn test_named(client: &mut Client) { } ); assert_eq!( - named_by_id().bind(client, &visible_id).one().unwrap(), + named_by_id(client).bind(&visible_id).one().unwrap(), Named { id: visible_id, name: "stuff".into(), @@ -244,40 +233,34 @@ pub fn test_named(client: &mut Client) { } ); assert_eq!( - named().bind(client).map(|it| it.id).all().unwrap(), + named(client).bind().map(|it| it.id).all().unwrap(), &[hidden_id, visible_id, last_id] ); - new_named_complex() - .params( - client, - &NamedComplexParams { - named: NamedCompositeBorrowed { - wow: Some("Hello world"), - such_cool: None, - }, - named_with_dot: Some(NamedCompositeWithDot { - this_is_inconceivable: Some(EnumWithDot::variant_with_dot), - }), + new_named_complex(client) + .params(&NamedComplexParams { + named: NamedCompositeBorrowed { + wow: Some("Hello world"), + such_cool: None, }, - ) + named_with_dot: Some(NamedCompositeWithDot { + this_is_inconceivable: Some(EnumWithDot::variant_with_dot), + }), + }) .unwrap(); - new_named_complex() - .params( - client, - &NamedComplexParams { - named: NamedCompositeBorrowed { - wow: Some("Hello world, again"), - such_cool: None, - }, - named_with_dot: None, + new_named_complex(client) + .params(&NamedComplexParams { + named: NamedCompositeBorrowed { + wow: Some("Hello world, again"), + such_cool: None, }, - ) + named_with_dot: None, + }) .unwrap(); assert_eq!( - named_complex().bind(client).all().unwrap(), + named_complex(client).bind().all().unwrap(), vec![ NamedComplex { named: NamedComposite { @@ -307,8 +290,8 @@ pub fn test_copy(client: &mut Client) { second: 4.2, }; moving(copy_params); // Ignore if copied - insert_copy().bind(client, ©_params).unwrap(); - let copy_row = select_copy().bind(client).one().unwrap(); + insert_copy(client).bind(©_params).unwrap(); + let copy_row = select_copy(client).bind().one().unwrap(); moving(copy_row); // Ignore if copied moving(copy_row); @@ -317,8 +300,8 @@ pub fn test_copy(client: &mut Client) { first: 42, second: "Hello world", }; - insert_clone().bind(client, &clone_params).unwrap(); - select_copy().bind(client).one().unwrap(); + insert_clone(client).bind(&clone_params).unwrap(); + select_copy(client).bind().one().unwrap(); } // Test domain erasing @@ -345,11 +328,8 @@ pub fn test_domain(client: &mut Client) { nb: 42, txt: "Hello world".to_string(), }; - assert_eq!( - 1, - insert_nightmare_domain().params(client, ¶ms).unwrap() - ); - let actual = select_nightmare_domain().bind(client).one().unwrap(); + assert_eq!(1, insert_nightmare_domain(client).params(¶ms).unwrap()); + let actual = select_nightmare_domain(client).bind().one().unwrap(); assert_eq!(expected, actual); let expected = SelectNightmareDomainNull { arr: Some(vec![Some(json.clone())]), @@ -363,7 +343,7 @@ pub fn test_domain(client: &mut Client) { txt: "Hello world".to_string(), }), }; - let actual = select_nightmare_domain_null().bind(client).one().unwrap(); + let actual = select_nightmare_domain_null(client).bind().one().unwrap(); assert_eq!(expected, actual); } @@ -453,8 +433,8 @@ pub fn test_stress(client: &mut Client) { varchar_: &expected.varchar_, numeric_: Decimal::new(202, 2), }; - assert_eq!(1, insert_everything().params(client, ¶ms).unwrap()); - let actual = select_everything().bind(client).one().unwrap(); + assert_eq!(1, insert_everything(client).params(¶ms).unwrap()); + let actual = select_everything(client).bind().one().unwrap(); assert_eq!(expected, actual); // Every supported array type @@ -530,11 +510,8 @@ pub fn test_stress(client: &mut Client) { varchar_: txt, numeric_: &expected.numeric_, }; - assert_eq!( - 1, - insert_everything_array().params(client, ¶ms).unwrap() - ); - let actual = select_everything_array().bind(client).one().unwrap(); + assert_eq!(1, insert_everything_array(client).params(¶ms).unwrap()); + let actual = select_everything_array(client).bind().one().unwrap(); assert_eq!(expected, actual); // Complex mix of enum, domain and composite types @@ -557,8 +534,8 @@ pub fn test_stress(client: &mut Client) { domain: "Hello", }; - assert_eq!(1, insert_nightmare().bind(client, ¶ms).unwrap()); - let actual = select_nightmare().bind(client).one().unwrap(); + assert_eq!(1, insert_nightmare(client).bind(¶ms).unwrap()); + let actual = select_nightmare(client).bind().one().unwrap(); assert_eq!(expected, actual); } @@ -568,6 +545,6 @@ pub fn test_keyword_escaping(client: &mut Client) { r#async: SyntaxComposite { r#async: 34 }, r#enum: SyntaxEnum::r#box, }; - tricky_sql10().params(client, ¶ms).unwrap(); - r#typeof().bind(client).all().unwrap(); + tricky_sql10(client).params(¶ms).unwrap(); + r#typeof(client).bind().all().unwrap(); } diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index af6c4b8a..9210ff4b 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -547,11 +547,11 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu ) }; code!(w => - pub fn bind<'a, C: GenericClient,$($traits_idx: $traits,)>(&'a mut self, client: &'a $client_mut C, $($params_name: &'a $params_ty,) ) -> ${row_name}Query<'a,C, $row_struct_name, $nb_params> { + pub fn bind<$($traits_idx: $traits,)>(&'a mut self, $($params_name: &'a $params_ty,) ) -> ${row_name}Query<'a,C, $row_struct_name, $nb_params> { ${row_name}Query { - client, + client: self.0, params: [$($params_name,)], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| { $!extractor }, mapper: |it| { $mapper }, } @@ -564,9 +564,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu p.ty.sql_wrapped(&p.ident.rs, ctx) }); code!(w => - pub $fn_async fn bind<'a, C: GenericClient,$($traits_idx: $traits,)>(&'a mut self, client: &'a $client_mut C, $($params_name: &'a $params_ty,)) -> Result { - let stmt = self.0.prepare(client)$fn_await?; - client.execute(stmt, &[ $($params_wrap,) ])$fn_await + pub $fn_async fn bind<$($traits_idx: $traits,)>(&'a mut self, $($params_name: &'a $params_ty,)) -> Result { + let stmt = self.1.prepare(self.0)$fn_await?; + self.0.execute(stmt, &[ $($params_wrap,) ])$fn_await } ); } @@ -576,11 +576,11 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu let sql = sql.replace('"', "\\\""); // Rust string format escaping let name = &ident.rs; code!(w => - pub fn $name() -> ${struct_name}Stmt { - ${struct_name}Stmt($client::private::Stmt::new("$sql")) + pub fn $name<'a, C: GenericClient>(client: &'a$client_mut C) -> ${struct_name}Stmt<'a, C> { + ${struct_name}Stmt(client, $client::private::Stmt::new("$sql")) } - pub struct ${struct_name}Stmt($client::private::Stmt); - impl ${struct_name}Stmt { + pub struct ${struct_name}Stmt<'a, C: GenericClient>(&'a$client_mut C, $client::private::Stmt); + impl <'a, C: GenericClient> ${struct_name}Stmt<'a, C> { $!lazy_impl } ); @@ -605,9 +605,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu let name = &module.rows.get_index(*idx).unwrap().1.name; let nb_params = param_field.len(); code!(w => - impl <'a, C: GenericClient,$($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, ${name}Query<'a, C, $query_row_struct, $nb_params>, C> for ${struct_name}Stmt { - fn params(&'a mut self, client: &'a $client_mut C, params: &'a $param_path<$lifetime $($traits_idx,)>) -> ${name}Query<'a, C, $query_row_struct, $nb_params> { - self.bind(client, $(¶ms.$params_name,)) + impl <'a, C: GenericClient,$($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, ${name}Query<'a, C, $query_row_struct, $nb_params>> for ${struct_name}Stmt<'a, C> { + fn params(&'a mut self, params: &'a $param_path<$lifetime $($traits_idx,)>) -> ${name}Query<'a, C, $query_row_struct, $nb_params> { + self.bind($(¶ms.$params_name,)) } } ); @@ -624,9 +624,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu ("", "Result", "", "self", "") }; code!(w => - impl <'a, C: GenericClient $send_sync, $($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, $pre_ty$post_ty_lf, C> for ${struct_name}Stmt { - fn params(&'a mut self, client: &'a $client_mut C, params: &'a $param_path<$lifetime $($traits_idx,)>) -> $pre_ty$post_ty_lf { - $pre.bind(client, $(¶ms.$params_name,))$post + impl <'a, C: GenericClient $send_sync, $($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, $pre_ty$post_ty_lf> for ${struct_name}Stmt<'a, C> { + fn params(&'a mut self, params: &'a $param_path<$lifetime $($traits_idx,)>) -> $pre_ty$post_ty_lf { + $pre.bind($(¶ms.$params_name,))$post } } ); diff --git a/examples/auto_build/src/cornucopia.rs b/examples/auto_build/src/cornucopia.rs index 7645821c..d1aaf27b 100644 --- a/examples/auto_build/src/cornucopia.rs +++ b/examples/auto_build/src/cornucopia.rs @@ -66,24 +66,24 @@ pub mod queries { Ok(it) } } - pub fn example_query() -> ExampleQueryStmt { - ExampleQueryStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn example_query<'a, C: GenericClient>(client: &'a C) -> ExampleQueryStmt<'a, C> { + ExampleQueryStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM example_table", - )) + ), + ) } - pub struct ExampleQueryStmt(cornucopia_async::private::Stmt); - impl ExampleQueryStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> StringQuery<'a, C, String, 0> { + pub struct ExampleQueryStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> ExampleQueryStmt<'a, C> { + pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { StringQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } diff --git a/examples/auto_build/src/main.rs b/examples/auto_build/src/main.rs index ae6e8ff4..5372820c 100644 --- a/examples/auto_build/src/main.rs +++ b/examples/auto_build/src/main.rs @@ -25,5 +25,5 @@ async fn main() { cfg.dbname = Some(String::from("postgres")); let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls).unwrap(); let client = pool.get().await.unwrap(); - example_query().bind(&client).all().await.unwrap(); + example_query(&client).bind().all().await.unwrap(); } diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index 36941dc5..dcd50a2d 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -212,21 +212,23 @@ pub mod queries { use cornucopia_async::GenericClient; use futures; use futures::{StreamExt, TryStreamExt}; - pub fn insert_book() -> InsertBookStmt { - InsertBookStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO Book (title) + pub fn insert_book<'a, C: GenericClient>(client: &'a C) -> InsertBookStmt<'a, C> { + InsertBookStmt( + client, + cornucopia_async::private::Stmt::new( + "INSERT INTO Book (title) VALUES ($1)", - )) + ), + ) } - pub struct InsertBookStmt(cornucopia_async::private::Stmt); - impl InsertBookStmt { - pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + pub struct InsertBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> InsertBookStmt<'a, C> { + pub async fn bind( &'a mut self, - client: &'a C, title: &'a T1, ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[title]).await + let stmt = self.1.prepare(self.0).await?; + self.0.execute(stmt, &[title]).await } } } @@ -579,24 +581,24 @@ pub mod queries { Ok(it) } } - pub fn authors() -> AuthorsStmt { - AuthorsStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn authors<'a, C: GenericClient>(client: &'a C) -> AuthorsStmt<'a, C> { + AuthorsStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT * FROM Author", - )) + ), + ) } - pub struct AuthorsStmt(cornucopia_async::private::Stmt); - impl AuthorsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> AuthorsQuery<'a, C, Authors, 0> { + pub struct AuthorsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> AuthorsStmt<'a, C> { + pub fn bind(&'a mut self) -> AuthorsQuery<'a, C, Authors, 0> { AuthorsQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -606,58 +608,61 @@ FROM } } } - pub fn books() -> BooksStmt { - BooksStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn books<'a, C: GenericClient>(client: &'a C) -> BooksStmt<'a, C> { + BooksStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT Title FROM Book", - )) + ), + ) } - pub struct BooksStmt(cornucopia_async::private::Stmt); - impl BooksStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> StringQuery<'a, C, String, 0> { + pub struct BooksStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> BooksStmt<'a, C> { + pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { StringQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_by_id() -> AuthorNameByIdStmt { - AuthorNameByIdStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn author_name_by_id<'a, C: GenericClient>(client: &'a C) -> AuthorNameByIdStmt<'a, C> { + AuthorNameByIdStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT Author.Name FROM Author WHERE Author.Id = $1", - )) + ), + ) } - pub struct AuthorNameByIdStmt(cornucopia_async::private::Stmt); - impl AuthorNameByIdStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - id: &'a i32, - ) -> StringQuery<'a, C, String, 1> { + pub struct AuthorNameByIdStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); + impl<'a, C: GenericClient> AuthorNameByIdStmt<'a, C> { + pub fn bind(&'a mut self, id: &'a i32) -> StringQuery<'a, C, String, 1> { StringQuery { - client, + client: self.0, params: [id], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_starting_with() -> AuthorNameStartingWithStmt { - AuthorNameStartingWithStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn author_name_starting_with<'a, C: GenericClient>( + client: &'a C, + ) -> AuthorNameStartingWithStmt<'a, C> { + AuthorNameStartingWithStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT BookAuthor.AuthorId, Author.Name, BookAuthor.BookId, @@ -668,19 +673,22 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", - )) - } - pub struct AuthorNameStartingWithStmt(cornucopia_async::private::Stmt); - impl AuthorNameStartingWithStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + ), + ) + } + pub struct AuthorNameStartingWithStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> AuthorNameStartingWithStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, start_str: &'a T1, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { AuthorNameStartingWithQuery { - client, + client: self.0, params: [start_str], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -696,63 +704,73 @@ WHERE 'a, AuthorNameStartingWithParams, AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1>, - C, - > for AuthorNameStartingWithStmt + > for AuthorNameStartingWithStmt<'a, C> { fn params( &'a mut self, - client: &'a C, params: &'a AuthorNameStartingWithParams, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { - self.bind(client, ¶ms.start_str) + self.bind(¶ms.start_str) } } - pub fn select_voice_actor_with_character() -> SelectVoiceActorWithCharacterStmt { - SelectVoiceActorWithCharacterStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_voice_actor_with_character<'a, C: GenericClient>( + client: &'a C, + ) -> SelectVoiceActorWithCharacterStmt<'a, C> { + SelectVoiceActorWithCharacterStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT voice_actor FROM SpongeBobVoiceActor WHERE character = $1", - )) - } - pub struct SelectVoiceActorWithCharacterStmt(cornucopia_async::private::Stmt); - impl SelectVoiceActorWithCharacterStmt { - pub fn bind<'a, C: GenericClient>( + ), + ) + } + pub struct SelectVoiceActorWithCharacterStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectVoiceActorWithCharacterStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> { PublicVoiceactorQuery { - client, + client: self.0, params: [spongebob_character], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_translations() -> SelectTranslationsStmt { - SelectTranslationsStmt(cornucopia_async::private::Stmt::new( - "SELECT + pub fn select_translations<'a, C: GenericClient>( + client: &'a C, + ) -> SelectTranslationsStmt<'a, C> { + SelectTranslationsStmt( + client, + cornucopia_async::private::Stmt::new( + "SELECT Title, Translations FROM Book", - )) - } - pub struct SelectTranslationsStmt(cornucopia_async::private::Stmt); - impl SelectTranslationsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { + ), + ) + } + pub struct SelectTranslationsStmt<'a, C: GenericClient>( + &'a C, + cornucopia_async::private::Stmt, + ); + impl<'a, C: GenericClient> SelectTranslationsStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { SelectTranslationsQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), diff --git a/examples/basic_async/src/main.rs b/examples/basic_async/src/main.rs index cd535ed8..a0cf4192 100644 --- a/examples/basic_async/src/main.rs +++ b/examples/basic_async/src/main.rs @@ -21,34 +21,31 @@ pub async fn main() { let mut client = pool.get().await.unwrap(); // The `all` method returns queried rows collected into a `Vec` - let authors = authors().bind(&client).all().await.unwrap(); + let authors = authors(&client).bind().all().await.unwrap(); dbg!(authors); // Queries also accept transactions. Let's see how that works. { // Once you've created a transaction, you can pass it to your queries // just like you would with a regular query. Nothing special to do. - let transaction = client.transaction().await.unwrap(); + let tx = client.transaction().await.unwrap(); // Insertions work just like any other query. // Note that queries with a void return type (such as regular insertions) // are executed as soon as you `bind` their parameters. - insert_book() - .bind(&transaction, &"The Great Gatsby") - .await - .unwrap(); + insert_book(&tx).bind(&"The Great Gatsby").await.unwrap(); // Bind parameters are "smart". A query that expects a `&str` will also accept other // "string-like" types like `String`. See https://cornucopia-rs.netlify.app/book/using_queries/ergonomic_parameters.html // for more details. - insert_book() - .bind(&transaction, &String::from("Moby Dick")) + insert_book(&tx) + .bind(&String::from("Moby Dick")) .await .unwrap(); // You can use a `map` to transform query results ergonomically. - let uppercase_books = books() - .bind(&transaction) + let uppercase_books = books(&tx) + .bind() .map(|book_title| book_title.to_uppercase()) .all() .await @@ -57,12 +54,12 @@ pub async fn main() { // Don't forget to `commit` when you're done with the transaction! // Otherwise, it will be rolled back without further effect. - transaction.commit().await.unwrap(); + tx.commit().await.unwrap(); } // Using `opt` returns an optional row (zero or one). // Any other number of rows will return an error. - let author_name = author_name_by_id().bind(&client, &0).opt().await.unwrap(); + let author_name = author_name_by_id(&client).bind(&0).opt().await.unwrap(); dbg!(author_name); // Using named structs as parameters and rows can be more convenient @@ -76,8 +73,8 @@ pub async fn main() { // ! 2. Import the `Params` trait. println!( "{:?}", - author_name_starting_with() - .params(&client, &AuthorNameStartingWithParams { start_str: "Jo" }) + author_name_starting_with(&client) + .params(&AuthorNameStartingWithParams { start_str: "Jo" }) .all() .await .unwrap() @@ -88,8 +85,8 @@ pub async fn main() { // They will be automatically generated by Cornucopia. // You can use them as bind parameters (as shown here) // or receive them in returned rows. - let patrick_voice_actor = select_voice_actor_with_character() - .bind(&client, &SpongeBobCharacter::Patrick) + let patrick_voice_actor = select_voice_actor_with_character(&client) + .bind(&SpongeBobCharacter::Patrick) .one() .await .unwrap(); @@ -97,8 +94,8 @@ pub async fn main() { // Cornucopia also supports PostgreSQL arrays, which you // can use as bind parameters or in returned rows. - let translations = select_translations() - .bind(&client) + let translations = select_translations(&client) + .bind() .map(|row| format!("{}: {:?}", row.title, row.translations)) .all() .await diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index 55e9cea0..d947dd6f 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -210,21 +210,23 @@ pub mod types { pub mod queries { pub mod module_1 { use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - pub fn insert_book() -> InsertBookStmt { - InsertBookStmt(cornucopia_sync::private::Stmt::new( - "INSERT INTO Book (title) + pub fn insert_book<'a, C: GenericClient>(client: &'a mut C) -> InsertBookStmt<'a, C> { + InsertBookStmt( + client, + cornucopia_sync::private::Stmt::new( + "INSERT INTO Book (title) VALUES ($1)", - )) + ), + ) } - pub struct InsertBookStmt(cornucopia_sync::private::Stmt); - impl InsertBookStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + pub struct InsertBookStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> InsertBookStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, title: &'a T1, ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[title]) + let stmt = self.1.prepare(self.0)?; + self.0.execute(stmt, &[title]) } } } @@ -555,24 +557,24 @@ pub mod queries { Ok(it) } } - pub fn authors() -> AuthorsStmt { - AuthorsStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn authors<'a, C: GenericClient>(client: &'a mut C) -> AuthorsStmt<'a, C> { + AuthorsStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT * FROM Author", - )) + ), + ) } - pub struct AuthorsStmt(cornucopia_sync::private::Stmt); - impl AuthorsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> AuthorsQuery<'a, C, Authors, 0> { + pub struct AuthorsStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> AuthorsStmt<'a, C> { + pub fn bind(&'a mut self) -> AuthorsQuery<'a, C, Authors, 0> { AuthorsQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -582,58 +584,66 @@ FROM } } } - pub fn books() -> BooksStmt { - BooksStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn books<'a, C: GenericClient>(client: &'a mut C) -> BooksStmt<'a, C> { + BooksStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT Title FROM Book", - )) + ), + ) } - pub struct BooksStmt(cornucopia_sync::private::Stmt); - impl BooksStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> StringQuery<'a, C, String, 0> { + pub struct BooksStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); + impl<'a, C: GenericClient> BooksStmt<'a, C> { + pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { StringQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_by_id() -> AuthorNameByIdStmt { - AuthorNameByIdStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn author_name_by_id<'a, C: GenericClient>( + client: &'a mut C, + ) -> AuthorNameByIdStmt<'a, C> { + AuthorNameByIdStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT Author.Name FROM Author WHERE Author.Id = $1", - )) - } - pub struct AuthorNameByIdStmt(cornucopia_sync::private::Stmt); - impl AuthorNameByIdStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - id: &'a i32, - ) -> StringQuery<'a, C, String, 1> { + ), + ) + } + pub struct AuthorNameByIdStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> AuthorNameByIdStmt<'a, C> { + pub fn bind(&'a mut self, id: &'a i32) -> StringQuery<'a, C, String, 1> { StringQuery { - client, + client: self.0, params: [id], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_starting_with() -> AuthorNameStartingWithStmt { - AuthorNameStartingWithStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn author_name_starting_with<'a, C: GenericClient>( + client: &'a mut C, + ) -> AuthorNameStartingWithStmt<'a, C> { + AuthorNameStartingWithStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT BookAuthor.AuthorId, Author.Name, BookAuthor.BookId, @@ -644,19 +654,22 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", - )) - } - pub struct AuthorNameStartingWithStmt(cornucopia_sync::private::Stmt); - impl AuthorNameStartingWithStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + ), + ) + } + pub struct AuthorNameStartingWithStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> AuthorNameStartingWithStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, start_str: &'a T1, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { AuthorNameStartingWithQuery { - client, + client: self.0, params: [start_str], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -672,63 +685,73 @@ WHERE 'a, AuthorNameStartingWithParams, AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1>, - C, - > for AuthorNameStartingWithStmt + > for AuthorNameStartingWithStmt<'a, C> { fn params( &'a mut self, - client: &'a mut C, params: &'a AuthorNameStartingWithParams, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { - self.bind(client, ¶ms.start_str) + self.bind(¶ms.start_str) } } - pub fn select_voice_actor_with_character() -> SelectVoiceActorWithCharacterStmt { - SelectVoiceActorWithCharacterStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_voice_actor_with_character<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectVoiceActorWithCharacterStmt<'a, C> { + SelectVoiceActorWithCharacterStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT voice_actor FROM SpongeBobVoiceActor WHERE character = $1", - )) - } - pub struct SelectVoiceActorWithCharacterStmt(cornucopia_sync::private::Stmt); - impl SelectVoiceActorWithCharacterStmt { - pub fn bind<'a, C: GenericClient>( + ), + ) + } + pub struct SelectVoiceActorWithCharacterStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectVoiceActorWithCharacterStmt<'a, C> { + pub fn bind( &'a mut self, - client: &'a mut C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> { PublicVoiceactorQuery { - client, + client: self.0, params: [spongebob_character], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_translations() -> SelectTranslationsStmt { - SelectTranslationsStmt(cornucopia_sync::private::Stmt::new( - "SELECT + pub fn select_translations<'a, C: GenericClient>( + client: &'a mut C, + ) -> SelectTranslationsStmt<'a, C> { + SelectTranslationsStmt( + client, + cornucopia_sync::private::Stmt::new( + "SELECT Title, Translations FROM Book", - )) - } - pub struct SelectTranslationsStmt(cornucopia_sync::private::Stmt); - impl SelectTranslationsStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { + ), + ) + } + pub struct SelectTranslationsStmt<'a, C: GenericClient>( + &'a mut C, + cornucopia_sync::private::Stmt, + ); + impl<'a, C: GenericClient> SelectTranslationsStmt<'a, C> { + pub fn bind(&'a mut self) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { SelectTranslationsQuery { - client, + client: self.0, params: [], - stmt: &mut self.0, + stmt: &mut self.1, extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), diff --git a/examples/basic_sync/src/main.rs b/examples/basic_sync/src/main.rs index b8dc4176..062981cc 100644 --- a/examples/basic_sync/src/main.rs +++ b/examples/basic_sync/src/main.rs @@ -20,32 +20,30 @@ pub fn main() { let mut client = get_client().unwrap(); // The `all` method returns queried rows collected into a `Vec` - let authors = authors().bind(&mut client).all().unwrap(); + let authors = authors(&mut client).bind().all().unwrap(); dbg!(authors); // Queries also accept transactions. Let's see how that works. { // Once you've created a transaction, you can pass it to your queries // just like you would with a regular query. Nothing special to do. - let mut transaction = client.transaction().unwrap(); + let mut tx = client.transaction().unwrap(); // Insertions work just like any other query. // Note that queries with a void return type (such as regular insertions) // are executed as soon as you `bind` their parameters. - insert_book() - .bind(&mut transaction, &"The Great Gatsby") - .unwrap(); + insert_book(&mut tx).bind(&"The Great Gatsby").unwrap(); // Bind parameters are "smart". A query that expects a `&str` will also accept other // "string-like" types like `String`. See https://cornucopia-rs.netlify.app/book/using_queries/ergonomic_parameters.html // for more details. - insert_book() - .bind(&mut transaction, &String::from("Moby Dick")) + insert_book(&mut tx) + .bind(&String::from("Moby Dick")) .unwrap(); // You can use a `map` to transform query results ergonomically. - let uppercase_books = books() - .bind(&mut transaction) + let uppercase_books = books(&mut tx) + .bind() .map(|book_title| book_title.to_uppercase()) .all() .unwrap(); @@ -53,12 +51,12 @@ pub fn main() { // Don't forget to `commit` when you're done with the transaction! // Otherwise, it will be rolled back without further effect. - transaction.commit().unwrap(); + tx.commit().unwrap(); } // Using `opt` returns an optional row (zero or one). // Any other number of rows will return an error. - let author_name = author_name_by_id().bind(&mut client, &0).opt().unwrap(); + let author_name = author_name_by_id(&mut client).bind(&0).opt().unwrap(); dbg!(author_name); // Using named structs as parameters and rows can be more convenient @@ -70,11 +68,8 @@ pub fn main() { // ! general information and the `queries/module_2.sql` file to see how this particular // ! parameter type was created). // ! 2. Import the `Params` trait. - let name_starting_with_jo = author_name_starting_with() - .params( - &mut client, - &AuthorNameStartingWithParams { start_str: "Jo" }, - ) + let name_starting_with_jo = author_name_starting_with(&mut client) + .params(&AuthorNameStartingWithParams { start_str: "Jo" }) .all() .unwrap(); dbg!(name_starting_with_jo); @@ -84,16 +79,16 @@ pub fn main() { // They will be automatically generated by Cornucopia. // You can use them as bind parameters (as shown here) // or receive them in returned rows. - let patrick_voice_actor = select_voice_actor_with_character() - .bind(&mut client, &SpongeBobCharacter::Patrick) + let patrick_voice_actor = select_voice_actor_with_character(&mut client) + .bind(&SpongeBobCharacter::Patrick) .one() .unwrap(); dbg!(patrick_voice_actor); // Cornucopia also supports PostgreSQL arrays, which you // can use as bind parameters or in returned rows. - let translations = select_translations() - .bind(&mut client) + let translations = select_translations(&mut client) + .bind() .map(|row| format!("{}: {:?}", row.title, row.translations)) .all() .unwrap(); From cde2d78fc85c90aad2a3a945be494fdcde7ea0c0 Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 01:45:43 +0100 Subject: [PATCH 2/7] Stop implicit statement caching --- bench/usage/cornucopia_benches/generated.rs | 481 ++- bench/usage/cornucopia_benches/mod.rs | 65 +- clients/async/src/lib.rs | 4 +- clients/async/src/private.rs | 31 - clients/sync/src/lib.rs | 4 +- clients/sync/src/private.rs | 30 - codegen_test/src/cornucopia.rs | 3134 +++++++++---------- codegen_test/src/main.rs | 183 +- cornucopia/src/codegen.rs | 48 +- examples/auto_build/src/cornucopia.rs | 36 +- examples/auto_build/src/main.rs | 2 +- examples/basic_async/src/cornucopia.rs | 244 +- examples/basic_async/src/main.rs | 33 +- examples/basic_sync/src/cornucopia.rs | 249 +- examples/basic_sync/src/main.rs | 35 +- 15 files changed, 2134 insertions(+), 2445 deletions(-) diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs index 823b0864..d50baa4e 100644 --- a/bench/usage/cornucopia_benches/generated.rs +++ b/bench/usage/cornucopia_benches/generated.rs @@ -142,7 +142,7 @@ pub mod queries { pub struct UserQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::UserBorrowed, mapper: fn(super::UserBorrowed) -> T, } @@ -157,34 +157,34 @@ pub mod queries { UserQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -193,7 +193,7 @@ pub mod queries { pub struct PostQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::PostBorrowed, mapper: fn(super::PostBorrowed) -> T, } @@ -208,34 +208,34 @@ pub mod queries { PostQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -244,7 +244,7 @@ pub mod queries { pub struct CommentQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::CommentBorrowed, mapper: fn(super::CommentBorrowed) -> T, } @@ -259,34 +259,34 @@ pub mod queries { CommentQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -295,7 +295,7 @@ pub mod queries { pub struct SelectComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::SelectComplexBorrowed, mapper: fn(super::SelectComplexBorrowed) -> T, } @@ -310,52 +310,52 @@ pub mod queries { SelectComplexQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn users<'a, C: GenericClient>(client: &'a mut C) -> UsersStmt<'a, C> { - UsersStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM users"), - ) + pub fn users() -> UsersStmt { + UsersStmt("SELECT * FROM users") } - pub struct UsersStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> UsersStmt<'a, C> { - pub fn bind(&'a mut self) -> UserQuery<'a, C, super::User, 0> { + pub struct UsersStmt(&'static str); + impl UsersStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> UserQuery<'a, C, super::User, 0> { UserQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -365,26 +365,24 @@ pub mod queries { } } } - pub fn insert_user<'a, C: GenericClient>(client: &'a mut C) -> InsertUserStmt<'a, C> { - InsertUserStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO users (name, hair_color) VALUES ($1, $2)", - ), - ) - } - pub struct InsertUserStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertUserStmt<'a, C> { - pub fn bind( - &'a mut self, + pub fn insert_user() -> InsertUserStmt { + InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)") + } + pub struct InsertUserStmt(&'static str); + impl InsertUserStmt { + pub fn bind< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::StringSql, + >( + &'a self, + client: &'a mut C, name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[name, hair_color]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[name, hair_color]) } } impl< @@ -397,28 +395,30 @@ pub mod queries { 'a, super::InsertUserParams, Result, - > for InsertUserStmt<'a, C> + C, + > for InsertUserStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::InsertUserParams, ) -> Result { - self.bind(¶ms.name, ¶ms.hair_color) + self.bind(client, ¶ms.name, ¶ms.hair_color) } } - pub fn posts<'a, C: GenericClient>(client: &'a mut C) -> PostsStmt<'a, C> { - PostsStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM posts"), - ) + pub fn posts() -> PostsStmt { + PostsStmt("SELECT * FROM posts") } - pub struct PostsStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> PostsStmt<'a, C> { - pub fn bind(&'a mut self) -> PostQuery<'a, C, super::Post, 0> { + pub struct PostsStmt(&'static str); + impl PostsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> PostQuery<'a, C, super::Post, 0> { PostQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -429,29 +429,20 @@ pub mod queries { } } } - pub fn post_by_user_ids<'a, C: GenericClient>( - client: &'a mut C, - ) -> PostByUserIdsStmt<'a, C> { - PostByUserIdsStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT * FROM posts WHERE user_id = ANY($1)", - ), - ) - } - pub struct PostByUserIdsStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> PostByUserIdsStmt<'a, C> { - pub fn bind>( - &'a mut self, + pub fn post_by_user_ids() -> PostByUserIdsStmt { + PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)") + } + pub struct PostByUserIdsStmt(&'static str); + impl PostByUserIdsStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( + &'a self, + client: &'a mut C, ids: &'a T1, ) -> PostQuery<'a, C, super::Post, 1> { PostQuery { - client: self.0, + client, params: [ids], - stmt: &mut self.1, + query: self.0, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -462,22 +453,19 @@ pub mod queries { } } } - pub fn comments<'a, C: GenericClient>(client: &'a mut C) -> CommentsStmt<'a, C> { - CommentsStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM comments"), - ) + pub fn comments() -> CommentsStmt { + CommentsStmt("SELECT * FROM comments") } - pub struct CommentsStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> CommentsStmt<'a, C> { - pub fn bind(&'a mut self) -> CommentQuery<'a, C, super::Comment, 0> { + pub struct CommentsStmt(&'static str); + impl CommentsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> CommentQuery<'a, C, super::Comment, 0> { CommentQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -487,29 +475,20 @@ pub mod queries { } } } - pub fn comments_by_post_id<'a, C: GenericClient>( - client: &'a mut C, - ) -> CommentsByPostIdStmt<'a, C> { - CommentsByPostIdStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT * FROM comments WHERE post_id = ANY($1)", - ), - ) - } - pub struct CommentsByPostIdStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> CommentsByPostIdStmt<'a, C> { - pub fn bind>( - &'a mut self, + pub fn comments_by_post_id() -> CommentsByPostIdStmt { + CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)") + } + pub struct CommentsByPostIdStmt(&'static str); + impl CommentsByPostIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( + &'a self, + client: &'a mut C, ids: &'a T1, ) -> CommentQuery<'a, C, super::Comment, 1> { CommentQuery { - client: self.0, + client, params: [ids], - stmt: &mut self.1, + query: self.0, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -519,21 +498,19 @@ pub mod queries { } } } - pub fn select_complex<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectComplexStmt<'a, C> { - SelectComplexStmt(client, cornucopia_sync :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) - } - pub struct SelectComplexStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectComplexStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { + pub fn select_complex() -> SelectComplexStmt { + SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id") + } + pub struct SelectComplexStmt(&'static str); + impl SelectComplexStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { SelectComplexQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), @@ -555,7 +532,7 @@ pub mod queries { pub struct UserQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::UserBorrowed, mapper: fn(super::UserBorrowed) -> T, } @@ -570,24 +547,24 @@ pub mod queries { UserQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -597,10 +574,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -610,7 +587,7 @@ pub mod queries { pub struct PostQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::PostBorrowed, mapper: fn(super::PostBorrowed) -> T, } @@ -625,24 +602,24 @@ pub mod queries { PostQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -652,10 +629,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -665,7 +642,7 @@ pub mod queries { pub struct CommentQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::CommentBorrowed, mapper: fn(super::CommentBorrowed) -> T, } @@ -680,24 +657,24 @@ pub mod queries { CommentQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -707,10 +684,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -720,7 +697,7 @@ pub mod queries { pub struct SelectComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::SelectComplexBorrowed, mapper: fn(super::SelectComplexBorrowed) -> T, } @@ -735,24 +712,24 @@ pub mod queries { SelectComplexQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -762,29 +739,29 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn users<'a, C: GenericClient>(client: &'a C) -> UsersStmt<'a, C> { - UsersStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM users"), - ) + pub fn users() -> UsersStmt { + UsersStmt("SELECT * FROM users") } - pub struct UsersStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> UsersStmt<'a, C> { - pub fn bind(&'a mut self) -> UserQuery<'a, C, super::User, 0> { + pub struct UsersStmt(&'static str); + impl UsersStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> UserQuery<'a, C, super::User, 0> { UserQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -794,26 +771,24 @@ pub mod queries { } } } - pub fn insert_user<'a, C: GenericClient>(client: &'a C) -> InsertUserStmt<'a, C> { - InsertUserStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO users (name, hair_color) VALUES ($1, $2)", - ), - ) + pub fn insert_user() -> InsertUserStmt { + InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)") } - pub struct InsertUserStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> InsertUserStmt<'a, C> { + pub struct InsertUserStmt(&'static str); + impl InsertUserStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, >( - &'a mut self, + &'a self, + client: &'a C, name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[name, hair_color]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[name, hair_color]).await } } impl< @@ -832,10 +807,12 @@ pub mod queries { + 'a, >, >, - > for InsertUserStmt<'a, C> + C, + > for InsertUserStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::InsertUserParams, ) -> std::pin::Pin< Box< @@ -844,22 +821,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(¶ms.name, ¶ms.hair_color)) + Box::pin(self.bind(client, ¶ms.name, ¶ms.hair_color)) } } - pub fn posts<'a, C: GenericClient>(client: &'a C) -> PostsStmt<'a, C> { - PostsStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM posts"), - ) + pub fn posts() -> PostsStmt { + PostsStmt("SELECT * FROM posts") } - pub struct PostsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> PostsStmt<'a, C> { - pub fn bind(&'a mut self) -> PostQuery<'a, C, super::Post, 0> { + pub struct PostsStmt(&'static str); + impl PostsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> PostQuery<'a, C, super::Post, 0> { PostQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -870,29 +847,20 @@ pub mod queries { } } } - pub fn post_by_user_ids<'a, C: GenericClient>( - client: &'a C, - ) -> PostByUserIdsStmt<'a, C> { - PostByUserIdsStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT * FROM posts WHERE user_id = ANY($1)", - ), - ) - } - pub struct PostByUserIdsStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> PostByUserIdsStmt<'a, C> { - pub fn bind>( - &'a mut self, + pub fn post_by_user_ids() -> PostByUserIdsStmt { + PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)") + } + pub struct PostByUserIdsStmt(&'static str); + impl PostByUserIdsStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( + &'a self, + client: &'a C, ids: &'a T1, ) -> PostQuery<'a, C, super::Post, 1> { PostQuery { - client: self.0, + client, params: [ids], - stmt: &mut self.1, + query: self.0, extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -903,19 +871,19 @@ pub mod queries { } } } - pub fn comments<'a, C: GenericClient>(client: &'a C) -> CommentsStmt<'a, C> { - CommentsStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM comments"), - ) + pub fn comments() -> CommentsStmt { + CommentsStmt("SELECT * FROM comments") } - pub struct CommentsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> CommentsStmt<'a, C> { - pub fn bind(&'a mut self) -> CommentQuery<'a, C, super::Comment, 0> { + pub struct CommentsStmt(&'static str); + impl CommentsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> CommentQuery<'a, C, super::Comment, 0> { CommentQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -925,29 +893,20 @@ pub mod queries { } } } - pub fn comments_by_post_id<'a, C: GenericClient>( - client: &'a C, - ) -> CommentsByPostIdStmt<'a, C> { - CommentsByPostIdStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT * FROM comments WHERE post_id = ANY($1)", - ), - ) - } - pub struct CommentsByPostIdStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> CommentsByPostIdStmt<'a, C> { - pub fn bind>( - &'a mut self, + pub fn comments_by_post_id() -> CommentsByPostIdStmt { + CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)") + } + pub struct CommentsByPostIdStmt(&'static str); + impl CommentsByPostIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( + &'a self, + client: &'a C, ids: &'a T1, ) -> CommentQuery<'a, C, super::Comment, 1> { CommentQuery { - client: self.0, + client, params: [ids], - stmt: &mut self.1, + query: self.0, extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -957,19 +916,19 @@ pub mod queries { } } } - pub fn select_complex<'a, C: GenericClient>(client: &'a C) -> SelectComplexStmt<'a, C> { - SelectComplexStmt(client, cornucopia_async :: private :: Stmt :: new("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id")) + pub fn select_complex() -> SelectComplexStmt { + SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id") } - pub struct SelectComplexStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectComplexStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { + pub struct SelectComplexStmt(&'static str); + impl SelectComplexStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> SelectComplexQuery<'a, C, super::SelectComplex, 0> { SelectComplexQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), diff --git a/bench/usage/cornucopia_benches/mod.rs b/bench/usage/cornucopia_benches/mod.rs index 1b082282..d81081f7 100644 --- a/bench/usage/cornucopia_benches/mod.rs +++ b/bench/usage/cornucopia_benches/mod.rs @@ -12,14 +12,15 @@ use self::generated::queries::bench::{ mod generated; pub fn bench_trivial_query(b: &mut Bencher, client: &Client) { - b.iter(move || block_on(async { users(client).bind().all().await.unwrap() })) + let mut stmt = users(); + b.iter(|| block_on(async { stmt.bind(client).all().await.unwrap() })) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { + let mut stmt = select_complex(); b.iter(|| { block_on(async { - select_complex(client) - .bind() + stmt.bind(client) .map(|it| { ( User { @@ -43,14 +44,18 @@ pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { + let mut stmt = insert_user(); b.iter(|| { block_on(async { let mut tx = client.transaction().await.unwrap(); for x in 0..size { - insert_user(&mut tx) - .bind(&format!("User {}", x).as_str(), &Some("hair_color")) - .await - .unwrap(); + stmt.bind( + &mut tx, + &format!("User {}", x).as_str(), + &Some("hair_color"), + ) + .await + .unwrap(); } tx.commit().await.unwrap(); }) @@ -58,19 +63,21 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { } pub fn loading_associations_sequentially(b: &mut Bencher, client: &Client) { + let mut user_stmt = users(); + let mut post_stmt = post_by_user_ids(); + let mut comment_stmt = comments_by_post_id(); b.iter(|| { - let mut user_stmt = users(client); block_on(async { - let users = user_stmt.bind().all().await.unwrap(); + let users = user_stmt.bind(client).all().await.unwrap(); let users_ids: Vec = users.iter().map(|it| it.id).collect(); - let posts = post_by_user_ids(client) - .bind(&users_ids.as_slice()) + let posts = post_stmt + .bind(client, &users_ids.as_slice()) .all() .await .unwrap(); let posts_ids: Vec = posts.iter().map(|it| it.id).collect(); - let comments = comments_by_post_id(client) - .bind(&posts_ids.as_slice()) + let comments = comment_stmt + .bind(client, &posts_ids.as_slice()) .all() .await .unwrap(); @@ -116,13 +123,14 @@ pub mod sync { Comment, Post, User, }; pub fn bench_trivial_query(b: &mut Bencher, client: &mut Client) { - b.iter(|| users(client).bind().all().unwrap()) + let mut stmt = users(); + b.iter(|| stmt.bind(client).all().unwrap()) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &mut Client) { + let mut stmt = select_complex(); b.iter(|| { - select_complex(client) - .bind() + stmt.bind(client) .map(|it| { ( User { @@ -144,28 +152,33 @@ pub mod sync { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { + let mut stmt = insert_user(); b.iter(|| { let mut tx = client.transaction().unwrap(); for x in 0..size { - insert_user(&mut tx) - .bind(&format!("User {}", x).as_str(), &Some("hair_color")) - .unwrap(); + stmt.bind( + &mut tx, + &format!("User {}", x).as_str(), + &Some("hair_color"), + ) + .unwrap(); } tx.commit().unwrap(); }) } pub fn loading_associations_sequentially(b: &mut Bencher, client: &mut Client) { + let mut user_stmt = users(); + let mut post_stmt = post_by_user_ids(); + let mut comment_stmt = comments_by_post_id(); + b.iter(|| { - let users = users(client).bind().all().unwrap(); + let users = user_stmt.bind(client).all().unwrap(); let users_ids: Vec = users.iter().map(|it| it.id).collect(); - let posts = post_by_user_ids(client) - .bind(&users_ids.as_slice()) - .all() - .unwrap(); + let posts = post_stmt.bind(client, &users_ids.as_slice()).all().unwrap(); let posts_ids: Vec = posts.iter().map(|it| it.id).collect(); - let comments = comments_by_post_id(client) - .bind(&posts_ids.as_slice()) + let comments = comment_stmt + .bind(client, &posts_ids.as_slice()) .all() .unwrap(); diff --git a/clients/async/src/lib.rs b/clients/async/src/lib.rs index 63403884..296d6bdd 100644 --- a/clients/async/src/lib.rs +++ b/clients/async/src/lib.rs @@ -13,6 +13,6 @@ mod generic_client; /// This trait allows you to bind parameters to a query using a single /// struct, rather than passing each bind parameter as a function parameter. -pub trait Params<'a, P, O> { - fn params(&'a mut self, params: &'a P) -> O; +pub trait Params<'a, P, O, C> { + fn params(&'a self, client: &'a C, params: &'a P) -> O; } diff --git a/clients/async/src/private.rs b/clients/async/src/private.rs index 5ab675d9..20b8d68d 100644 --- a/clients/async/src/private.rs +++ b/clients/async/src/private.rs @@ -1,32 +1 @@ pub use cornucopia_client_core::{slice_iter, Domain, DomainArray}; - -use crate::generic_client::GenericClient; -use tokio_postgres::{Error, Statement}; - -/// Cached statement -pub struct Stmt { - query: &'static str, - cached: Option, -} - -impl Stmt { - #[must_use] - pub fn new(query: &'static str) -> Self { - Self { - query, - cached: None, - } - } - - pub async fn prepare<'a, C: GenericClient>( - &'a mut self, - client: &C, - ) -> Result<&'a Statement, Error> { - if self.cached.is_none() { - let stmt = client.prepare(self.query).await?; - self.cached = Some(stmt); - } - // the statement is always prepared at this point - Ok(unsafe { self.cached.as_ref().unwrap_unchecked() }) - } -} diff --git a/clients/sync/src/lib.rs b/clients/sync/src/lib.rs index 0e2d5fc2..8e840021 100644 --- a/clients/sync/src/lib.rs +++ b/clients/sync/src/lib.rs @@ -8,6 +8,6 @@ pub use cornucopia_client_core::JsonSql; /// This trait allows you to bind parameters to a query using a single /// struct, rather than passing each bind parameter as a function parameter. -pub trait Params<'a, P, O> { - fn params(&'a mut self, params: &'a P) -> O; +pub trait Params<'a, P, O, C> { + fn params(&'a self, client: &'a mut C, params: &'a P) -> O; } diff --git a/clients/sync/src/private.rs b/clients/sync/src/private.rs index fa01d7c8..20b8d68d 100644 --- a/clients/sync/src/private.rs +++ b/clients/sync/src/private.rs @@ -1,31 +1 @@ pub use cornucopia_client_core::{slice_iter, Domain, DomainArray}; - -use postgres::Statement; - -/// Cached statement -pub struct Stmt { - query: &'static str, - cached: Option, -} - -impl Stmt { - #[must_use] - pub fn new(query: &'static str) -> Self { - Self { - query, - cached: None, - } - } - - pub fn prepare<'a, C: postgres::GenericClient>( - &'a mut self, - client: &mut C, - ) -> Result<&'a Statement, postgres::Error> { - if self.cached.is_none() { - let stmt = client.prepare(self.query)?; - self.cached = Some(stmt); - } - // the statement is always prepared at this point - Ok(unsafe { self.cached.as_ref().unwrap_unchecked() }) - } -} diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs index 7e4ad16f..911150d8 100644 --- a/codegen_test/src/cornucopia.rs +++ b/codegen_test/src/cornucopia.rs @@ -1268,7 +1268,7 @@ pub mod queries { pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn( &postgres::Row, ) @@ -1286,34 +1286,34 @@ pub mod queries { PublicCloneCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1322,7 +1322,7 @@ pub mod queries { pub struct PublicCopyCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::super::super::types::public::CopyComposite, mapper: fn(super::super::super::types::public::CopyComposite) -> T, } @@ -1337,73 +1337,61 @@ pub mod queries { PublicCopyCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn insert_clone<'a, C: GenericClient>(client: &'a mut C) -> InsertCloneStmt<'a, C> { - InsertCloneStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO clone (composite) VALUES ($1)", - ), - ) + pub fn insert_clone() -> InsertCloneStmt { + InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)") } - pub struct InsertCloneStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertCloneStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct InsertCloneStmt(&'static str); + impl InsertCloneStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[composite]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[composite]) } } - pub fn select_clone<'a, C: GenericClient>(client: &'a mut C) -> SelectCloneStmt<'a, C> { - SelectCloneStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM clone"), - ) + pub fn select_clone() -> SelectCloneStmt { + SelectCloneStmt("SELECT * FROM clone") } - pub struct SelectCloneStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectCloneStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCloneStmt(&'static str); + impl SelectCloneStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -1411,46 +1399,36 @@ pub mod queries { 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_copy<'a, C: GenericClient>(client: &'a mut C) -> InsertCopyStmt<'a, C> { - InsertCopyStmt( - client, - cornucopia_sync::private::Stmt::new("INSERT INTO copy (composite) VALUES ($1)"), - ) + pub fn insert_copy() -> InsertCopyStmt { + InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)") } - pub struct InsertCopyStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertCopyStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct InsertCopyStmt(&'static str); + impl InsertCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[composite]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[composite]) } } - pub fn select_copy<'a, C: GenericClient>(client: &'a mut C) -> SelectCopyStmt<'a, C> { - SelectCopyStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM copy"), - ) + pub fn select_copy() -> SelectCopyStmt { + SelectCopyStmt("SELECT * FROM copy") } - pub struct SelectCopyStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectCopyStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCopyStmt(&'static str); + impl SelectCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> PublicCopyCompositeQuery< 'a, C, @@ -1458,9 +1436,9 @@ pub mod queries { 0, > { PublicCopyCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -1474,7 +1452,7 @@ pub mod queries { pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn( &tokio_postgres::Row, ) @@ -1492,24 +1470,24 @@ pub mod queries { PublicCloneCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -1519,10 +1497,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -1532,7 +1510,7 @@ pub mod queries { pub struct PublicCopyCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::super::super::types::public::CopyComposite, mapper: fn(super::super::super::types::public::CopyComposite) -> T, @@ -1548,24 +1526,24 @@ pub mod queries { PublicCopyCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -1575,50 +1553,38 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn insert_clone<'a, C: GenericClient>(client: &'a C) -> InsertCloneStmt<'a, C> { - InsertCloneStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO clone (composite) VALUES ($1)", - ), - ) + pub fn insert_clone() -> InsertCloneStmt { + InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)") } - pub struct InsertCloneStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> InsertCloneStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct InsertCloneStmt(&'static str); + impl InsertCloneStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[composite]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[composite]).await } } - pub fn select_clone<'a, C: GenericClient>(client: &'a C) -> SelectCloneStmt<'a, C> { - SelectCloneStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM clone"), - ) + pub fn select_clone() -> SelectCloneStmt { + SelectCloneStmt("SELECT * FROM clone") } - pub struct SelectCloneStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectCloneStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCloneStmt(&'static str); + impl SelectCloneStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -1626,42 +1592,36 @@ pub mod queries { 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_copy<'a, C: GenericClient>(client: &'a C) -> InsertCopyStmt<'a, C> { - InsertCopyStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO copy (composite) VALUES ($1)", - ), - ) + pub fn insert_copy() -> InsertCopyStmt { + InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)") } - pub struct InsertCopyStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> InsertCopyStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct InsertCopyStmt(&'static str); + impl InsertCopyStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[composite]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[composite]).await } } - pub fn select_copy<'a, C: GenericClient>(client: &'a C) -> SelectCopyStmt<'a, C> { - SelectCopyStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM copy"), - ) + pub fn select_copy() -> SelectCopyStmt { + SelectCopyStmt("SELECT * FROM copy") } - pub struct SelectCopyStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> SelectCopyStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCopyStmt(&'static str); + impl SelectCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> PublicCopyCompositeQuery< 'a, C, @@ -1669,9 +1629,9 @@ pub mod queries { 0, > { PublicCopyCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -1773,7 +1733,7 @@ pub mod queries { pub struct SelectNightmareDomainQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::SelectNightmareDomainBorrowed, mapper: fn(super::SelectNightmareDomainBorrowed) -> T, } @@ -1788,34 +1748,34 @@ pub mod queries { SelectNightmareDomainQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1824,7 +1784,7 @@ pub mod queries { pub struct SelectNightmareDomainNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::SelectNightmareDomainNullBorrowed, mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, } @@ -1839,62 +1799,53 @@ pub mod queries { SelectNightmareDomainNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn select_nightmare_domain<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectNightmareDomainStmt<'a, C> { - SelectNightmareDomainStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT txt, json, nb, arr FROM nightmare_domain", - ), - ) + pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { + SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain") } - pub struct SelectNightmareDomainStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareDomainStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareDomainStmt(&'static str); + impl SelectNightmareDomainStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> { SelectNightmareDomainQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -1905,23 +1856,21 @@ pub mod queries { } } } - pub fn insert_nightmare_domain<'a, C: GenericClient>( - client: &'a mut C, - ) -> InsertNightmareDomainStmt<'a, C> { - InsertNightmareDomainStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) - } - pub struct InsertNightmareDomainStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertNightmareDomainStmt<'a, C> { + pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { + InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)") + } + pub struct InsertNightmareDomainStmt(&'static str); + impl InsertNightmareDomainStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::JsonSql, T3: cornucopia_sync::JsonSql, T4: cornucopia_sync::ArraySql, >( - &'a mut self, + &'a self, + client: &'a mut C, txt: &'a T1, json: &'a T2, nb: &'a i32, @@ -1930,9 +1879,9 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute( - stmt, + let stmt = client.prepare(self.0)?; + client.execute( + &stmt, &[ &cornucopia_sync::private::Domain(txt), &cornucopia_sync::private::Domain(json), @@ -1957,13 +1906,16 @@ pub mod queries { 'a, super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, Result, - > for InsertNightmareDomainStmt<'a, C> + C, + > for InsertNightmareDomainStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, ) -> Result { self.bind( + client, ¶ms.txt, ¶ms.json, ¶ms.nb, @@ -1972,27 +1924,20 @@ pub mod queries { ) } } - pub fn select_nightmare_domain_null<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectNightmareDomainNullStmt<'a, C> { - SelectNightmareDomainNullStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM nightmare_domain"), - ) + pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { + SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain") } - pub struct SelectNightmareDomainNullStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareDomainNullStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareDomainNullStmt(&'static str); + impl SelectNightmareDomainNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> { SelectNightmareDomainNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -2012,7 +1957,7 @@ pub mod queries { pub struct SelectNightmareDomainQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainBorrowed, mapper: fn(super::SelectNightmareDomainBorrowed) -> T, } @@ -2027,24 +1972,24 @@ pub mod queries { SelectNightmareDomainQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2054,10 +1999,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2067,7 +2012,7 @@ pub mod queries { pub struct SelectNightmareDomainNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainNullBorrowed, mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, } @@ -2082,24 +2027,24 @@ pub mod queries { SelectNightmareDomainNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2109,39 +2054,30 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn select_nightmare_domain<'a, C: GenericClient>( - client: &'a C, - ) -> SelectNightmareDomainStmt<'a, C> { - SelectNightmareDomainStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT txt, json, nb, arr FROM nightmare_domain", - ), - ) + pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { + SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain") } - pub struct SelectNightmareDomainStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareDomainStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareDomainStmt(&'static str); + impl SelectNightmareDomainStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> { SelectNightmareDomainQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -2152,23 +2088,21 @@ pub mod queries { } } } - pub fn insert_nightmare_domain<'a, C: GenericClient>( - client: &'a C, - ) -> InsertNightmareDomainStmt<'a, C> { - InsertNightmareDomainStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)")) - } - pub struct InsertNightmareDomainStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> InsertNightmareDomainStmt<'a, C> { + pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { + InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)") + } + pub struct InsertNightmareDomainStmt(&'static str); + impl InsertNightmareDomainStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::JsonSql, T3: cornucopia_async::JsonSql, T4: cornucopia_async::ArraySql, >( - &'a mut self, + &'a self, + client: &'a C, txt: &'a T1, json: &'a T2, nb: &'a i32, @@ -2177,10 +2111,10 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0 + let stmt = client.prepare(self.0).await?; + client .execute( - stmt, + &stmt, &[ &cornucopia_async::private::Domain(txt), &cornucopia_async::private::Domain(json), @@ -2212,10 +2146,12 @@ pub mod queries { + 'a, >, >, - > for InsertNightmareDomainStmt<'a, C> + C, + > for InsertNightmareDomainStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, ) -> std::pin::Pin< Box< @@ -2225,6 +2161,7 @@ pub mod queries { >, > { Box::pin(self.bind( + client, ¶ms.txt, ¶ms.json, ¶ms.nb, @@ -2233,27 +2170,20 @@ pub mod queries { )) } } - pub fn select_nightmare_domain_null<'a, C: GenericClient>( - client: &'a C, - ) -> SelectNightmareDomainNullStmt<'a, C> { - SelectNightmareDomainNullStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM nightmare_domain"), - ) + pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { + SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain") } - pub struct SelectNightmareDomainNullStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareDomainNullStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareDomainNullStmt(&'static str); + impl SelectNightmareDomainNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> { SelectNightmareDomainNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -2339,7 +2269,7 @@ pub mod queries { pub struct IdQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::Id, mapper: fn(super::Id) -> T, } @@ -2351,34 +2281,34 @@ pub mod queries { IdQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -2387,7 +2317,7 @@ pub mod queries { pub struct NamedQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::NamedBorrowed, mapper: fn(super::NamedBorrowed) -> T, } @@ -2402,34 +2332,34 @@ pub mod queries { NamedQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -2438,7 +2368,7 @@ pub mod queries { pub struct NamedComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::NamedComplexBorrowed, mapper: fn(super::NamedComplexBorrowed) -> T, } @@ -2453,132 +2383,120 @@ pub mod queries { NamedComplexQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn new_named_visible<'a, C: GenericClient>( - client: &'a mut C, - ) -> NewNamedVisibleStmt<'a, C> { + pub fn new_named_visible() -> NewNamedVisibleStmt { NewNamedVisibleStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", ) } - pub struct NewNamedVisibleStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedVisibleStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NewNamedVisibleStmt(&'static str); + impl NewNamedVisibleStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a T1, price: &'a Option, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> - for NewNamedVisibleStmt<'a, C> + cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>, C> + for NewNamedVisibleStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn new_named_hidden<'a, C: GenericClient>( - client: &'a mut C, - ) -> NewNamedHiddenStmt<'a, C> { + pub fn new_named_hidden() -> NewNamedHiddenStmt { NewNamedHiddenStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NewNamedHiddenStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedHiddenStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NewNamedHiddenStmt(&'static str); + impl NewNamedHiddenStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, price: &'a Option, name: &'a T1, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client: self.0, + client, params: [price, name], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> - for NewNamedHiddenStmt<'a, C> + cornucopia_sync::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>, C> + for NewNamedHiddenStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(¶ms.price, ¶ms.name) + self.bind(client, ¶ms.price, ¶ms.name) } } - pub fn named<'a, C: GenericClient>(client: &'a mut C) -> NamedStmt<'a, C> { - NamedStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM named"), - ) + pub fn named() -> NamedStmt { + NamedStmt("SELECT * FROM named") } - pub struct NamedStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> NamedStmt<'a, C> { - pub fn bind(&'a mut self) -> NamedQuery<'a, C, super::Named, 0> { + pub struct NamedStmt(&'static str); + impl NamedStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> NamedQuery<'a, C, super::Named, 0> { NamedQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2589,22 +2507,20 @@ pub mod queries { } } } - pub fn named_by_id<'a, C: GenericClient>(client: &'a mut C) -> NamedByIdStmt<'a, C> { - NamedByIdStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM named WHERE id = $1"), - ) + pub fn named_by_id() -> NamedByIdStmt { + NamedByIdStmt("SELECT * FROM named WHERE id = $1") } - pub struct NamedByIdStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NamedByIdStmt<'a, C> { - pub fn bind(&'a mut self, id: &'a i32) -> NamedQuery<'a, C, super::Named, 1> { + pub struct NamedByIdStmt(&'static str); + impl NamedByIdStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + id: &'a i32, + ) -> NamedQuery<'a, C, super::Named, 1> { NamedQuery { - client: self.0, + client, params: [id], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2615,30 +2531,23 @@ pub mod queries { } } } - pub fn new_named_complex<'a, C: GenericClient>( - client: &'a mut C, - ) -> NewNamedComplexStmt<'a, C> { + pub fn new_named_complex() -> NewNamedComplexStmt { NewNamedComplexStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", - ), + "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", ) } - pub struct NewNamedComplexStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedComplexStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NewNamedComplexStmt(&'static str); + impl NewNamedComplexStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, named: &'a super::super::super::types::public::NamedCompositeBorrowed<'a>, named_with_dot: &'a Option< super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[named, named_with_dot]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[named, named_with_dot]) } } impl<'a, C: GenericClient> @@ -2646,33 +2555,30 @@ pub mod queries { 'a, super::NamedComplexParams<'a>, Result, - > for NewNamedComplexStmt<'a, C> + C, + > for NewNamedComplexStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::NamedComplexParams<'a>, ) -> Result { - self.bind(¶ms.named, ¶ms.named_with_dot) + self.bind(client, ¶ms.named, ¶ms.named_with_dot) } } - pub fn named_complex<'a, C: GenericClient>( - client: &'a mut C, - ) -> NamedComplexStmt<'a, C> { - NamedComplexStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM named_complex"), - ) + pub fn named_complex() -> NamedComplexStmt { + NamedComplexStmt("SELECT * FROM named_complex") } - pub struct NamedComplexStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NamedComplexStmt<'a, C> { - pub fn bind(&'a mut self) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { + pub struct NamedComplexStmt(&'static str); + impl NamedComplexStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { NamedComplexQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -2689,7 +2595,7 @@ pub mod queries { pub struct IdQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::Id, mapper: fn(super::Id) -> T, } @@ -2701,24 +2607,24 @@ pub mod queries { IdQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2728,10 +2634,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2741,7 +2647,7 @@ pub mod queries { pub struct NamedQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::NamedBorrowed, mapper: fn(super::NamedBorrowed) -> T, } @@ -2756,24 +2662,24 @@ pub mod queries { NamedQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2783,10 +2689,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2796,7 +2702,7 @@ pub mod queries { pub struct NamedComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::NamedComplexBorrowed, mapper: fn(super::NamedComplexBorrowed) -> T, } @@ -2811,24 +2717,24 @@ pub mod queries { NamedComplexQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2838,109 +2744,105 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn new_named_visible<'a, C: GenericClient>( - client: &'a C, - ) -> NewNamedVisibleStmt<'a, C> { + pub fn new_named_visible() -> NewNamedVisibleStmt { NewNamedVisibleStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", ) } - pub struct NewNamedVisibleStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedVisibleStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NewNamedVisibleStmt(&'static str); + impl NewNamedVisibleStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a T1, price: &'a Option, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> - for NewNamedVisibleStmt<'a, C> + cornucopia_async::Params< + 'a, + super::NamedParams, + IdQuery<'a, C, super::Id, 2>, + C, + > for NewNamedVisibleStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn new_named_hidden<'a, C: GenericClient>( - client: &'a C, - ) -> NewNamedHiddenStmt<'a, C> { + pub fn new_named_hidden() -> NewNamedHiddenStmt { NewNamedHiddenStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NewNamedHiddenStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedHiddenStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NewNamedHiddenStmt(&'static str); + impl NewNamedHiddenStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, price: &'a Option, name: &'a T1, ) -> IdQuery<'a, C, super::Id, 2> { IdQuery { - client: self.0, + client, params: [price, name], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, super::NamedParams, IdQuery<'a, C, super::Id, 2>> - for NewNamedHiddenStmt<'a, C> + cornucopia_async::Params< + 'a, + super::NamedParams, + IdQuery<'a, C, super::Id, 2>, + C, + > for NewNamedHiddenStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::NamedParams, ) -> IdQuery<'a, C, super::Id, 2> { - self.bind(¶ms.price, ¶ms.name) + self.bind(client, ¶ms.price, ¶ms.name) } } - pub fn named<'a, C: GenericClient>(client: &'a C) -> NamedStmt<'a, C> { - NamedStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM named"), - ) + pub fn named() -> NamedStmt { + NamedStmt("SELECT * FROM named") } - pub struct NamedStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> NamedStmt<'a, C> { - pub fn bind(&'a mut self) -> NamedQuery<'a, C, super::Named, 0> { + pub struct NamedStmt(&'static str); + impl NamedStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> NamedQuery<'a, C, super::Named, 0> { NamedQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2951,19 +2853,20 @@ pub mod queries { } } } - pub fn named_by_id<'a, C: GenericClient>(client: &'a C) -> NamedByIdStmt<'a, C> { - NamedByIdStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM named WHERE id = $1"), - ) + pub fn named_by_id() -> NamedByIdStmt { + NamedByIdStmt("SELECT * FROM named WHERE id = $1") } - pub struct NamedByIdStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> NamedByIdStmt<'a, C> { - pub fn bind(&'a mut self, id: &'a i32) -> NamedQuery<'a, C, super::Named, 1> { + pub struct NamedByIdStmt(&'static str); + impl NamedByIdStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + id: &'a i32, + ) -> NamedQuery<'a, C, super::Named, 1> { NamedQuery { - client: self.0, + client, params: [id], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2974,30 +2877,23 @@ pub mod queries { } } } - pub fn new_named_complex<'a, C: GenericClient>( - client: &'a C, - ) -> NewNamedComplexStmt<'a, C> { + pub fn new_named_complex() -> NewNamedComplexStmt { NewNamedComplexStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", - ), + "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", ) } - pub struct NewNamedComplexStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NewNamedComplexStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct NewNamedComplexStmt(&'static str); + impl NewNamedComplexStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, named: &'a super::super::super::types::public::NamedCompositeBorrowed<'a>, named_with_dot: &'a Option< super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[named, named_with_dot]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[named, named_with_dot]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -3011,10 +2907,12 @@ pub mod queries { + 'a, >, >, - > for NewNamedComplexStmt<'a, C> + C, + > for NewNamedComplexStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::NamedComplexParams<'a>, ) -> std::pin::Pin< Box< @@ -3023,25 +2921,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(¶ms.named, ¶ms.named_with_dot)) + Box::pin(self.bind(client, ¶ms.named, ¶ms.named_with_dot)) } } - pub fn named_complex<'a, C: GenericClient>(client: &'a C) -> NamedComplexStmt<'a, C> { - NamedComplexStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM named_complex"), - ) + pub fn named_complex() -> NamedComplexStmt { + NamedComplexStmt("SELECT * FROM named_complex") } - pub struct NamedComplexStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NamedComplexStmt<'a, C> { - pub fn bind(&'a mut self) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { + pub struct NamedComplexStmt(&'static str); + impl NamedComplexStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> NamedComplexQuery<'a, C, super::NamedComplex, 0> { NamedComplexQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -3095,7 +2990,7 @@ pub mod queries { pub struct NullityQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::NullityBorrowed, mapper: fn(super::NullityBorrowed) -> T, } @@ -3110,66 +3005,61 @@ pub mod queries { NullityQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn new_nullity<'a, C: GenericClient>(client: &'a mut C) -> NewNullityStmt<'a, C> { - NewNullityStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", - ), - ) + pub fn new_nullity() -> NewNullityStmt { + NewNullityStmt("INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)") } - pub struct NewNullityStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NewNullityStmt<'a, C> { + pub struct NewNullityStmt(&'static str); + impl NewNullityStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::ArraySql>, T3: cornucopia_sync::StringSql, >( - &'a mut self, + &'a self, + client: &'a mut C, texts: &'a T2, name: &'a T3, composite: &'a Option< super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[texts, name, composite]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[texts, name, composite]) } } impl< @@ -3183,28 +3073,30 @@ pub mod queries { 'a, super::NullityParams<'a, T1, T2, T3>, Result, - > for NewNullityStmt<'a, C> + C, + > for NewNullityStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::NullityParams<'a, T1, T2, T3>, ) -> Result { - self.bind(¶ms.texts, ¶ms.name, ¶ms.composite) + self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite) } } - pub fn nullity<'a, C: GenericClient>(client: &'a mut C) -> NullityStmt<'a, C> { - NullityStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM nullity"), - ) + pub fn nullity() -> NullityStmt { + NullityStmt("SELECT * FROM nullity") } - pub struct NullityStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> NullityStmt<'a, C> { - pub fn bind(&'a mut self) -> NullityQuery<'a, C, super::Nullity, 0> { + pub struct NullityStmt(&'static str); + impl NullityStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> NullityQuery<'a, C, super::Nullity, 0> { NullityQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3222,7 +3114,7 @@ pub mod queries { pub struct NullityQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::NullityBorrowed, mapper: fn(super::NullityBorrowed) -> T, } @@ -3237,24 +3129,24 @@ pub mod queries { NullityQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3264,40 +3156,38 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn new_nullity<'a, C: GenericClient>(client: &'a C) -> NewNullityStmt<'a, C> { - NewNullityStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", - ), - ) + pub fn new_nullity() -> NewNullityStmt { + NewNullityStmt("INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)") } - pub struct NewNullityStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> NewNullityStmt<'a, C> { + pub struct NewNullityStmt(&'static str); + impl NewNullityStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::ArraySql>, T3: cornucopia_async::StringSql, >( - &'a mut self, + &'a self, + client: &'a C, texts: &'a T2, name: &'a T3, composite: &'a Option< super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[texts, name, composite]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[texts, name, composite]).await } } impl< @@ -3317,10 +3207,12 @@ pub mod queries { + 'a, >, >, - > for NewNullityStmt<'a, C> + C, + > for NewNullityStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::NullityParams<'a, T1, T2, T3>, ) -> std::pin::Pin< Box< @@ -3329,22 +3221,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(¶ms.texts, ¶ms.name, ¶ms.composite)) + Box::pin(self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite)) } } - pub fn nullity<'a, C: GenericClient>(client: &'a C) -> NullityStmt<'a, C> { - NullityStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM nullity"), - ) + pub fn nullity() -> NullityStmt { + NullityStmt("SELECT * FROM nullity") } - pub struct NullityStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> NullityStmt<'a, C> { - pub fn bind(&'a mut self) -> NullityQuery<'a, C, super::Nullity, 0> { + pub struct NullityStmt(&'static str); + impl NullityStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> NullityQuery<'a, C, super::Nullity, 0> { NullityQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3409,7 +3301,7 @@ pub mod queries { pub struct SelectBookQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::SelectBookBorrowed, mapper: fn(super::SelectBookBorrowed) -> T, } @@ -3424,34 +3316,34 @@ pub mod queries { SelectBookQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -3460,7 +3352,7 @@ pub mod queries { pub struct FindBooksQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::FindBooksBorrowed, mapper: fn(super::FindBooksBorrowed) -> T, } @@ -3475,59 +3367,57 @@ pub mod queries { FindBooksQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn insert_book<'a, C: GenericClient>(client: &'a mut C) -> InsertBookStmt<'a, C> { - InsertBookStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO book (author, name) VALUES ($1, $2)", - ), - ) + pub fn insert_book() -> InsertBookStmt { + InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)") } - pub struct InsertBookStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertBookStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct InsertBookStmt(&'static str); + impl InsertBookStmt { + pub fn bind< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::StringSql, + >( + &'a self, + client: &'a mut C, author: &'a Option, name: &'a T2, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[author, name]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[author, name]) } } impl< @@ -3540,31 +3430,30 @@ pub mod queries { 'a, super::InsertBookParams, Result, - > for InsertBookStmt<'a, C> + C, + > for InsertBookStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::InsertBookParams, ) -> Result { - self.bind(¶ms.author, ¶ms.name) + self.bind(client, ¶ms.author, ¶ms.name) } } - pub fn select_book<'a, C: GenericClient>(client: &'a mut C) -> SelectBookStmt<'a, C> { - SelectBookStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM book"), - ) + pub fn select_book() -> SelectBookStmt { + SelectBookStmt("SELECT * FROM book") } - pub struct SelectBookStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectBookStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectBookQuery<'a, C, super::SelectBook, 0> { + pub struct SelectBookStmt(&'static str); + impl SelectBookStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> SelectBookQuery<'a, C, super::SelectBook, 0> { SelectBookQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3573,28 +3462,25 @@ pub mod queries { } } } - pub fn find_books<'a, C: GenericClient>(client: &'a mut C) -> FindBooksStmt<'a, C> { - FindBooksStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM book WHERE name = ANY ($1)"), - ) + pub fn find_books() -> FindBooksStmt { + FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)") } - pub struct FindBooksStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> FindBooksStmt<'a, C> { + pub struct FindBooksStmt(&'static str); + impl FindBooksStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::ArraySql, >( - &'a mut self, + &'a self, + client: &'a mut C, title: &'a T2, ) -> FindBooksQuery<'a, C, super::FindBooks, 1> { FindBooksQuery { - client: self.0, + client, params: [title], - stmt: &mut self.1, + query: self.0, extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3603,56 +3489,51 @@ pub mod queries { } } } - pub fn params_use_twice<'a, C: GenericClient>( - client: &'a mut C, - ) -> ParamsUseTwiceStmt<'a, C> { + pub fn params_use_twice() -> ParamsUseTwiceStmt { ParamsUseTwiceStmt( - client, - cornucopia_sync::private::Stmt::new( - "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", - ), + "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", ) } - pub struct ParamsUseTwiceStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> ParamsUseTwiceStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct ParamsUseTwiceStmt(&'static str); + impl ParamsUseTwiceStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a T1, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[name]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[name]) } } - pub fn params_order<'a, C: GenericClient>(client: &'a mut C) -> ParamsOrderStmt<'a, C> { - ParamsOrderStmt( - client, - cornucopia_sync::private::Stmt::new( - "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", - ), - ) + pub fn params_order() -> ParamsOrderStmt { + ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1") } - pub struct ParamsOrderStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> ParamsOrderStmt<'a, C> { - pub fn bind(&'a mut self, c: &'a i32, a: &'a i32) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[c, a]) + pub struct ParamsOrderStmt(&'static str); + impl ParamsOrderStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + c: &'a i32, + a: &'a i32, + ) -> Result { + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[c, a]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::ParamsOrderParams, Result> - for ParamsOrderStmt<'a, C> + cornucopia_sync::Params< + 'a, + super::ParamsOrderParams, + Result, + C, + > for ParamsOrderStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::ParamsOrderParams, ) -> Result { - self.bind(¶ms.c, ¶ms.a) + self.bind(client, ¶ms.c, ¶ms.a) } } } @@ -3663,7 +3544,7 @@ pub mod queries { pub struct SelectBookQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::SelectBookBorrowed, mapper: fn(super::SelectBookBorrowed) -> T, } @@ -3678,24 +3559,24 @@ pub mod queries { SelectBookQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3705,10 +3586,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -3718,7 +3599,7 @@ pub mod queries { pub struct FindBooksQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::FindBooksBorrowed, mapper: fn(super::FindBooksBorrowed) -> T, } @@ -3733,24 +3614,24 @@ pub mod queries { FindBooksQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3760,36 +3641,34 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn insert_book<'a, C: GenericClient>(client: &'a C) -> InsertBookStmt<'a, C> { - InsertBookStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO book (author, name) VALUES ($1, $2)", - ), - ) + pub fn insert_book() -> InsertBookStmt { + InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)") } - pub struct InsertBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> InsertBookStmt<'a, C> { + pub struct InsertBookStmt(&'static str); + impl InsertBookStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, >( - &'a mut self, + &'a self, + client: &'a C, author: &'a Option, name: &'a T2, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[author, name]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[author, name]).await } } impl< @@ -3808,10 +3687,12 @@ pub mod queries { + 'a, >, >, - > for InsertBookStmt<'a, C> + C, + > for InsertBookStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::InsertBookParams, ) -> std::pin::Pin< Box< @@ -3820,22 +3701,22 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(¶ms.author, ¶ms.name)) + Box::pin(self.bind(client, ¶ms.author, ¶ms.name)) } } - pub fn select_book<'a, C: GenericClient>(client: &'a C) -> SelectBookStmt<'a, C> { - SelectBookStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM book"), - ) + pub fn select_book() -> SelectBookStmt { + SelectBookStmt("SELECT * FROM book") } - pub struct SelectBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> SelectBookStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectBookQuery<'a, C, super::SelectBook, 0> { + pub struct SelectBookStmt(&'static str); + impl SelectBookStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> SelectBookQuery<'a, C, super::SelectBook, 0> { SelectBookQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3844,27 +3725,25 @@ pub mod queries { } } } - pub fn find_books<'a, C: GenericClient>(client: &'a C) -> FindBooksStmt<'a, C> { - FindBooksStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT * FROM book WHERE name = ANY ($1)", - ), - ) + pub fn find_books() -> FindBooksStmt { + FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)") } - pub struct FindBooksStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> FindBooksStmt<'a, C> { + pub struct FindBooksStmt(&'static str); + impl FindBooksStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::ArraySql, >( - &'a mut self, + &'a self, + client: &'a C, title: &'a T2, ) -> FindBooksQuery<'a, C, super::FindBooks, 1> { FindBooksQuery { - client: self.0, + client, params: [title], - stmt: &mut self.1, + query: self.0, extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3873,49 +3752,35 @@ pub mod queries { } } } - pub fn params_use_twice<'a, C: GenericClient>( - client: &'a C, - ) -> ParamsUseTwiceStmt<'a, C> { + pub fn params_use_twice() -> ParamsUseTwiceStmt { ParamsUseTwiceStmt( - client, - cornucopia_async::private::Stmt::new( - "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", - ), + "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", ) } - pub struct ParamsUseTwiceStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> ParamsUseTwiceStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct ParamsUseTwiceStmt(&'static str); + impl ParamsUseTwiceStmt { + pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a T1, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[name]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[name]).await } } - pub fn params_order<'a, C: GenericClient>(client: &'a C) -> ParamsOrderStmt<'a, C> { - ParamsOrderStmt( - client, - cornucopia_async::private::Stmt::new( - "UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", - ), - ) + pub fn params_order() -> ParamsOrderStmt { + ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1") } - pub struct ParamsOrderStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> ParamsOrderStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct ParamsOrderStmt(&'static str); + impl ParamsOrderStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, c: &'a i32, a: &'a i32, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[c, a]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[c, a]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -3929,10 +3794,12 @@ pub mod queries { + 'a, >, >, - > for ParamsOrderStmt<'a, C> + C, + > for ParamsOrderStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::ParamsOrderParams, ) -> std::pin::Pin< Box< @@ -3941,7 +3808,7 @@ pub mod queries { + 'a, >, > { - Box::pin(self.bind(¶ms.c, ¶ms.a)) + Box::pin(self.bind(client, ¶ms.c, ¶ms.a)) } } } @@ -4644,7 +4511,7 @@ pub mod queries { pub struct EverythingQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::EverythingBorrowed, mapper: fn(super::EverythingBorrowed) -> T, } @@ -4659,34 +4526,34 @@ pub mod queries { EverythingQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4695,7 +4562,7 @@ pub mod queries { pub struct EverythingNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::EverythingNullBorrowed, mapper: fn(super::EverythingNullBorrowed) -> T, } @@ -4710,34 +4577,34 @@ pub mod queries { EverythingNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4746,7 +4613,7 @@ pub mod queries { pub struct EverythingArrayQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::EverythingArrayBorrowed, mapper: fn(super::EverythingArrayBorrowed) -> T, } @@ -4761,34 +4628,34 @@ pub mod queries { EverythingArrayQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4797,7 +4664,7 @@ pub mod queries { pub struct EverythingArrayNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::EverythingArrayNullBorrowed, mapper: fn(super::EverythingArrayNullBorrowed) -> T, } @@ -4812,34 +4679,34 @@ pub mod queries { EverythingArrayNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4848,7 +4715,7 @@ pub mod queries { pub struct PublicNightmareCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn( &postgres::Row, ) @@ -4866,62 +4733,57 @@ pub mod queries { PublicNightmareCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn select_everything<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectEverythingStmt<'a, C> { + pub fn select_everything() -> SelectEverythingStmt { SelectEverythingStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM Everything", - ), ) } - pub struct SelectEverythingStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingStmt<'a, C> { - pub fn bind(&'a mut self) -> EverythingQuery<'a, C, super::Everything, 0> { + pub struct SelectEverythingStmt(&'static str); + impl SelectEverythingStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> EverythingQuery<'a, C, super::Everything, 0> { EverythingQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -4962,29 +4824,24 @@ FROM } } } - pub fn select_everything_null<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectEverythingNullStmt<'a, C> { + pub fn select_everything_null() -> SelectEverythingNullStmt { SelectEverythingNullStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM Everything", - ), ) } - pub struct SelectEverythingNullStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingNullStmt<'a, C> { - pub fn bind(&'a mut self) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { + pub struct SelectEverythingNullStmt(&'static str); + impl SelectEverythingNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { EverythingNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5025,25 +4882,23 @@ FROM } } } - pub fn insert_everything<'a, C: GenericClient>( - client: &'a mut C, - ) -> InsertEverythingStmt<'a, C> { - InsertEverythingStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)")) - } - pub struct InsertEverythingStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertEverythingStmt<'a, C> { + pub fn insert_everything() -> InsertEverythingStmt { + InsertEverythingStmt("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)") + } + pub struct InsertEverythingStmt(&'static str); + impl InsertEverythingStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_sync::StringSql, T2: cornucopia_sync::StringSql, T3: cornucopia_sync::BytesSql, T4: cornucopia_sync::JsonSql, T5: cornucopia_sync::JsonSql, >( - &'a mut self, + &'a self, + client: &'a mut C, bool_: &'a bool, boolean_: &'a bool, char_: &'a i8, @@ -5079,9 +4934,9 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute( - stmt, + let stmt = client.prepare(self.0)?; + client.execute( + &stmt, &[ bool_, boolean_, @@ -5134,13 +4989,16 @@ FROM 'a, super::EverythingParams, Result, - > for InsertEverythingStmt<'a, C> + C, + > for InsertEverythingStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::EverythingParams, ) -> Result { self.bind( + client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -5178,31 +5036,24 @@ FROM ) } } - pub fn select_everything_array<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectEverythingArrayStmt<'a, C> { + pub fn select_everything_array() -> SelectEverythingArrayStmt { SelectEverythingArrayStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM EverythingArray", - ), ) } - pub struct SelectEverythingArrayStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingArrayStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectEverythingArrayStmt(&'static str); + impl SelectEverythingArrayStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { EverythingArrayQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5237,32 +5088,25 @@ FROM } } } - pub fn select_everything_array_null<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectEverythingArrayNullStmt<'a, C> { + pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { SelectEverythingArrayNullStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM EverythingArray", - ), ) } - pub struct SelectEverythingArrayNullStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingArrayNullStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectEverythingArrayNullStmt(&'static str); + impl SelectEverythingArrayNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> { EverythingArrayNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5297,18 +5141,15 @@ FROM } } } - pub fn insert_everything_array<'a, C: GenericClient>( - client: &'a mut C, - ) -> InsertEverythingArrayStmt<'a, C> { - InsertEverythingArrayStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)")) - } - pub struct InsertEverythingArrayStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertEverythingArrayStmt<'a, C> { + pub fn insert_everything_array() -> InsertEverythingArrayStmt { + InsertEverythingArrayStmt("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)") + } + pub struct InsertEverythingArrayStmt(&'static str); + impl InsertEverythingArrayStmt { pub fn bind< + 'a, + C: GenericClient, T1: cornucopia_sync::ArraySql, T2: cornucopia_sync::ArraySql, T3: cornucopia_sync::ArraySql, @@ -5343,7 +5184,8 @@ FROM T32: cornucopia_sync::ArraySql, T33: cornucopia_sync::ArraySql, >( - &'a mut self, + &'a self, + client: &'a mut C, bool_: &'a T1, boolean_: &'a T2, char_: &'a T3, @@ -5373,9 +5215,9 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute( - stmt, + let stmt = client.prepare(self.0)?; + client.execute( + &stmt, &[ bool_, boolean_, @@ -5484,10 +5326,12 @@ FROM T33, >, Result, - > for InsertEverythingArrayStmt<'a, C> + C, + > for InsertEverythingArrayStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::EverythingArrayParams< T1, T2, @@ -5525,6 +5369,7 @@ FROM >, ) -> Result { self.bind( + client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -5556,26 +5401,19 @@ FROM ) } } - pub fn select_nightmare<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectNightmareStmt<'a, C> { + pub fn select_nightmare() -> SelectNightmareStmt { SelectNightmareStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM nightmare", - ), ) } - pub struct SelectNightmareStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareStmt(&'static str); + impl SelectNightmareStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> PublicNightmareCompositeQuery< 'a, C, @@ -5583,36 +5421,29 @@ FROM 0, > { PublicNightmareCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_nightmare<'a, C: GenericClient>( - client: &'a mut C, - ) -> InsertNightmareStmt<'a, C> { + pub fn insert_nightmare() -> InsertNightmareStmt { InsertNightmareStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO nightmare (composite) + "INSERT INTO nightmare (composite) VALUES ($1)", - ), ) } - pub struct InsertNightmareStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> InsertNightmareStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct InsertNightmareStmt(&'static str); + impl InsertNightmareStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[composite]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[composite]) } } } @@ -5623,7 +5454,7 @@ FROM pub struct EverythingQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::EverythingBorrowed, mapper: fn(super::EverythingBorrowed) -> T, } @@ -5638,24 +5469,24 @@ FROM EverythingQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5665,10 +5496,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5678,7 +5509,7 @@ FROM pub struct EverythingNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::EverythingNullBorrowed, mapper: fn(super::EverythingNullBorrowed) -> T, } @@ -5693,24 +5524,24 @@ FROM EverythingNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5720,10 +5551,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5733,7 +5564,7 @@ FROM pub struct EverythingArrayQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayBorrowed, mapper: fn(super::EverythingArrayBorrowed) -> T, } @@ -5748,24 +5579,24 @@ FROM EverythingArrayQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5775,10 +5606,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5788,7 +5619,7 @@ FROM pub struct EverythingArrayNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayNullBorrowed, mapper: fn(super::EverythingArrayNullBorrowed) -> T, } @@ -5803,24 +5634,24 @@ FROM EverythingArrayNullQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5830,10 +5661,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5843,7 +5674,7 @@ FROM pub struct PublicNightmareCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn( &tokio_postgres::Row, ) @@ -5861,24 +5692,24 @@ FROM PublicNightmareCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5888,39 +5719,34 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn select_everything<'a, C: GenericClient>( - client: &'a C, - ) -> SelectEverythingStmt<'a, C> { + pub fn select_everything() -> SelectEverythingStmt { SelectEverythingStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM Everything", - ), ) } - pub struct SelectEverythingStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingStmt<'a, C> { - pub fn bind(&'a mut self) -> EverythingQuery<'a, C, super::Everything, 0> { + pub struct SelectEverythingStmt(&'static str); + impl SelectEverythingStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> EverythingQuery<'a, C, super::Everything, 0> { EverythingQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5961,29 +5787,24 @@ FROM } } } - pub fn select_everything_null<'a, C: GenericClient>( - client: &'a C, - ) -> SelectEverythingNullStmt<'a, C> { + pub fn select_everything_null() -> SelectEverythingNullStmt { SelectEverythingNullStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM Everything", - ), ) } - pub struct SelectEverythingNullStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingNullStmt<'a, C> { - pub fn bind(&'a mut self) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { + pub struct SelectEverythingNullStmt(&'static str); + impl SelectEverythingNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> EverythingNullQuery<'a, C, super::EverythingNull, 0> { EverythingNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6024,25 +5845,23 @@ FROM } } } - pub fn insert_everything<'a, C: GenericClient>( - client: &'a C, - ) -> InsertEverythingStmt<'a, C> { - InsertEverythingStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)")) - } - pub struct InsertEverythingStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> InsertEverythingStmt<'a, C> { + pub fn insert_everything() -> InsertEverythingStmt { + InsertEverythingStmt("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)") + } + pub struct InsertEverythingStmt(&'static str); + impl InsertEverythingStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql, T3: cornucopia_async::BytesSql, T4: cornucopia_async::JsonSql, T5: cornucopia_async::JsonSql, >( - &'a mut self, + &'a self, + client: &'a C, bool_: &'a bool, boolean_: &'a bool, char_: &'a i8, @@ -6078,10 +5897,10 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0 + let stmt = client.prepare(self.0).await?; + client .execute( - stmt, + &stmt, &[ bool_, boolean_, @@ -6141,10 +5960,12 @@ FROM + 'a, >, >, - > for InsertEverythingStmt<'a, C> + C, + > for InsertEverythingStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::EverythingParams, ) -> std::pin::Pin< Box< @@ -6154,6 +5975,7 @@ FROM >, > { Box::pin(self.bind( + client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -6191,31 +6013,24 @@ FROM )) } } - pub fn select_everything_array<'a, C: GenericClient>( - client: &'a C, - ) -> SelectEverythingArrayStmt<'a, C> { + pub fn select_everything_array() -> SelectEverythingArrayStmt { SelectEverythingArrayStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM EverythingArray", - ), ) } - pub struct SelectEverythingArrayStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingArrayStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectEverythingArrayStmt(&'static str); + impl SelectEverythingArrayStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { EverythingArrayQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6250,32 +6065,25 @@ FROM } } } - pub fn select_everything_array_null<'a, C: GenericClient>( - client: &'a C, - ) -> SelectEverythingArrayNullStmt<'a, C> { + pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { SelectEverythingArrayNullStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM EverythingArray", - ), ) } - pub struct SelectEverythingArrayNullStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectEverythingArrayNullStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectEverythingArrayNullStmt(&'static str); + impl SelectEverythingArrayNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> { EverythingArrayNullQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6310,18 +6118,15 @@ FROM } } } - pub fn insert_everything_array<'a, C: GenericClient>( - client: &'a C, - ) -> InsertEverythingArrayStmt<'a, C> { - InsertEverythingArrayStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)")) - } - pub struct InsertEverythingArrayStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> InsertEverythingArrayStmt<'a, C> { + pub fn insert_everything_array() -> InsertEverythingArrayStmt { + InsertEverythingArrayStmt("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)") + } + pub struct InsertEverythingArrayStmt(&'static str); + impl InsertEverythingArrayStmt { pub async fn bind< + 'a, + C: GenericClient, T1: cornucopia_async::ArraySql, T2: cornucopia_async::ArraySql, T3: cornucopia_async::ArraySql, @@ -6356,7 +6161,8 @@ FROM T32: cornucopia_async::ArraySql, T33: cornucopia_async::ArraySql, >( - &'a mut self, + &'a self, + client: &'a C, bool_: &'a T1, boolean_: &'a T2, char_: &'a T3, @@ -6386,10 +6192,10 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0 + let stmt = client.prepare(self.0).await?; + client .execute( - stmt, + &stmt, &[ bool_, boolean_, @@ -6505,10 +6311,12 @@ FROM + 'a, >, >, - > for InsertEverythingArrayStmt<'a, C> + C, + > for InsertEverythingArrayStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::EverythingArrayParams< T1, T2, @@ -6552,6 +6360,7 @@ FROM >, > { Box::pin(self.bind( + client, ¶ms.bool_, ¶ms.boolean_, ¶ms.char_, @@ -6583,26 +6392,19 @@ FROM )) } } - pub fn select_nightmare<'a, C: GenericClient>( - client: &'a C, - ) -> SelectNightmareStmt<'a, C> { + pub fn select_nightmare() -> SelectNightmareStmt { SelectNightmareStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM nightmare", - ), ) } - pub struct SelectNightmareStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectNightmareStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectNightmareStmt(&'static str); + impl SelectNightmareStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> PublicNightmareCompositeQuery< 'a, C, @@ -6610,36 +6412,29 @@ FROM 0, > { PublicNightmareCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn insert_nightmare<'a, C: GenericClient>( - client: &'a C, - ) -> InsertNightmareStmt<'a, C> { + pub fn insert_nightmare() -> InsertNightmareStmt { InsertNightmareStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO nightmare (composite) + "INSERT INTO nightmare (composite) VALUES ($1)", - ), ) } - pub struct InsertNightmareStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> InsertNightmareStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct InsertNightmareStmt(&'static str); + impl InsertNightmareStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[composite]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[composite]).await } } } @@ -6754,7 +6549,7 @@ FROM pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn( &postgres::Row, ) @@ -6772,34 +6567,34 @@ FROM PublicCloneCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6808,7 +6603,7 @@ FROM pub struct Optioni32Query<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> Option, mapper: fn(Option) -> T, } @@ -6820,34 +6615,34 @@ FROM Optioni32Query { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6856,7 +6651,7 @@ FROM pub struct RowQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::Row, mapper: fn(super::Row) -> T, } @@ -6868,34 +6663,34 @@ FROM RowQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6904,7 +6699,7 @@ FROM pub struct RowSpaceQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::RowSpace, mapper: fn(super::RowSpace) -> T, } @@ -6919,34 +6714,34 @@ FROM RowSpaceQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6955,7 +6750,7 @@ FROM pub struct TypeofQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::TypeofBorrowed, mapper: fn(super::TypeofBorrowed) -> T, } @@ -6970,54 +6765,47 @@ FROM TypeofQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn select_compact<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectCompactStmt<'a, C> { - SelectCompactStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM clone"), - ) + pub fn select_compact() -> SelectCompactStmt { + SelectCompactStmt("SELECT * FROM clone") } - pub struct SelectCompactStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCompactStmt(&'static str); + impl SelectCompactStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7025,29 +6813,22 @@ FROM 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_spaced<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectSpacedStmt<'a, C> { - SelectSpacedStmt( - client, - cornucopia_sync::private::Stmt::new(" SELECT * FROM clone "), - ) + pub fn select_spaced() -> SelectSpacedStmt { + SelectSpacedStmt(" SELECT * FROM clone ") } - pub struct SelectSpacedStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectSpacedStmt(&'static str); + impl SelectSpacedStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7055,38 +6836,31 @@ FROM 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn implicit_compact<'a, C: GenericClient>( - client: &'a mut C, - ) -> ImplicitCompactStmt<'a, C> { + pub fn implicit_compact() -> ImplicitCompactStmt { ImplicitCompactStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct ImplicitCompactStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> ImplicitCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct ImplicitCompactStmt(&'static str); + impl ImplicitCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -7097,39 +6871,34 @@ FROM 'a, super::ImplicitCompactParams, Optioni32Query<'a, C, Option, 2>, - > for ImplicitCompactStmt<'a, C> + C, + > for ImplicitCompactStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::ImplicitCompactParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn implicit_spaced<'a, C: GenericClient>( - client: &'a mut C, - ) -> ImplicitSpacedStmt<'a, C> { + pub fn implicit_spaced() -> ImplicitSpacedStmt { ImplicitSpacedStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct ImplicitSpacedStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> ImplicitSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct ImplicitSpacedStmt(&'static str); + impl ImplicitSpacedStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -7140,77 +6909,68 @@ FROM 'a, super::ImplicitSpacedParams, Optioni32Query<'a, C, Option, 2>, - > for ImplicitSpacedStmt<'a, C> + C, + > for ImplicitSpacedStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::ImplicitSpacedParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn named_compact<'a, C: GenericClient>( - client: &'a mut C, - ) -> NamedCompactStmt<'a, C> { + pub fn named_compact() -> NamedCompactStmt { NamedCompactStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NamedCompactStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NamedCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NamedCompactStmt(&'static str); + impl NamedCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a T1, price: &'a f64, ) -> RowQuery<'a, C, super::Row, 2> { RowQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>> - for NamedCompactStmt<'a, C> + cornucopia_sync::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>, C> + for NamedCompactStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::Params, ) -> RowQuery<'a, C, super::Row, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn named_spaced<'a, C: GenericClient>(client: &'a mut C) -> NamedSpacedStmt<'a, C> { + pub fn named_spaced() -> NamedSpacedStmt { NamedSpacedStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NamedSpacedStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> NamedSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NamedSpacedStmt(&'static str); + impl NamedSpacedStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, name: &'a T1, price: &'a f64, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { RowSpaceQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -7221,308 +6981,336 @@ FROM 'a, super::ParamsSpace, RowSpaceQuery<'a, C, super::RowSpace, 2>, - > for NamedSpacedStmt<'a, C> + C, + > for NamedSpacedStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::ParamsSpace, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn tricky_sql<'a, C: GenericClient>(client: &'a mut C) -> TrickySqlStmt<'a, C> { - TrickySqlStmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) + pub fn tricky_sql() -> TrickySqlStmt { + TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)") } - pub struct TrickySqlStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySqlStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySqlStmt(&'static str); + impl TrickySqlStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySqlParams, Result> - for TrickySqlStmt<'a, C> + cornucopia_sync::Params<'a, super::TrickySqlParams, Result, C> + for TrickySqlStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySqlParams, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql1<'a, C: GenericClient>(client: &'a mut C) -> TrickySql1Stmt<'a, C> { - TrickySql1Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) + pub fn tricky_sql1() -> TrickySql1Stmt { + TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)") } - pub struct TrickySql1Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql1Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql1Stmt(&'static str); + impl TrickySql1Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql1Params, Result> - for TrickySql1Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql1Params, + Result, + C, + > for TrickySql1Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql1Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql2<'a, C: GenericClient>(client: &'a mut C) -> TrickySql2Stmt<'a, C> { - TrickySql2Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql2() -> TrickySql2Stmt { + TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)") } - pub struct TrickySql2Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql2Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql2Stmt(&'static str); + impl TrickySql2Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql2Params, Result> - for TrickySql2Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql2Params, + Result, + C, + > for TrickySql2Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql2Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql3<'a, C: GenericClient>(client: &'a mut C) -> TrickySql3Stmt<'a, C> { - TrickySql3Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) + pub fn tricky_sql3() -> TrickySql3Stmt { + TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)") } - pub struct TrickySql3Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql3Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql3Stmt(&'static str); + impl TrickySql3Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql3Params, Result> - for TrickySql3Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql3Params, + Result, + C, + > for TrickySql3Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql3Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql4<'a, C: GenericClient>(client: &'a mut C) -> TrickySql4Stmt<'a, C> { - TrickySql4Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) + pub fn tricky_sql4() -> TrickySql4Stmt { + TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)") } - pub struct TrickySql4Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql4Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql4Stmt(&'static str); + impl TrickySql4Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql4Params, Result> - for TrickySql4Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql4Params, + Result, + C, + > for TrickySql4Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql4Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql6<'a, C: GenericClient>(client: &'a mut C) -> TrickySql6Stmt<'a, C> { - TrickySql6Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql6() -> TrickySql6Stmt { + TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)") } - pub struct TrickySql6Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql6Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql6Stmt(&'static str); + impl TrickySql6Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql6Params, Result> - for TrickySql6Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql6Params, + Result, + C, + > for TrickySql6Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql6Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql7<'a, C: GenericClient>(client: &'a mut C) -> TrickySql7Stmt<'a, C> { - TrickySql7Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) + pub fn tricky_sql7() -> TrickySql7Stmt { + TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)") } - pub struct TrickySql7Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql7Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql7Stmt(&'static str); + impl TrickySql7Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql7Params, Result> - for TrickySql7Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql7Params, + Result, + C, + > for TrickySql7Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql7Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql8<'a, C: GenericClient>(client: &'a mut C) -> TrickySql8Stmt<'a, C> { - TrickySql8Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql8() -> TrickySql8Stmt { + TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)") } - pub struct TrickySql8Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql8Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql8Stmt(&'static str); + impl TrickySql8Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql8Params, Result> - for TrickySql8Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql8Params, + Result, + C, + > for TrickySql8Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql8Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql9<'a, C: GenericClient>(client: &'a mut C) -> TrickySql9Stmt<'a, C> { - TrickySql9Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql9() -> TrickySql9Stmt { + TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)") } - pub struct TrickySql9Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql9Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql9Stmt(&'static str); + impl TrickySql9Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql9Params, Result> - for TrickySql9Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql9Params, + Result, + C, + > for TrickySql9Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql9Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn tricky_sql10<'a, C: GenericClient>(client: &'a mut C) -> TrickySql10Stmt<'a, C> { - TrickySql10Stmt(client, cornucopia_sync :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) + pub fn tricky_sql10() -> TrickySql10Stmt { + TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)") } - pub struct TrickySql10Stmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql10Stmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct TrickySql10Stmt(&'static str); + impl TrickySql10Stmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[r#async, r#enum]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[r#async, r#enum]) } } impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, super::TrickySql10Params, Result> - for TrickySql10Stmt<'a, C> + cornucopia_sync::Params< + 'a, + super::TrickySql10Params, + Result, + C, + > for TrickySql10Stmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a super::TrickySql10Params, ) -> Result { - self.bind(¶ms.r#async, ¶ms.r#enum) + self.bind(client, ¶ms.r#async, ¶ms.r#enum) } } - pub fn r#typeof<'a, C: GenericClient>(client: &'a mut C) -> RTypeofStmt<'a, C> { - RTypeofStmt( - client, - cornucopia_sync::private::Stmt::new("SELECT * FROM syntax"), - ) + pub fn r#typeof() -> RTypeofStmt { + RTypeofStmt("SELECT * FROM syntax") } - pub struct RTypeofStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> RTypeofStmt<'a, C> { - pub fn bind(&'a mut self) -> TypeofQuery<'a, C, super::Typeof, 0> { + pub struct RTypeofStmt(&'static str); + impl RTypeofStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> TypeofQuery<'a, C, super::Typeof, 0> { TypeofQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), @@ -7540,7 +7328,7 @@ FROM pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn( &tokio_postgres::Row, ) @@ -7558,24 +7346,24 @@ FROM PublicCloneCompositeQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7585,10 +7373,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7598,7 +7386,7 @@ FROM pub struct Optioni32Query<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> Option, mapper: fn(Option) -> T, } @@ -7610,24 +7398,24 @@ FROM Optioni32Query { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7637,10 +7425,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7650,7 +7438,7 @@ FROM pub struct RowQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::Row, mapper: fn(super::Row) -> T, } @@ -7662,24 +7450,24 @@ FROM RowQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7689,10 +7477,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7702,7 +7490,7 @@ FROM pub struct RowSpaceQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::RowSpace, mapper: fn(super::RowSpace) -> T, } @@ -7717,24 +7505,24 @@ FROM RowSpaceQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7744,10 +7532,10 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7757,7 +7545,7 @@ FROM pub struct TypeofQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::TypeofBorrowed, mapper: fn(super::TypeofBorrowed) -> T, } @@ -7772,24 +7560,24 @@ FROM TypeofQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7799,29 +7587,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn select_compact<'a, C: GenericClient>(client: &'a C) -> SelectCompactStmt<'a, C> { - SelectCompactStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM clone"), - ) + pub fn select_compact() -> SelectCompactStmt { + SelectCompactStmt("SELECT * FROM clone") } - pub struct SelectCompactStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectCompactStmt(&'static str); + impl SelectCompactStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7829,27 +7612,22 @@ FROM 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_spaced<'a, C: GenericClient>(client: &'a C) -> SelectSpacedStmt<'a, C> { - SelectSpacedStmt( - client, - cornucopia_async::private::Stmt::new(" SELECT * FROM clone "), - ) + pub fn select_spaced() -> SelectSpacedStmt { + SelectSpacedStmt(" SELECT * FROM clone ") } - pub struct SelectSpacedStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectSpacedStmt(&'static str); + impl SelectSpacedStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, ) -> PublicCloneCompositeQuery< 'a, C, @@ -7857,38 +7635,31 @@ FROM 0, > { PublicCloneCompositeQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn implicit_compact<'a, C: GenericClient>( - client: &'a C, - ) -> ImplicitCompactStmt<'a, C> { + pub fn implicit_compact() -> ImplicitCompactStmt { ImplicitCompactStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct ImplicitCompactStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> ImplicitCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct ImplicitCompactStmt(&'static str); + impl ImplicitCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -7899,39 +7670,34 @@ FROM 'a, super::ImplicitCompactParams, Optioni32Query<'a, C, Option, 2>, - > for ImplicitCompactStmt<'a, C> + C, + > for ImplicitCompactStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::ImplicitCompactParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn implicit_spaced<'a, C: GenericClient>( - client: &'a C, - ) -> ImplicitSpacedStmt<'a, C> { + pub fn implicit_spaced() -> ImplicitSpacedStmt { ImplicitSpacedStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct ImplicitSpacedStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> ImplicitSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct ImplicitSpacedStmt(&'static str); + impl ImplicitSpacedStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a Option, price: &'a Option, ) -> Optioni32Query<'a, C, Option, 2> { Optioni32Query { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it, } @@ -7942,75 +7708,68 @@ FROM 'a, super::ImplicitSpacedParams, Optioni32Query<'a, C, Option, 2>, - > for ImplicitSpacedStmt<'a, C> + C, + > for ImplicitSpacedStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::ImplicitSpacedParams, ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn named_compact<'a, C: GenericClient>(client: &'a C) -> NamedCompactStmt<'a, C> { + pub fn named_compact() -> NamedCompactStmt { NamedCompactStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NamedCompactStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NamedCompactStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NamedCompactStmt(&'static str); + impl NamedCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a T1, price: &'a f64, ) -> RowQuery<'a, C, super::Row, 2> { RowQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } } } impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>> - for NamedCompactStmt<'a, C> + cornucopia_async::Params<'a, super::Params, RowQuery<'a, C, super::Row, 2>, C> + for NamedCompactStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::Params, ) -> RowQuery<'a, C, super::Row, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn named_spaced<'a, C: GenericClient>(client: &'a C) -> NamedSpacedStmt<'a, C> { + pub fn named_spaced() -> NamedSpacedStmt { NamedSpacedStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", - ), + "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", ) } - pub struct NamedSpacedStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> NamedSpacedStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct NamedSpacedStmt(&'static str); + impl NamedSpacedStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, name: &'a T1, price: &'a f64, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { RowSpaceQuery { - client: self.0, + client, params: [name, price], - stmt: &mut self.1, + query: self.0, extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -8021,27 +7780,30 @@ FROM 'a, super::ParamsSpace, RowSpaceQuery<'a, C, super::RowSpace, 2>, - > for NamedSpacedStmt<'a, C> + C, + > for NamedSpacedStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::ParamsSpace, ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { - self.bind(¶ms.name, ¶ms.price) + self.bind(client, ¶ms.name, ¶ms.price) } } - pub fn tricky_sql<'a, C: GenericClient>(client: &'a C) -> TrickySqlStmt<'a, C> { - TrickySqlStmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)")) + pub fn tricky_sql() -> TrickySqlStmt { + TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)") } - pub struct TrickySqlStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySqlStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySqlStmt(&'static str); + impl TrickySqlStmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8055,10 +7817,12 @@ FROM + 'a, >, >, - > for TrickySqlStmt<'a, C> + C, + > for TrickySqlStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySqlParams, ) -> std::pin::Pin< Box< @@ -8067,21 +7831,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql1<'a, C: GenericClient>(client: &'a C) -> TrickySql1Stmt<'a, C> { - TrickySql1Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)")) + pub fn tricky_sql1() -> TrickySql1Stmt { + TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)") } - pub struct TrickySql1Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql1Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql1Stmt(&'static str); + impl TrickySql1Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8095,10 +7860,12 @@ FROM + 'a, >, >, - > for TrickySql1Stmt<'a, C> + C, + > for TrickySql1Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql1Params, ) -> std::pin::Pin< Box< @@ -8107,21 +7874,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql2<'a, C: GenericClient>(client: &'a C) -> TrickySql2Stmt<'a, C> { - TrickySql2Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql2() -> TrickySql2Stmt { + TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)") } - pub struct TrickySql2Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql2Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql2Stmt(&'static str); + impl TrickySql2Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8135,10 +7903,12 @@ FROM + 'a, >, >, - > for TrickySql2Stmt<'a, C> + C, + > for TrickySql2Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql2Params, ) -> std::pin::Pin< Box< @@ -8147,21 +7917,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql3<'a, C: GenericClient>(client: &'a C) -> TrickySql3Stmt<'a, C> { - TrickySql3Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)")) + pub fn tricky_sql3() -> TrickySql3Stmt { + TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)") } - pub struct TrickySql3Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql3Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql3Stmt(&'static str); + impl TrickySql3Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8175,10 +7946,12 @@ FROM + 'a, >, >, - > for TrickySql3Stmt<'a, C> + C, + > for TrickySql3Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql3Params, ) -> std::pin::Pin< Box< @@ -8187,21 +7960,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql4<'a, C: GenericClient>(client: &'a C) -> TrickySql4Stmt<'a, C> { - TrickySql4Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)")) + pub fn tricky_sql4() -> TrickySql4Stmt { + TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)") } - pub struct TrickySql4Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql4Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql4Stmt(&'static str); + impl TrickySql4Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8215,10 +7989,12 @@ FROM + 'a, >, >, - > for TrickySql4Stmt<'a, C> + C, + > for TrickySql4Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql4Params, ) -> std::pin::Pin< Box< @@ -8227,21 +8003,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql6<'a, C: GenericClient>(client: &'a C) -> TrickySql6Stmt<'a, C> { - TrickySql6Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)")) + pub fn tricky_sql6() -> TrickySql6Stmt { + TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)") } - pub struct TrickySql6Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql6Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql6Stmt(&'static str); + impl TrickySql6Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8255,10 +8032,12 @@ FROM + 'a, >, >, - > for TrickySql6Stmt<'a, C> + C, + > for TrickySql6Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql6Params, ) -> std::pin::Pin< Box< @@ -8267,21 +8046,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql7<'a, C: GenericClient>(client: &'a C) -> TrickySql7Stmt<'a, C> { - TrickySql7Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)")) + pub fn tricky_sql7() -> TrickySql7Stmt { + TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)") } - pub struct TrickySql7Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql7Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql7Stmt(&'static str); + impl TrickySql7Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8295,10 +8075,12 @@ FROM + 'a, >, >, - > for TrickySql7Stmt<'a, C> + C, + > for TrickySql7Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql7Params, ) -> std::pin::Pin< Box< @@ -8307,21 +8089,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql8<'a, C: GenericClient>(client: &'a C) -> TrickySql8Stmt<'a, C> { - TrickySql8Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql8() -> TrickySql8Stmt { + TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)") } - pub struct TrickySql8Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql8Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql8Stmt(&'static str); + impl TrickySql8Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8335,10 +8118,12 @@ FROM + 'a, >, >, - > for TrickySql8Stmt<'a, C> + C, + > for TrickySql8Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql8Params, ) -> std::pin::Pin< Box< @@ -8347,21 +8132,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql9<'a, C: GenericClient>(client: &'a C) -> TrickySql9Stmt<'a, C> { - TrickySql9Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)")) + pub fn tricky_sql9() -> TrickySql9Stmt { + TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)") } - pub struct TrickySql9Stmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> TrickySql9Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql9Stmt(&'static str); + impl TrickySql9Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8375,10 +8161,12 @@ FROM + 'a, >, >, - > for TrickySql9Stmt<'a, C> + C, + > for TrickySql9Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql9Params, ) -> std::pin::Pin< Box< @@ -8387,24 +8175,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn tricky_sql10<'a, C: GenericClient>(client: &'a C) -> TrickySql10Stmt<'a, C> { - TrickySql10Stmt(client, cornucopia_async :: private :: Stmt :: new("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)")) + pub fn tricky_sql10() -> TrickySql10Stmt { + TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)") } - pub struct TrickySql10Stmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> TrickySql10Stmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct TrickySql10Stmt(&'static str); + impl TrickySql10Stmt { + pub async fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[r#async, r#enum]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8418,10 +8204,12 @@ FROM + 'a, >, >, - > for TrickySql10Stmt<'a, C> + C, + > for TrickySql10Stmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a super::TrickySql10Params, ) -> std::pin::Pin< Box< @@ -8430,22 +8218,22 @@ FROM + 'a, >, > { - Box::pin(self.bind(¶ms.r#async, ¶ms.r#enum)) + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) } } - pub fn r#typeof<'a, C: GenericClient>(client: &'a C) -> RTypeofStmt<'a, C> { - RTypeofStmt( - client, - cornucopia_async::private::Stmt::new("SELECT * FROM syntax"), - ) + pub fn r#typeof() -> RTypeofStmt { + RTypeofStmt("SELECT * FROM syntax") } - pub struct RTypeofStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> RTypeofStmt<'a, C> { - pub fn bind(&'a mut self) -> TypeofQuery<'a, C, super::Typeof, 0> { + pub struct RTypeofStmt(&'static str); + impl RTypeofStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> TypeofQuery<'a, C, super::Typeof, 0> { TypeofQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), diff --git a/codegen_test/src/main.rs b/codegen_test/src/main.rs index e1e0dcb1..8e5d3e5f 100644 --- a/codegen_test/src/main.rs +++ b/codegen_test/src/main.rs @@ -80,18 +80,18 @@ pub fn moving(_item: T) {} pub fn test_params(client: &mut Client) { assert_eq!( 1, - insert_book(client) - .bind(&None::<&str>, &"Necronomicon") + insert_book() + .bind(client, &None::<&str>, &"Necronomicon") .unwrap() ); assert_eq!( 1, - insert_book(client) - .bind(&Some("Marcel Proust"), &"In Search of Lost Time") + insert_book() + .bind(client, &Some("Marcel Proust"), &"In Search of Lost Time") .unwrap() ); assert_eq!( - select_book(client).bind().all().unwrap(), + select_book().bind(client).all().unwrap(), &[ SelectBook { author: None, @@ -103,61 +103,66 @@ pub fn test_params(client: &mut Client) { } ] ); - params_use_twice(client).bind(&"name").unwrap(); + params_use_twice().bind(client, &"name").unwrap(); } pub fn test_trait_sql(client: &mut Client) { let str = "hello world"; - insert_book(client).bind(&Some(str), &str).unwrap(); - find_books(client).bind(&[str].as_slice()).all().unwrap(); + insert_book().bind(client, &Some(str), &str).unwrap(); + find_books().bind(client, &[str].as_slice()).all().unwrap(); let string = str.to_string(); - insert_book(client) - .bind(&Some(string.clone()), &string) + insert_book() + .bind(client, &Some(string.clone()), &string) .unwrap(); - find_books(client) - .bind(&vec![string.clone()]) + find_books() + .bind(client, &vec![string.clone()]) .all() .unwrap(); - let boxed = string.into_boxed_str(); - insert_book(client) - .bind(&Some(boxed.clone()), &boxed) + let boxed = string.clone().into_boxed_str(); + insert_book() + .bind(client, &Some(boxed.clone()), &boxed) .unwrap(); - find_books(client).bind(&vec![boxed]).all().unwrap(); + find_books().bind(client, &vec![boxed]).all().unwrap(); let cow = Cow::Borrowed(str); - insert_book(client).bind(&Some(cow.clone()), &cow).unwrap(); - find_books(client).bind(&vec![cow]).all().unwrap(); + insert_book() + .bind(client, &Some(cow.clone()), &cow) + .unwrap(); + find_books().bind(client, &vec![cow]).all().unwrap(); let map: HashMap<&str, &str> = HashMap::from_iter([("one", "1"), ("two", "2"), ("three", "3")].into_iter()); // Old way with allocation let vec: Vec<_> = map.values().collect(); - find_books(client).bind(&vec.as_slice()).all().unwrap(); + find_books().bind(client, &vec.as_slice()).all().unwrap(); // A little more ergonomic - find_books(client).bind(&vec).all().unwrap(); + find_books().bind(client, &vec).all().unwrap(); // Zero allocation - find_books(client) - .bind(&IterSql(|| map.values())) + find_books() + .bind(client, &IterSql(|| map.values())) .all() .unwrap(); } pub fn test_nullity(client: &mut Client) { - new_nullity(client) - .params(&NullityParams { - composite: Some(NullityCompositeParams { - jsons: Some(&[None]), - id: 42, - }), - name: "James Bond", - texts: [Some("Hello"), Some("world"), None].as_slice(), - }) + new_nullity() + .params( + client, + &NullityParams { + composite: Some(NullityCompositeParams { + jsons: Some(&[None]), + id: 42, + }), + name: "James Bond", + texts: [Some("Hello"), Some("world"), None].as_slice(), + }, + ) .unwrap(); assert_eq!( - nullity(client).bind().one().unwrap(), + nullity().bind(client).one().unwrap(), Nullity { composite: Some(NullityComposite { jsons: Some(vec![None]), @@ -170,29 +175,35 @@ pub fn test_nullity(client: &mut Client) { } pub fn test_named(client: &mut Client) { - let hidden_id = new_named_hidden(client) - .params(&NamedParams { - name: "secret", - price: Some(42.0), - }) + let hidden_id = new_named_hidden() + .params( + client, + &NamedParams { + name: "secret", + price: Some(42.0), + }, + ) .one() .unwrap() .id; - let visible_id = new_named_visible(client) - .params(&NamedParams { - name: "stuff", - price: Some(84.0), - }) + let visible_id = new_named_visible() + .params( + client, + &NamedParams { + name: "stuff", + price: Some(84.0), + }, + ) .one() .unwrap() .id; - let last_id = new_named_visible(client) - .bind(&"can't by me", &None) + let last_id = new_named_visible() + .bind(client, &"can't by me", &None) .one() .unwrap() .id; assert_eq!( - named(client).bind().all().unwrap(), + named().bind(client).all().unwrap(), &[ Named { id: hidden_id, @@ -215,7 +226,7 @@ pub fn test_named(client: &mut Client) { ] ); assert_eq!( - named_by_id(client).bind(&hidden_id).one().unwrap(), + named_by_id().bind(client, &hidden_id).one().unwrap(), Named { id: hidden_id, name: "secret".into(), @@ -224,7 +235,7 @@ pub fn test_named(client: &mut Client) { } ); assert_eq!( - named_by_id(client).bind(&visible_id).one().unwrap(), + named_by_id().bind(client, &visible_id).one().unwrap(), Named { id: visible_id, name: "stuff".into(), @@ -233,34 +244,40 @@ pub fn test_named(client: &mut Client) { } ); assert_eq!( - named(client).bind().map(|it| it.id).all().unwrap(), + named().bind(client).map(|it| it.id).all().unwrap(), &[hidden_id, visible_id, last_id] ); - new_named_complex(client) - .params(&NamedComplexParams { - named: NamedCompositeBorrowed { - wow: Some("Hello world"), - such_cool: None, + new_named_complex() + .params( + client, + &NamedComplexParams { + named: NamedCompositeBorrowed { + wow: Some("Hello world"), + such_cool: None, + }, + named_with_dot: Some(NamedCompositeWithDot { + this_is_inconceivable: Some(EnumWithDot::variant_with_dot), + }), }, - named_with_dot: Some(NamedCompositeWithDot { - this_is_inconceivable: Some(EnumWithDot::variant_with_dot), - }), - }) + ) .unwrap(); - new_named_complex(client) - .params(&NamedComplexParams { - named: NamedCompositeBorrowed { - wow: Some("Hello world, again"), - such_cool: None, + new_named_complex() + .params( + client, + &NamedComplexParams { + named: NamedCompositeBorrowed { + wow: Some("Hello world, again"), + such_cool: None, + }, + named_with_dot: None, }, - named_with_dot: None, - }) + ) .unwrap(); assert_eq!( - named_complex(client).bind().all().unwrap(), + named_complex().bind(client).all().unwrap(), vec![ NamedComplex { named: NamedComposite { @@ -290,8 +307,8 @@ pub fn test_copy(client: &mut Client) { second: 4.2, }; moving(copy_params); // Ignore if copied - insert_copy(client).bind(©_params).unwrap(); - let copy_row = select_copy(client).bind().one().unwrap(); + insert_copy().bind(client, ©_params).unwrap(); + let copy_row = select_copy().bind(client).one().unwrap(); moving(copy_row); // Ignore if copied moving(copy_row); @@ -300,8 +317,8 @@ pub fn test_copy(client: &mut Client) { first: 42, second: "Hello world", }; - insert_clone(client).bind(&clone_params).unwrap(); - select_copy(client).bind().one().unwrap(); + insert_clone().bind(client, &clone_params).unwrap(); + select_copy().bind(client).one().unwrap(); } // Test domain erasing @@ -328,8 +345,11 @@ pub fn test_domain(client: &mut Client) { nb: 42, txt: "Hello world".to_string(), }; - assert_eq!(1, insert_nightmare_domain(client).params(¶ms).unwrap()); - let actual = select_nightmare_domain(client).bind().one().unwrap(); + assert_eq!( + 1, + insert_nightmare_domain().params(client, ¶ms).unwrap() + ); + let actual = select_nightmare_domain().bind(client).one().unwrap(); assert_eq!(expected, actual); let expected = SelectNightmareDomainNull { arr: Some(vec![Some(json.clone())]), @@ -343,7 +363,7 @@ pub fn test_domain(client: &mut Client) { txt: "Hello world".to_string(), }), }; - let actual = select_nightmare_domain_null(client).bind().one().unwrap(); + let actual = select_nightmare_domain_null().bind(client).one().unwrap(); assert_eq!(expected, actual); } @@ -433,8 +453,8 @@ pub fn test_stress(client: &mut Client) { varchar_: &expected.varchar_, numeric_: Decimal::new(202, 2), }; - assert_eq!(1, insert_everything(client).params(¶ms).unwrap()); - let actual = select_everything(client).bind().one().unwrap(); + assert_eq!(1, insert_everything().params(client, ¶ms).unwrap()); + let actual = select_everything().bind(client).one().unwrap(); assert_eq!(expected, actual); // Every supported array type @@ -510,8 +530,11 @@ pub fn test_stress(client: &mut Client) { varchar_: txt, numeric_: &expected.numeric_, }; - assert_eq!(1, insert_everything_array(client).params(¶ms).unwrap()); - let actual = select_everything_array(client).bind().one().unwrap(); + assert_eq!( + 1, + insert_everything_array().params(client, ¶ms).unwrap() + ); + let actual = select_everything_array().bind(client).one().unwrap(); assert_eq!(expected, actual); // Complex mix of enum, domain and composite types @@ -534,8 +557,8 @@ pub fn test_stress(client: &mut Client) { domain: "Hello", }; - assert_eq!(1, insert_nightmare(client).bind(¶ms).unwrap()); - let actual = select_nightmare(client).bind().one().unwrap(); + assert_eq!(1, insert_nightmare().bind(client, ¶ms).unwrap()); + let actual = select_nightmare().bind(client).one().unwrap(); assert_eq!(expected, actual); } @@ -545,6 +568,6 @@ pub fn test_keyword_escaping(client: &mut Client) { r#async: SyntaxComposite { r#async: 34 }, r#enum: SyntaxEnum::r#box, }; - tricky_sql10(client).params(¶ms).unwrap(); - r#typeof(client).bind().all().unwrap(); + tricky_sql10().params(client, ¶ms).unwrap(); + r#typeof().bind(client).all().unwrap(); } diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index 9210ff4b..56168294 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -425,7 +425,7 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { pub struct ${name}Query<'a, C: GenericClient, T, const N: usize> { client: &'a $client_mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut $client::private::Stmt, + query: &'static str, extractor: fn(&$backend::Row) -> $row_struct, mapper: fn($row_struct) -> T, } @@ -434,15 +434,15 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { ${name}Query { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub $fn_async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)$fn_await?; - let row = self.client.query_one(stmt, &self.params)$fn_await?; + let stmt = self.client.prepare(self.query)$fn_await?; + let row = self.client.query_one(&stmt, &self.params)$fn_await?; Ok((self.mapper)((self.extractor)(&row))) } @@ -451,10 +451,10 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { } pub $fn_async fn opt(self) -> Result, $backend::Error> { - let stmt = self.stmt.prepare(self.client)$fn_await?; + let stmt = self.client.prepare(self.query)$fn_await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) $fn_await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -462,10 +462,10 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { pub $fn_async fn iter( self, ) -> Result> + 'a, $backend::Error> { - let stmt = self.stmt.prepare(self.client)$fn_await?; + let stmt = self.client.prepare(self.query)$fn_await?; let it = self .client - .query_raw(stmt, $client::private::slice_iter(&self.params)) + .query_raw(&stmt, $client::private::slice_iter(&self.params)) $fn_await? $raw_pre .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) @@ -547,11 +547,11 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu ) }; code!(w => - pub fn bind<$($traits_idx: $traits,)>(&'a mut self, $($params_name: &'a $params_ty,) ) -> ${row_name}Query<'a,C, $row_struct_name, $nb_params> { + pub fn bind<'a, C: GenericClient, $($traits_idx: $traits,)>(&'a self, client: &'a $client_mut C, $($params_name: &'a $params_ty,) ) -> ${row_name}Query<'a,C, $row_struct_name, $nb_params> { ${row_name}Query { - client: self.0, + client, params: [$($params_name,)], - stmt: &mut self.1, + query: self.0, extractor: |row| { $!extractor }, mapper: |it| { $mapper }, } @@ -564,9 +564,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu p.ty.sql_wrapped(&p.ident.rs, ctx) }); code!(w => - pub $fn_async fn bind<$($traits_idx: $traits,)>(&'a mut self, $($params_name: &'a $params_ty,)) -> Result { - let stmt = self.1.prepare(self.0)$fn_await?; - self.0.execute(stmt, &[ $($params_wrap,) ])$fn_await + pub $fn_async fn bind<'a, C: GenericClient, $($traits_idx: $traits,)>(&'a self, client: &'a $client_mut C, $($params_name: &'a $params_ty,)) -> Result { + let stmt = client.prepare(self.0)$fn_await?; + client.execute(&stmt, &[ $($params_wrap,) ])$fn_await } ); } @@ -576,11 +576,11 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu let sql = sql.replace('"', "\\\""); // Rust string format escaping let name = &ident.rs; code!(w => - pub fn $name<'a, C: GenericClient>(client: &'a$client_mut C) -> ${struct_name}Stmt<'a, C> { - ${struct_name}Stmt(client, $client::private::Stmt::new("$sql")) + pub fn $name() -> ${struct_name}Stmt { + ${struct_name}Stmt("$sql") } - pub struct ${struct_name}Stmt<'a, C: GenericClient>(&'a$client_mut C, $client::private::Stmt); - impl <'a, C: GenericClient> ${struct_name}Stmt<'a, C> { + pub struct ${struct_name}Stmt(&'static str); + impl ${struct_name}Stmt { $!lazy_impl } ); @@ -605,9 +605,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu let name = &module.rows.get_index(*idx).unwrap().1.name; let nb_params = param_field.len(); code!(w => - impl <'a, C: GenericClient,$($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, ${name}Query<'a, C, $query_row_struct, $nb_params>> for ${struct_name}Stmt<'a, C> { - fn params(&'a mut self, params: &'a $param_path<$lifetime $($traits_idx,)>) -> ${name}Query<'a, C, $query_row_struct, $nb_params> { - self.bind($(¶ms.$params_name,)) + impl <'a, C: GenericClient,$($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, ${name}Query<'a, C, $query_row_struct, $nb_params>, C> for ${struct_name}Stmt { + fn params(&'a self, client: &'a $client_mut C, params: &'a $param_path<$lifetime $($traits_idx,)>) -> ${name}Query<'a, C, $query_row_struct, $nb_params> { + self.bind(client, $(¶ms.$params_name,)) } } ); @@ -624,9 +624,9 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu ("", "Result", "", "self", "") }; code!(w => - impl <'a, C: GenericClient $send_sync, $($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, $pre_ty$post_ty_lf> for ${struct_name}Stmt<'a, C> { - fn params(&'a mut self, params: &'a $param_path<$lifetime $($traits_idx,)>) -> $pre_ty$post_ty_lf { - $pre.bind($(¶ms.$params_name,))$post + impl <'a, C: GenericClient $send_sync, $($traits_idx: $traits,)> $client::Params<'a, $param_path<$lifetime $($traits_idx,)>, $pre_ty$post_ty_lf, C> for ${struct_name}Stmt { + fn params(&'a self, client: &'a $client_mut C, params: &'a $param_path<$lifetime $($traits_idx,)>) -> $pre_ty$post_ty_lf { + $pre.bind(client, $(¶ms.$params_name,))$post } } ); diff --git a/examples/auto_build/src/cornucopia.rs b/examples/auto_build/src/cornucopia.rs index d1aaf27b..74f050ec 100644 --- a/examples/auto_build/src/cornucopia.rs +++ b/examples/auto_build/src/cornucopia.rs @@ -17,7 +17,7 @@ pub mod queries { pub struct StringQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -29,24 +29,24 @@ pub mod queries { StringQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -56,34 +56,34 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn example_query<'a, C: GenericClient>(client: &'a C) -> ExampleQueryStmt<'a, C> { + pub fn example_query() -> ExampleQueryStmt { ExampleQueryStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM example_table", - ), ) } - pub struct ExampleQueryStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> ExampleQueryStmt<'a, C> { - pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { + pub struct ExampleQueryStmt(&'static str); + impl ExampleQueryStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> StringQuery<'a, C, String, 0> { StringQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } diff --git a/examples/auto_build/src/main.rs b/examples/auto_build/src/main.rs index 5372820c..ae6e8ff4 100644 --- a/examples/auto_build/src/main.rs +++ b/examples/auto_build/src/main.rs @@ -25,5 +25,5 @@ async fn main() { cfg.dbname = Some(String::from("postgres")); let pool = cfg.create_pool(Some(Runtime::Tokio1), NoTls).unwrap(); let client = pool.get().await.unwrap(); - example_query(&client).bind().all().await.unwrap(); + example_query().bind(&client).all().await.unwrap(); } diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index dcd50a2d..d4a9cdf1 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -212,23 +212,21 @@ pub mod queries { use cornucopia_async::GenericClient; use futures; use futures::{StreamExt, TryStreamExt}; - pub fn insert_book<'a, C: GenericClient>(client: &'a C) -> InsertBookStmt<'a, C> { + pub fn insert_book() -> InsertBookStmt { InsertBookStmt( - client, - cornucopia_async::private::Stmt::new( - "INSERT INTO Book (title) + "INSERT INTO Book (title) VALUES ($1)", - ), ) } - pub struct InsertBookStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> InsertBookStmt<'a, C> { - pub async fn bind( - &'a mut self, + pub struct InsertBookStmt(&'static str); + impl InsertBookStmt { + pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, title: &'a T1, ) -> Result { - let stmt = self.1.prepare(self.0).await?; - self.0.execute(stmt, &[title]).await + let stmt = client.prepare(self.0).await?; + client.execute(&stmt, &[title]).await } } } @@ -315,7 +313,7 @@ pub mod queries { pub struct AuthorsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> AuthorsBorrowed, mapper: fn(AuthorsBorrowed) -> T, } @@ -327,24 +325,24 @@ pub mod queries { AuthorsQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -354,10 +352,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -367,7 +365,7 @@ pub mod queries { pub struct StringQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -379,24 +377,24 @@ pub mod queries { StringQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -406,10 +404,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -419,7 +417,7 @@ pub mod queries { pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> AuthorNameStartingWithBorrowed, mapper: fn(AuthorNameStartingWithBorrowed) -> T, } @@ -434,24 +432,24 @@ pub mod queries { AuthorNameStartingWithQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -461,10 +459,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -474,7 +472,7 @@ pub mod queries { pub struct PublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } @@ -489,24 +487,24 @@ pub mod queries { PublicVoiceactorQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -516,10 +514,10 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -529,7 +527,7 @@ pub mod queries { pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_async::private::Stmt, + query: &'static str, extractor: fn(&tokio_postgres::Row) -> SelectTranslationsBorrowed, mapper: fn(SelectTranslationsBorrowed) -> T, } @@ -544,24 +542,24 @@ pub mod queries { SelectTranslationsQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client).await?; - let row = self.client.query_one(stmt, &self.params).await?; + let stmt = self.client.prepare(self.query).await?; + let row = self.client.query_one(&stmt, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(stmt, &self.params) + .query_opt(&stmt, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -571,34 +569,34 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.stmt.prepare(self.client).await?; + let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); Ok(it) } } - pub fn authors<'a, C: GenericClient>(client: &'a C) -> AuthorsStmt<'a, C> { + pub fn authors() -> AuthorsStmt { AuthorsStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT * FROM Author", - ), ) } - pub struct AuthorsStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> AuthorsStmt<'a, C> { - pub fn bind(&'a mut self) -> AuthorsQuery<'a, C, Authors, 0> { + pub struct AuthorsStmt(&'static str); + impl AuthorsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> AuthorsQuery<'a, C, Authors, 0> { AuthorsQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -608,61 +606,58 @@ FROM } } } - pub fn books<'a, C: GenericClient>(client: &'a C) -> BooksStmt<'a, C> { + pub fn books() -> BooksStmt { BooksStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT Title FROM Book", - ), ) } - pub struct BooksStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> BooksStmt<'a, C> { - pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { + pub struct BooksStmt(&'static str); + impl BooksStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> StringQuery<'a, C, String, 0> { StringQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_by_id<'a, C: GenericClient>(client: &'a C) -> AuthorNameByIdStmt<'a, C> { + pub fn author_name_by_id() -> AuthorNameByIdStmt { AuthorNameByIdStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT Author.Name FROM Author WHERE Author.Id = $1", - ), ) } - pub struct AuthorNameByIdStmt<'a, C: GenericClient>(&'a C, cornucopia_async::private::Stmt); - impl<'a, C: GenericClient> AuthorNameByIdStmt<'a, C> { - pub fn bind(&'a mut self, id: &'a i32) -> StringQuery<'a, C, String, 1> { + pub struct AuthorNameByIdStmt(&'static str); + impl AuthorNameByIdStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + id: &'a i32, + ) -> StringQuery<'a, C, String, 1> { StringQuery { - client: self.0, + client, params: [id], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_starting_with<'a, C: GenericClient>( - client: &'a C, - ) -> AuthorNameStartingWithStmt<'a, C> { + pub fn author_name_starting_with() -> AuthorNameStartingWithStmt { AuthorNameStartingWithStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT BookAuthor.AuthorId, Author.Name, BookAuthor.BookId, @@ -673,22 +668,19 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", - ), ) } - pub struct AuthorNameStartingWithStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> AuthorNameStartingWithStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct AuthorNameStartingWithStmt(&'static str); + impl AuthorNameStartingWithStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a self, + client: &'a C, start_str: &'a T1, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { AuthorNameStartingWithQuery { - client: self.0, + client, params: [start_str], - stmt: &mut self.1, + query: self.0, extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -704,73 +696,63 @@ WHERE 'a, AuthorNameStartingWithParams, AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1>, - > for AuthorNameStartingWithStmt<'a, C> + C, + > for AuthorNameStartingWithStmt { fn params( - &'a mut self, + &'a self, + client: &'a C, params: &'a AuthorNameStartingWithParams, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { - self.bind(¶ms.start_str) + self.bind(client, ¶ms.start_str) } } - pub fn select_voice_actor_with_character<'a, C: GenericClient>( - client: &'a C, - ) -> SelectVoiceActorWithCharacterStmt<'a, C> { + pub fn select_voice_actor_with_character() -> SelectVoiceActorWithCharacterStmt { SelectVoiceActorWithCharacterStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT voice_actor FROM SpongeBobVoiceActor WHERE character = $1", - ), ) } - pub struct SelectVoiceActorWithCharacterStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectVoiceActorWithCharacterStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectVoiceActorWithCharacterStmt(&'static str); + impl SelectVoiceActorWithCharacterStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> { PublicVoiceactorQuery { - client: self.0, + client, params: [spongebob_character], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_translations<'a, C: GenericClient>( - client: &'a C, - ) -> SelectTranslationsStmt<'a, C> { + pub fn select_translations() -> SelectTranslationsStmt { SelectTranslationsStmt( - client, - cornucopia_async::private::Stmt::new( - "SELECT + "SELECT Title, Translations FROM Book", - ), ) } - pub struct SelectTranslationsStmt<'a, C: GenericClient>( - &'a C, - cornucopia_async::private::Stmt, - ); - impl<'a, C: GenericClient> SelectTranslationsStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { + pub struct SelectTranslationsStmt(&'static str); + impl SelectTranslationsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a C, + ) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { SelectTranslationsQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), diff --git a/examples/basic_async/src/main.rs b/examples/basic_async/src/main.rs index a0cf4192..cd535ed8 100644 --- a/examples/basic_async/src/main.rs +++ b/examples/basic_async/src/main.rs @@ -21,31 +21,34 @@ pub async fn main() { let mut client = pool.get().await.unwrap(); // The `all` method returns queried rows collected into a `Vec` - let authors = authors(&client).bind().all().await.unwrap(); + let authors = authors().bind(&client).all().await.unwrap(); dbg!(authors); // Queries also accept transactions. Let's see how that works. { // Once you've created a transaction, you can pass it to your queries // just like you would with a regular query. Nothing special to do. - let tx = client.transaction().await.unwrap(); + let transaction = client.transaction().await.unwrap(); // Insertions work just like any other query. // Note that queries with a void return type (such as regular insertions) // are executed as soon as you `bind` their parameters. - insert_book(&tx).bind(&"The Great Gatsby").await.unwrap(); + insert_book() + .bind(&transaction, &"The Great Gatsby") + .await + .unwrap(); // Bind parameters are "smart". A query that expects a `&str` will also accept other // "string-like" types like `String`. See https://cornucopia-rs.netlify.app/book/using_queries/ergonomic_parameters.html // for more details. - insert_book(&tx) - .bind(&String::from("Moby Dick")) + insert_book() + .bind(&transaction, &String::from("Moby Dick")) .await .unwrap(); // You can use a `map` to transform query results ergonomically. - let uppercase_books = books(&tx) - .bind() + let uppercase_books = books() + .bind(&transaction) .map(|book_title| book_title.to_uppercase()) .all() .await @@ -54,12 +57,12 @@ pub async fn main() { // Don't forget to `commit` when you're done with the transaction! // Otherwise, it will be rolled back without further effect. - tx.commit().await.unwrap(); + transaction.commit().await.unwrap(); } // Using `opt` returns an optional row (zero or one). // Any other number of rows will return an error. - let author_name = author_name_by_id(&client).bind(&0).opt().await.unwrap(); + let author_name = author_name_by_id().bind(&client, &0).opt().await.unwrap(); dbg!(author_name); // Using named structs as parameters and rows can be more convenient @@ -73,8 +76,8 @@ pub async fn main() { // ! 2. Import the `Params` trait. println!( "{:?}", - author_name_starting_with(&client) - .params(&AuthorNameStartingWithParams { start_str: "Jo" }) + author_name_starting_with() + .params(&client, &AuthorNameStartingWithParams { start_str: "Jo" }) .all() .await .unwrap() @@ -85,8 +88,8 @@ pub async fn main() { // They will be automatically generated by Cornucopia. // You can use them as bind parameters (as shown here) // or receive them in returned rows. - let patrick_voice_actor = select_voice_actor_with_character(&client) - .bind(&SpongeBobCharacter::Patrick) + let patrick_voice_actor = select_voice_actor_with_character() + .bind(&client, &SpongeBobCharacter::Patrick) .one() .await .unwrap(); @@ -94,8 +97,8 @@ pub async fn main() { // Cornucopia also supports PostgreSQL arrays, which you // can use as bind parameters or in returned rows. - let translations = select_translations(&client) - .bind() + let translations = select_translations() + .bind(&client) .map(|row| format!("{}: {:?}", row.title, row.translations)) .all() .await diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index d947dd6f..7f886a6b 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -210,23 +210,21 @@ pub mod types { pub mod queries { pub mod module_1 { use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - pub fn insert_book<'a, C: GenericClient>(client: &'a mut C) -> InsertBookStmt<'a, C> { + pub fn insert_book() -> InsertBookStmt { InsertBookStmt( - client, - cornucopia_sync::private::Stmt::new( - "INSERT INTO Book (title) + "INSERT INTO Book (title) VALUES ($1)", - ), ) } - pub struct InsertBookStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> InsertBookStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct InsertBookStmt(&'static str); + impl InsertBookStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, title: &'a T1, ) -> Result { - let stmt = self.1.prepare(self.0)?; - self.0.execute(stmt, &[title]) + let stmt = client.prepare(self.0)?; + client.execute(&stmt, &[title]) } } } @@ -311,7 +309,7 @@ pub mod queries { pub struct AuthorsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> AuthorsBorrowed, mapper: fn(AuthorsBorrowed) -> T, } @@ -323,34 +321,34 @@ pub mod queries { AuthorsQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -359,7 +357,7 @@ pub mod queries { pub struct StringQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -371,34 +369,34 @@ pub mod queries { StringQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -407,7 +405,7 @@ pub mod queries { pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> AuthorNameStartingWithBorrowed, mapper: fn(AuthorNameStartingWithBorrowed) -> T, } @@ -422,34 +420,34 @@ pub mod queries { AuthorNameStartingWithQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -458,7 +456,7 @@ pub mod queries { pub struct PublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } @@ -473,34 +471,34 @@ pub mod queries { PublicVoiceactorQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -509,7 +507,7 @@ pub mod queries { pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], - stmt: &'a mut cornucopia_sync::private::Stmt, + query: &'static str, extractor: fn(&postgres::Row) -> SelectTranslationsBorrowed, mapper: fn(SelectTranslationsBorrowed) -> T, } @@ -524,57 +522,57 @@ pub mod queries { SelectTranslationsQuery { client: self.client, params: self.params, - stmt: self.stmt, + query: self.query, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let stmt = self.stmt.prepare(self.client)?; - let row = self.client.query_one(stmt, &self.params)?; + let stmt = self.client.prepare(self.query)?; + let row = self.client.query_one(&stmt, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(stmt, &self.params)? + .query_opt(&stmt, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.stmt.prepare(self.client)?; + let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) } } - pub fn authors<'a, C: GenericClient>(client: &'a mut C) -> AuthorsStmt<'a, C> { + pub fn authors() -> AuthorsStmt { AuthorsStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT * FROM Author", - ), ) } - pub struct AuthorsStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> AuthorsStmt<'a, C> { - pub fn bind(&'a mut self) -> AuthorsQuery<'a, C, Authors, 0> { + pub struct AuthorsStmt(&'static str); + impl AuthorsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> AuthorsQuery<'a, C, Authors, 0> { AuthorsQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -584,66 +582,58 @@ FROM } } } - pub fn books<'a, C: GenericClient>(client: &'a mut C) -> BooksStmt<'a, C> { + pub fn books() -> BooksStmt { BooksStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT Title FROM Book", - ), ) } - pub struct BooksStmt<'a, C: GenericClient>(&'a mut C, cornucopia_sync::private::Stmt); - impl<'a, C: GenericClient> BooksStmt<'a, C> { - pub fn bind(&'a mut self) -> StringQuery<'a, C, String, 0> { + pub struct BooksStmt(&'static str); + impl BooksStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> StringQuery<'a, C, String, 0> { StringQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_by_id<'a, C: GenericClient>( - client: &'a mut C, - ) -> AuthorNameByIdStmt<'a, C> { + pub fn author_name_by_id() -> AuthorNameByIdStmt { AuthorNameByIdStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT Author.Name FROM Author WHERE Author.Id = $1", - ), ) } - pub struct AuthorNameByIdStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> AuthorNameByIdStmt<'a, C> { - pub fn bind(&'a mut self, id: &'a i32) -> StringQuery<'a, C, String, 1> { + pub struct AuthorNameByIdStmt(&'static str); + impl AuthorNameByIdStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + id: &'a i32, + ) -> StringQuery<'a, C, String, 1> { StringQuery { - client: self.0, + client, params: [id], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn author_name_starting_with<'a, C: GenericClient>( - client: &'a mut C, - ) -> AuthorNameStartingWithStmt<'a, C> { + pub fn author_name_starting_with() -> AuthorNameStartingWithStmt { AuthorNameStartingWithStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT BookAuthor.AuthorId, Author.Name, BookAuthor.BookId, @@ -654,22 +644,19 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", - ), ) } - pub struct AuthorNameStartingWithStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> AuthorNameStartingWithStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct AuthorNameStartingWithStmt(&'static str); + impl AuthorNameStartingWithStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a self, + client: &'a mut C, start_str: &'a T1, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { AuthorNameStartingWithQuery { - client: self.0, + client, params: [start_str], - stmt: &mut self.1, + query: self.0, extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -685,73 +672,63 @@ WHERE 'a, AuthorNameStartingWithParams, AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1>, - > for AuthorNameStartingWithStmt<'a, C> + C, + > for AuthorNameStartingWithStmt { fn params( - &'a mut self, + &'a self, + client: &'a mut C, params: &'a AuthorNameStartingWithParams, ) -> AuthorNameStartingWithQuery<'a, C, AuthorNameStartingWith, 1> { - self.bind(¶ms.start_str) + self.bind(client, ¶ms.start_str) } } - pub fn select_voice_actor_with_character<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectVoiceActorWithCharacterStmt<'a, C> { + pub fn select_voice_actor_with_character() -> SelectVoiceActorWithCharacterStmt { SelectVoiceActorWithCharacterStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT voice_actor FROM SpongeBobVoiceActor WHERE character = $1", - ), ) } - pub struct SelectVoiceActorWithCharacterStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectVoiceActorWithCharacterStmt<'a, C> { - pub fn bind( - &'a mut self, + pub struct SelectVoiceActorWithCharacterStmt(&'static str); + impl SelectVoiceActorWithCharacterStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> { PublicVoiceactorQuery { - client: self.0, + client, params: [spongebob_character], - stmt: &mut self.1, + query: self.0, extractor: |row| row.get(0), mapper: |it| it.into(), } } } - pub fn select_translations<'a, C: GenericClient>( - client: &'a mut C, - ) -> SelectTranslationsStmt<'a, C> { + pub fn select_translations() -> SelectTranslationsStmt { SelectTranslationsStmt( - client, - cornucopia_sync::private::Stmt::new( - "SELECT + "SELECT Title, Translations FROM Book", - ), ) } - pub struct SelectTranslationsStmt<'a, C: GenericClient>( - &'a mut C, - cornucopia_sync::private::Stmt, - ); - impl<'a, C: GenericClient> SelectTranslationsStmt<'a, C> { - pub fn bind(&'a mut self) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { + pub struct SelectTranslationsStmt(&'static str); + impl SelectTranslationsStmt { + pub fn bind<'a, C: GenericClient>( + &'a self, + client: &'a mut C, + ) -> SelectTranslationsQuery<'a, C, SelectTranslations, 0> { SelectTranslationsQuery { - client: self.0, + client, params: [], - stmt: &mut self.1, + query: self.0, extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), diff --git a/examples/basic_sync/src/main.rs b/examples/basic_sync/src/main.rs index 062981cc..b8dc4176 100644 --- a/examples/basic_sync/src/main.rs +++ b/examples/basic_sync/src/main.rs @@ -20,30 +20,32 @@ pub fn main() { let mut client = get_client().unwrap(); // The `all` method returns queried rows collected into a `Vec` - let authors = authors(&mut client).bind().all().unwrap(); + let authors = authors().bind(&mut client).all().unwrap(); dbg!(authors); // Queries also accept transactions. Let's see how that works. { // Once you've created a transaction, you can pass it to your queries // just like you would with a regular query. Nothing special to do. - let mut tx = client.transaction().unwrap(); + let mut transaction = client.transaction().unwrap(); // Insertions work just like any other query. // Note that queries with a void return type (such as regular insertions) // are executed as soon as you `bind` their parameters. - insert_book(&mut tx).bind(&"The Great Gatsby").unwrap(); + insert_book() + .bind(&mut transaction, &"The Great Gatsby") + .unwrap(); // Bind parameters are "smart". A query that expects a `&str` will also accept other // "string-like" types like `String`. See https://cornucopia-rs.netlify.app/book/using_queries/ergonomic_parameters.html // for more details. - insert_book(&mut tx) - .bind(&String::from("Moby Dick")) + insert_book() + .bind(&mut transaction, &String::from("Moby Dick")) .unwrap(); // You can use a `map` to transform query results ergonomically. - let uppercase_books = books(&mut tx) - .bind() + let uppercase_books = books() + .bind(&mut transaction) .map(|book_title| book_title.to_uppercase()) .all() .unwrap(); @@ -51,12 +53,12 @@ pub fn main() { // Don't forget to `commit` when you're done with the transaction! // Otherwise, it will be rolled back without further effect. - tx.commit().unwrap(); + transaction.commit().unwrap(); } // Using `opt` returns an optional row (zero or one). // Any other number of rows will return an error. - let author_name = author_name_by_id(&mut client).bind(&0).opt().unwrap(); + let author_name = author_name_by_id().bind(&mut client, &0).opt().unwrap(); dbg!(author_name); // Using named structs as parameters and rows can be more convenient @@ -68,8 +70,11 @@ pub fn main() { // ! general information and the `queries/module_2.sql` file to see how this particular // ! parameter type was created). // ! 2. Import the `Params` trait. - let name_starting_with_jo = author_name_starting_with(&mut client) - .params(&AuthorNameStartingWithParams { start_str: "Jo" }) + let name_starting_with_jo = author_name_starting_with() + .params( + &mut client, + &AuthorNameStartingWithParams { start_str: "Jo" }, + ) .all() .unwrap(); dbg!(name_starting_with_jo); @@ -79,16 +84,16 @@ pub fn main() { // They will be automatically generated by Cornucopia. // You can use them as bind parameters (as shown here) // or receive them in returned rows. - let patrick_voice_actor = select_voice_actor_with_character(&mut client) - .bind(&SpongeBobCharacter::Patrick) + let patrick_voice_actor = select_voice_actor_with_character() + .bind(&mut client, &SpongeBobCharacter::Patrick) .one() .unwrap(); dbg!(patrick_voice_actor); // Cornucopia also supports PostgreSQL arrays, which you // can use as bind parameters or in returned rows. - let translations = select_translations(&mut client) - .bind() + let translations = select_translations() + .bind(&mut client) .map(|row| format!("{}: {:?}", row.title, row.translations)) .all() .unwrap(); From 11c82f01b33b856c94d9e3a5ea0267a9101627e7 Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 02:20:54 +0100 Subject: [PATCH 3/7] Implicit prepare only when cached --- bench/usage/cornucopia_benches/generated.rs | 102 ++-- clients/async/src/deadpool.rs | 110 ++-- clients/async/src/generic_client.rs | 139 ++--- codegen_test/src/cornucopia.rs | 606 +++++++++----------- cornucopia/src/codegen.rs | 12 +- examples/auto_build/src/cornucopia.rs | 12 +- examples/basic_async/src/cornucopia.rs | 63 +- examples/basic_sync/src/cornucopia.rs | 63 +- 8 files changed, 490 insertions(+), 617 deletions(-) diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs index d50baa4e..d42e56f4 100644 --- a/bench/usage/cornucopia_benches/generated.rs +++ b/bench/usage/cornucopia_benches/generated.rs @@ -163,28 +163,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -214,28 +214,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -265,28 +265,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -316,28 +316,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -381,8 +381,7 @@ pub mod queries { name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[name, hair_color]) + client.execute(self.0, &[name, hair_color]) } } impl< @@ -553,18 +552,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -574,10 +571,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -608,18 +607,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -629,10 +626,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -663,18 +662,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -684,10 +681,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -718,18 +717,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -739,10 +736,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -787,8 +786,7 @@ pub mod queries { name: &'a T1, hair_color: &'a Option, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[name, hair_color]).await + client.execute(self.0, &[name, hair_color]).await } } impl< diff --git a/clients/async/src/deadpool.rs b/clients/async/src/deadpool.rs index 8d0a78cd..5feeb7c7 100644 --- a/clients/async/src/deadpool.rs +++ b/clients/async/src/deadpool.rs @@ -3,130 +3,100 @@ use deadpool_postgres::{ Client as DeadpoolClient, ClientWrapper, Transaction as DeadpoolTransaction, }; use tokio_postgres::{ - types::BorrowToSql, Client as PgClient, Error, RowStream, Statement, ToStatement, - Transaction as PgTransaction, + types::BorrowToSql, Client as PgClient, Error, RowStream, Transaction as PgTransaction, }; use crate::generic_client::GenericClient; #[async_trait] impl GenericClient for DeadpoolClient { - async fn prepare(&self, query: &str) -> Result { - ClientWrapper::prepare_cached(self, query).await - } - - async fn execute( + async fn execute( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgClient::execute(self, query, params).await + ) -> Result { + let stmt = ClientWrapper::prepare_cached(self, query).await?; + PgClient::execute(self, &stmt, params).await } - async fn query_one( + async fn query_one( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgClient::query_one(self, statement, params).await + ) -> Result { + let stmt = ClientWrapper::prepare_cached(self, query).await?; + PgClient::query_one(self, &stmt, params).await } - async fn query_opt( + async fn query_opt( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgClient::query_opt(self, statement, params).await + ) -> Result, Error> { + let stmt = ClientWrapper::prepare_cached(self, query).await?; + PgClient::query_opt(self, &stmt, params).await } - async fn query( + async fn query( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgClient::query(self, query, params).await + ) -> Result, Error> { + let stmt = ClientWrapper::prepare_cached(self, query).await?; + PgClient::query(self, &stmt, params).await } - async fn query_raw(&self, statement: &T, params: I) -> Result + async fn query_raw(&self, query: &str, params: I) -> Result where - T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - PgClient::query_raw(self, statement, params).await + let stmt = ClientWrapper::prepare_cached(self, query).await?; + PgClient::query_raw(self, &stmt, params).await } } #[async_trait] impl GenericClient for DeadpoolTransaction<'_> { - async fn prepare(&self, query: &str) -> Result { - DeadpoolTransaction::prepare_cached(self, query).await - } - - async fn execute( + async fn execute( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result { PgTransaction::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgTransaction::query_one(self, statement, params).await + ) -> Result { + PgTransaction::query_one(self, query, params).await } - async fn query_opt( + async fn query_opt( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - PgTransaction::query_opt(self, statement, params).await + ) -> Result, Error> { + PgTransaction::query_opt(self, query, params).await } - async fn query( + async fn query( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result, Error> { PgTransaction::query(self, query, params).await } - async fn query_raw(&self, statement: &T, params: I) -> Result + async fn query_raw(&self, query: &str, params: I) -> Result where - T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - PgTransaction::query_raw(self, statement, params).await + PgTransaction::query_raw(self, query, params).await } } diff --git a/clients/async/src/generic_client.rs b/clients/async/src/generic_client.rs index e0042c9b..3cd51156 100644 --- a/clients/async/src/generic_client.rs +++ b/clients/async/src/generic_client.rs @@ -1,7 +1,5 @@ use async_trait::async_trait; -use tokio_postgres::{ - types::BorrowToSql, Client, Error, RowStream, Statement, ToStatement, Transaction, -}; +use tokio_postgres::{types::BorrowToSql, Client, Error, RowStream, Transaction}; /// Abstraction over multiple types of asynchronous clients. /// This allows you to use tokio_postgres clients and transactions interchangeably. @@ -10,39 +8,28 @@ use tokio_postgres::{ /// abstracts over deadpool clients and transactions #[async_trait] pub trait GenericClient: Send + Sync { - async fn prepare(&self, query: &str) -> Result; - async fn execute( + async fn execute( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send; - async fn query_one( + ) -> Result; + async fn query_one( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send; - async fn query_opt( + ) -> Result; + async fn query_opt( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send; - async fn query( + ) -> Result, Error>; + async fn query( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> + ) -> Result, Error>; + async fn query_raw(&self, query: &str, params: I) -> Result where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send; - - async fn query_raw(&self, statement: &T, params: I) -> Result - where - T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator; @@ -50,122 +37,88 @@ pub trait GenericClient: Send + Sync { #[async_trait] impl GenericClient for Transaction<'_> { - async fn prepare(&self, query: &str) -> Result { - Transaction::prepare(self, query).await - } - - async fn execute( + async fn execute( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result { Transaction::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - Transaction::query_one(self, statement, params).await + ) -> Result { + Transaction::query_one(self, query, params).await } - async fn query_opt( + async fn query_opt( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - Transaction::query_opt(self, statement, params).await + ) -> Result, Error> { + Transaction::query_opt(self, query, params).await } - async fn query( + async fn query( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result, Error> { Transaction::query(self, query, params).await } - async fn query_raw(&self, statement: &T, params: I) -> Result + async fn query_raw(&self, query: &str, params: I) -> Result where - T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - Transaction::query_raw(self, statement, params).await + Transaction::query_raw(self, query, params).await } } #[async_trait] impl GenericClient for Client { - async fn prepare(&self, query: &str) -> Result { - Client::prepare(self, query).await - } - - async fn execute( + async fn execute( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result { Client::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - Client::query_one(self, statement, params).await + ) -> Result { + Client::query_one(self, query, params).await } - async fn query_opt( + async fn query_opt( &self, - statement: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { - Client::query_opt(self, statement, params).await + ) -> Result, Error> { + Client::query_opt(self, query, params).await } - async fn query( + async fn query( &self, - query: &T, + query: &str, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> - where - T: ?Sized + tokio_postgres::ToStatement + Sync + Send, - { + ) -> Result, Error> { Client::query(self, query, params).await } - async fn query_raw(&self, statement: &T, params: I) -> Result + async fn query_raw(&self, query: &str, params: I) -> Result where - T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - Client::query_raw(self, statement, params).await + Client::query_raw(self, query, params).await } } diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs index 911150d8..1cb42f23 100644 --- a/codegen_test/src/cornucopia.rs +++ b/codegen_test/src/cornucopia.rs @@ -1292,28 +1292,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1343,28 +1343,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1380,8 +1380,7 @@ pub mod queries { client: &'a mut C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[composite]) + client.execute(self.0, &[composite]) } } pub fn select_clone() -> SelectCloneStmt { @@ -1417,8 +1416,7 @@ pub mod queries { client: &'a mut C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[composite]) + client.execute(self.0, &[composite]) } } pub fn select_copy() -> SelectCopyStmt { @@ -1476,18 +1474,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -1497,10 +1493,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -1532,18 +1530,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -1553,10 +1549,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -1573,8 +1571,7 @@ pub mod queries { client: &'a C, composite: &'a super::super::super::types::public::CloneCompositeBorrowed<'a>, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[composite]).await + client.execute(self.0, &[composite]).await } } pub fn select_clone() -> SelectCloneStmt { @@ -1610,8 +1607,7 @@ pub mod queries { client: &'a C, composite: &'a super::super::super::types::public::CopyComposite, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[composite]).await + client.execute(self.0, &[composite]).await } } pub fn select_copy() -> SelectCopyStmt { @@ -1754,28 +1750,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1805,28 +1801,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -1879,9 +1875,8 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = client.prepare(self.0)?; client.execute( - &stmt, + self.0, &[ &cornucopia_sync::private::Domain(txt), &cornucopia_sync::private::Domain(json), @@ -1978,18 +1973,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -1999,10 +1992,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2033,18 +2028,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2054,10 +2047,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2111,10 +2106,9 @@ pub mod queries { super::super::super::types::public::DomainCompositeParams<'a>, >, ) -> Result { - let stmt = client.prepare(self.0).await?; client .execute( - &stmt, + self.0, &[ &cornucopia_async::private::Domain(txt), &cornucopia_async::private::Domain(json), @@ -2287,28 +2281,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -2338,28 +2332,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -2389,28 +2383,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -2546,8 +2540,7 @@ pub mod queries { super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[named, named_with_dot]) + client.execute(self.0, &[named, named_with_dot]) } } impl<'a, C: GenericClient> @@ -2613,18 +2606,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2634,10 +2625,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2668,18 +2661,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2689,10 +2680,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2723,18 +2716,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -2744,10 +2735,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -2892,8 +2885,7 @@ pub mod queries { super::super::super::types::public::NamedCompositeWithDot, >, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[named, named_with_dot]).await + client.execute(self.0, &[named, named_with_dot]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -3011,28 +3003,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -3058,8 +3050,7 @@ pub mod queries { super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[texts, name, composite]) + client.execute(self.0, &[texts, name, composite]) } } impl< @@ -3135,18 +3126,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3156,10 +3145,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -3186,8 +3177,7 @@ pub mod queries { super::super::super::types::public::NullityCompositeParams<'a>, >, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[texts, name, composite]).await + client.execute(self.0, &[texts, name, composite]).await } } impl< @@ -3322,28 +3312,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -3373,28 +3363,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -3416,8 +3406,7 @@ pub mod queries { author: &'a Option, name: &'a T2, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[author, name]) + client.execute(self.0, &[author, name]) } } impl< @@ -3501,8 +3490,7 @@ pub mod queries { client: &'a mut C, name: &'a T1, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[name]) + client.execute(self.0, &[name]) } } pub fn params_order() -> ParamsOrderStmt { @@ -3516,8 +3504,7 @@ pub mod queries { c: &'a i32, a: &'a i32, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[c, a]) + client.execute(self.0, &[c, a]) } } impl<'a, C: GenericClient> @@ -3565,18 +3552,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3586,10 +3571,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -3620,18 +3607,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -3641,10 +3626,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -3667,8 +3654,7 @@ pub mod queries { author: &'a Option, name: &'a T2, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[author, name]).await + client.execute(self.0, &[author, name]).await } } impl< @@ -3764,8 +3750,7 @@ pub mod queries { client: &'a C, name: &'a T1, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[name]).await + client.execute(self.0, &[name]).await } } pub fn params_order() -> ParamsOrderStmt { @@ -3779,8 +3764,7 @@ pub mod queries { c: &'a i32, a: &'a i32, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[c, a]).await + client.execute(self.0, &[c, a]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -4532,28 +4516,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4583,28 +4567,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4634,28 +4618,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4685,28 +4669,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4739,28 +4723,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -4934,9 +4918,8 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = client.prepare(self.0)?; client.execute( - &stmt, + self.0, &[ bool_, boolean_, @@ -5215,9 +5198,8 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = client.prepare(self.0)?; client.execute( - &stmt, + self.0, &[ bool_, boolean_, @@ -5442,8 +5424,7 @@ FROM client: &'a mut C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[composite]) + client.execute(self.0, &[composite]) } } } @@ -5475,18 +5456,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5496,10 +5475,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5530,18 +5511,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5551,10 +5530,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5585,18 +5566,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5606,10 +5585,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5640,18 +5621,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5661,10 +5640,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5698,18 +5679,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -5719,10 +5698,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -5897,10 +5878,9 @@ FROM macaddr_: &'a eui48::MacAddress, numeric_: &'a rust_decimal::Decimal, ) -> Result { - let stmt = client.prepare(self.0).await?; client .execute( - &stmt, + self.0, &[ bool_, boolean_, @@ -6192,10 +6172,9 @@ FROM macaddr_: &'a T32, numeric_: &'a T33, ) -> Result { - let stmt = client.prepare(self.0).await?; client .execute( - &stmt, + self.0, &[ bool_, boolean_, @@ -6433,8 +6412,7 @@ FROM client: &'a C, composite: &'a super::super::super::types::public::NightmareCompositeParams<'a>, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[composite]).await + client.execute(self.0, &[composite]).await } } } @@ -6573,28 +6551,28 @@ FROM } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6621,28 +6599,28 @@ FROM } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6669,28 +6647,28 @@ FROM } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6720,28 +6698,28 @@ FROM } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -6771,28 +6749,28 @@ FROM } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -7003,8 +6981,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7030,8 +7007,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7061,8 +7037,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7092,8 +7067,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7123,8 +7097,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7154,8 +7127,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7185,8 +7157,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7216,8 +7187,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7247,8 +7217,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7278,8 +7247,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[r#async, r#enum]) + client.execute(self.0, &[r#async, r#enum]) } } impl<'a, C: GenericClient> @@ -7352,18 +7320,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7373,10 +7339,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7404,18 +7372,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7425,10 +7391,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7456,18 +7424,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7477,10 +7443,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7511,18 +7479,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7532,10 +7498,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7566,18 +7534,16 @@ FROM } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -7587,10 +7553,12 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -7802,8 +7770,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7845,8 +7812,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7888,8 +7854,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7931,8 +7896,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -7974,8 +7938,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8017,8 +7980,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8060,8 +8022,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8103,8 +8064,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8146,8 +8106,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> @@ -8189,8 +8148,7 @@ FROM r#async: &'a super::super::super::types::public::SyntaxComposite, r#enum: &'a super::super::super::types::public::SyntaxEnum, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[r#async, r#enum]).await + client.execute(self.0, &[r#async, r#enum]).await } } impl<'a, C: GenericClient + Send + Sync> diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index 56168294..3c83c7e6 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -441,8 +441,7 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { } pub $fn_async fn one(self) -> Result { - let stmt = self.client.prepare(self.query)$fn_await?; - let row = self.client.query_one(&stmt, &self.params)$fn_await?; + let row = self.client.query_one(self.query, &self.params)$fn_await?; Ok((self.mapper)((self.extractor)(&row))) } @@ -451,10 +450,9 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { } pub $fn_async fn opt(self) -> Result, $backend::Error> { - let stmt = self.client.prepare(self.query)$fn_await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) $fn_await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -462,10 +460,9 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { pub $fn_async fn iter( self, ) -> Result> + 'a, $backend::Error> { - let stmt = self.client.prepare(self.query)$fn_await?; let it = self .client - .query_raw(&stmt, $client::private::slice_iter(&self.params)) + .query_raw(self.query, $client::private::slice_iter(&self.params)) $fn_await? $raw_pre .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) @@ -565,8 +562,7 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu }); code!(w => pub $fn_async fn bind<'a, C: GenericClient, $($traits_idx: $traits,)>(&'a self, client: &'a $client_mut C, $($params_name: &'a $params_ty,)) -> Result { - let stmt = client.prepare(self.0)$fn_await?; - client.execute(&stmt, &[ $($params_wrap,) ])$fn_await + client.execute(self.0, &[ $($params_wrap,) ])$fn_await } ); } diff --git a/examples/auto_build/src/cornucopia.rs b/examples/auto_build/src/cornucopia.rs index 74f050ec..b878b8b4 100644 --- a/examples/auto_build/src/cornucopia.rs +++ b/examples/auto_build/src/cornucopia.rs @@ -35,18 +35,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -56,10 +54,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index d4a9cdf1..931ea914 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -225,8 +225,7 @@ pub mod queries { client: &'a C, title: &'a T1, ) -> Result { - let stmt = client.prepare(self.0).await?; - client.execute(&stmt, &[title]).await + client.execute(self.0, &[title]).await } } } @@ -331,18 +330,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -352,10 +349,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -383,18 +382,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -404,10 +401,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -438,18 +437,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -459,10 +456,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -493,18 +492,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -514,10 +511,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); @@ -548,18 +547,16 @@ pub mod queries { } } pub async fn one(self) -> Result { - let stmt = self.client.prepare(self.query).await?; - let row = self.client.query_one(&stmt, &self.params).await?; + let row = self.client.query_one(self.query, &self.params).await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - let stmt = self.client.prepare(self.query).await?; Ok(self .client - .query_opt(&stmt, &self.params) + .query_opt(self.query, &self.params) .await? .map(|row| (self.mapper)((self.extractor)(&row)))) } @@ -569,10 +566,12 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let stmt = self.client.prepare(self.query).await?; let it = self .client - .query_raw(&stmt, cornucopia_async::private::slice_iter(&self.params)) + .query_raw( + self.query, + cornucopia_async::private::slice_iter(&self.params), + ) .await? .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index 7f886a6b..1450c670 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -223,8 +223,7 @@ pub mod queries { client: &'a mut C, title: &'a T1, ) -> Result { - let stmt = client.prepare(self.0)?; - client.execute(&stmt, &[title]) + client.execute(self.0, &[title]) } } } @@ -327,28 +326,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -375,28 +374,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -426,28 +425,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -477,28 +476,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) @@ -528,28 +527,28 @@ pub mod queries { } } pub fn one(self) -> Result { - let stmt = self.client.prepare(self.query)?; - let row = self.client.query_one(&stmt, &self.params)?; + let row = self.client.query_one(self.query, &self.params)?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - let stmt = self.client.prepare(self.query)?; Ok(self .client - .query_opt(&stmt, &self.params)? + .query_opt(self.query, &self.params)? .map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let stmt = self.client.prepare(self.query)?; let it = self .client - .query_raw(&stmt, cornucopia_sync::private::slice_iter(&self.params))? + .query_raw( + self.query, + cornucopia_sync::private::slice_iter(&self.params), + )? .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); Ok(it) From 557f3447a0a37d26152a454caf344a0e93a158d5 Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 04:03:33 +0100 Subject: [PATCH 4/7] The best of all world --- bench/usage/cornucopia_benches/generated.rs | 497 +++- bench/usage/cornucopia_benches/mod.rs | 24 +- clients/async/src/deadpool.rs | 118 +- clients/async/src/generic_client.rs | 155 +- clients/async/src/lib.rs | 2 +- clients/async/src/private.rs | 59 + clients/sync/src/generic_client.rs | 132 + clients/sync/src/lib.rs | 3 + clients/sync/src/private.rs | 59 + codegen_test/src/cornucopia.rs | 2723 ++++++++++++++----- cornucopia/src/codegen.rs | 33 +- examples/auto_build/src/cornucopia.rs | 53 +- examples/basic_async/src/cornucopia.rs | 293 +- examples/basic_sync/src/cornucopia.rs | 271 +- 14 files changed, 3318 insertions(+), 1104 deletions(-) create mode 100644 clients/sync/src/generic_client.rs diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs index d42e56f4..dd8b5231 100644 --- a/bench/usage/cornucopia_benches/generated.rs +++ b/bench/usage/cornucopia_benches/generated.rs @@ -138,11 +138,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct UserQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::UserBorrowed, mapper: fn(super::UserBorrowed) -> T, } @@ -158,42 +160,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct PostQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::PostBorrowed, mapper: fn(super::PostBorrowed) -> T, } @@ -209,42 +222,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct CommentQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::CommentBorrowed, mapper: fn(super::CommentBorrowed) -> T, } @@ -260,42 +284,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct SelectComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::SelectComplexBorrowed, mapper: fn(super::SelectComplexBorrowed) -> T, } @@ -311,43 +346,62 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn users() -> UsersStmt { - UsersStmt("SELECT * FROM users") + UsersStmt("SELECT * FROM users", None) } - pub struct UsersStmt(&'static str); + pub struct UsersStmt(&'static str, Option); impl UsersStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -356,6 +410,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -366,10 +421,19 @@ pub mod queries { } } pub fn insert_user() -> InsertUserStmt { - InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)") + InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)", None) } - pub struct InsertUserStmt(&'static str); + pub struct InsertUserStmt(&'static str, Option); impl InsertUserStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -406,10 +470,19 @@ pub mod queries { } } pub fn posts() -> PostsStmt { - PostsStmt("SELECT * FROM posts") + PostsStmt("SELECT * FROM posts", None) } - pub struct PostsStmt(&'static str); + pub struct PostsStmt(&'static str, Option); impl PostsStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -418,6 +491,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -429,10 +503,19 @@ pub mod queries { } } pub fn post_by_user_ids() -> PostByUserIdsStmt { - PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)") + PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)", None) } - pub struct PostByUserIdsStmt(&'static str); + pub struct PostByUserIdsStmt(&'static str, Option); impl PostByUserIdsStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( &'a self, client: &'a mut C, @@ -442,6 +525,7 @@ pub mod queries { client, params: [ids], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -453,10 +537,19 @@ pub mod queries { } } pub fn comments() -> CommentsStmt { - CommentsStmt("SELECT * FROM comments") + CommentsStmt("SELECT * FROM comments", None) } - pub struct CommentsStmt(&'static str); + pub struct CommentsStmt(&'static str, Option); impl CommentsStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -465,6 +558,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -475,10 +569,19 @@ pub mod queries { } } pub fn comments_by_post_id() -> CommentsByPostIdStmt { - CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)") + CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)", None) } - pub struct CommentsByPostIdStmt(&'static str); + pub struct CommentsByPostIdStmt(&'static str, Option); impl CommentsByPostIdStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( &'a self, client: &'a mut C, @@ -488,6 +591,7 @@ pub mod queries { client, params: [ids], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -498,10 +602,19 @@ pub mod queries { } } pub fn select_complex() -> SelectComplexStmt { - SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id") + SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id", None) } - pub struct SelectComplexStmt(&'static str); + pub struct SelectComplexStmt(&'static str, Option); impl SelectComplexStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -510,6 +623,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), @@ -532,6 +646,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::UserBorrowed, mapper: fn(super::UserBorrowed) -> T, } @@ -547,23 +662,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -571,22 +696,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct PostQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::PostBorrowed, mapper: fn(super::PostBorrowed) -> T, } @@ -602,23 +729,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -626,22 +763,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct CommentQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::CommentBorrowed, mapper: fn(super::CommentBorrowed) -> T, } @@ -657,23 +796,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -681,22 +830,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct SelectComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::SelectComplexBorrowed, mapper: fn(super::SelectComplexBorrowed) -> T, } @@ -712,23 +863,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -736,23 +897,33 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn users() -> UsersStmt { - UsersStmt("SELECT * FROM users") + UsersStmt("SELECT * FROM users", None) } - pub struct UsersStmt(&'static str); + pub struct UsersStmt(&'static str, Option); impl UsersStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -761,6 +932,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::UserBorrowed { id: row.get(0), name: row.get(1), @@ -771,10 +943,19 @@ pub mod queries { } } pub fn insert_user() -> InsertUserStmt { - InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)") + InsertUserStmt("INSERT INTO users (name, hair_color) VALUES ($1, $2)", None) } - pub struct InsertUserStmt(&'static str); + pub struct InsertUserStmt(&'static str, Option); impl InsertUserStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -823,10 +1004,19 @@ pub mod queries { } } pub fn posts() -> PostsStmt { - PostsStmt("SELECT * FROM posts") + PostsStmt("SELECT * FROM posts", None) } - pub struct PostsStmt(&'static str); + pub struct PostsStmt(&'static str, Option); impl PostsStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -835,6 +1025,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -846,10 +1037,19 @@ pub mod queries { } } pub fn post_by_user_ids() -> PostByUserIdsStmt { - PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)") + PostByUserIdsStmt("SELECT * FROM posts WHERE user_id = ANY($1)", None) } - pub struct PostByUserIdsStmt(&'static str); + pub struct PostByUserIdsStmt(&'static str, Option); impl PostByUserIdsStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( &'a self, client: &'a C, @@ -859,6 +1059,7 @@ pub mod queries { client, params: [ids], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::PostBorrowed { id: row.get(0), user_id: row.get(1), @@ -870,10 +1071,19 @@ pub mod queries { } } pub fn comments() -> CommentsStmt { - CommentsStmt("SELECT * FROM comments") + CommentsStmt("SELECT * FROM comments", None) } - pub struct CommentsStmt(&'static str); + pub struct CommentsStmt(&'static str, Option); impl CommentsStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -882,6 +1092,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -892,10 +1103,19 @@ pub mod queries { } } pub fn comments_by_post_id() -> CommentsByPostIdStmt { - CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)") + CommentsByPostIdStmt("SELECT * FROM comments WHERE post_id = ANY($1)", None) } - pub struct CommentsByPostIdStmt(&'static str); + pub struct CommentsByPostIdStmt(&'static str, Option); impl CommentsByPostIdStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( &'a self, client: &'a C, @@ -905,6 +1125,7 @@ pub mod queries { client, params: [ids], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::CommentBorrowed { id: row.get(0), post_id: row.get(1), @@ -915,10 +1136,19 @@ pub mod queries { } } pub fn select_complex() -> SelectComplexStmt { - SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id") + SelectComplexStmt("SELECT u.id as myuser_id, u.name, u.hair_color, p.id as post_id, p.user_id, p.title, p.body FROM users as u LEFT JOIN posts as p on u.id = p.user_id", None) } - pub struct SelectComplexStmt(&'static str); + pub struct SelectComplexStmt(&'static str, Option); impl SelectComplexStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -927,6 +1157,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectComplexBorrowed { myuser_id: row.get(0), name: row.get(1), diff --git a/bench/usage/cornucopia_benches/mod.rs b/bench/usage/cornucopia_benches/mod.rs index d81081f7..0d802fe7 100644 --- a/bench/usage/cornucopia_benches/mod.rs +++ b/bench/usage/cornucopia_benches/mod.rs @@ -12,12 +12,12 @@ use self::generated::queries::bench::{ mod generated; pub fn bench_trivial_query(b: &mut Bencher, client: &Client) { - let mut stmt = users(); + let stmt = block_on(async { users().prepare(client).await.unwrap() }); b.iter(|| block_on(async { stmt.bind(client).all().await.unwrap() })) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { - let mut stmt = select_complex(); + let stmt = block_on(async { select_complex().prepare(client).await.unwrap() }); b.iter(|| { block_on(async { stmt.bind(client) @@ -44,7 +44,7 @@ pub fn bench_medium_complex_query(b: &mut Bencher, client: &Client) { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { - let mut stmt = insert_user(); + let stmt = block_on(async { insert_user().prepare(client).await.unwrap() }); b.iter(|| { block_on(async { let mut tx = client.transaction().await.unwrap(); @@ -63,9 +63,9 @@ pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { } pub fn loading_associations_sequentially(b: &mut Bencher, client: &Client) { - let mut user_stmt = users(); - let mut post_stmt = post_by_user_ids(); - let mut comment_stmt = comments_by_post_id(); + let user_stmt = block_on(async { users().prepare(client).await.unwrap() }); + let post_stmt = block_on(async { post_by_user_ids().prepare(client).await.unwrap() }); + let comment_stmt = block_on(async { comments_by_post_id().prepare(client).await.unwrap() }); b.iter(|| { block_on(async { let users = user_stmt.bind(client).all().await.unwrap(); @@ -123,12 +123,12 @@ pub mod sync { Comment, Post, User, }; pub fn bench_trivial_query(b: &mut Bencher, client: &mut Client) { - let mut stmt = users(); + let stmt = users().prepare(client).unwrap(); b.iter(|| stmt.bind(client).all().unwrap()) } pub fn bench_medium_complex_query(b: &mut Bencher, client: &mut Client) { - let mut stmt = select_complex(); + let stmt = select_complex().prepare(client).unwrap(); b.iter(|| { stmt.bind(client) .map(|it| { @@ -152,7 +152,7 @@ pub mod sync { } pub fn bench_insert(b: &mut Bencher, client: &mut Client, size: usize) { - let mut stmt = insert_user(); + let stmt = insert_user().prepare(client).unwrap(); b.iter(|| { let mut tx = client.transaction().unwrap(); for x in 0..size { @@ -168,9 +168,9 @@ pub mod sync { } pub fn loading_associations_sequentially(b: &mut Bencher, client: &mut Client) { - let mut user_stmt = users(); - let mut post_stmt = post_by_user_ids(); - let mut comment_stmt = comments_by_post_id(); + let user_stmt = users().prepare(client).unwrap(); + let post_stmt = post_by_user_ids().prepare(client).unwrap(); + let comment_stmt = comments_by_post_id().prepare(client).unwrap(); b.iter(|| { let users = user_stmt.bind(client).all().unwrap(); diff --git a/clients/async/src/deadpool.rs b/clients/async/src/deadpool.rs index 5feeb7c7..acd45d01 100644 --- a/clients/async/src/deadpool.rs +++ b/clients/async/src/deadpool.rs @@ -3,100 +3,138 @@ use deadpool_postgres::{ Client as DeadpoolClient, ClientWrapper, Transaction as DeadpoolTransaction, }; use tokio_postgres::{ - types::BorrowToSql, Client as PgClient, Error, RowStream, Transaction as PgTransaction, + types::BorrowToSql, Client as PgClient, Error, RowStream, Statement, ToStatement, + Transaction as PgTransaction, }; use crate::generic_client::GenericClient; #[async_trait] impl GenericClient for DeadpoolClient { - async fn execute( + async fn prepare(&self, query: &str) -> Result { + ClientWrapper::prepare_cached(self, query).await + } + + fn stmt_cache() -> bool { + true + } + + async fn execute( &self, - query: &str, + query: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { - let stmt = ClientWrapper::prepare_cached(self, query).await?; - PgClient::execute(self, &stmt, params).await + ) -> Result + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgClient::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - query: &str, + statement: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { - let stmt = ClientWrapper::prepare_cached(self, query).await?; - PgClient::query_one(self, &stmt, params).await + ) -> Result + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgClient::query_one(self, statement, params).await } - async fn query_opt( + async fn query_opt( &self, - query: &str, + statement: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { - let stmt = ClientWrapper::prepare_cached(self, query).await?; - PgClient::query_opt(self, &stmt, params).await + ) -> Result, Error> + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgClient::query_opt(self, statement, params).await } - async fn query( + async fn query( &self, - query: &str, + query: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { - let stmt = ClientWrapper::prepare_cached(self, query).await?; - PgClient::query(self, &stmt, params).await + ) -> Result, Error> + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgClient::query(self, query, params).await } - async fn query_raw(&self, query: &str, params: I) -> Result + async fn query_raw(&self, statement: &T, params: I) -> Result where + T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - let stmt = ClientWrapper::prepare_cached(self, query).await?; - PgClient::query_raw(self, &stmt, params).await + PgClient::query_raw(self, statement, params).await } } #[async_trait] impl GenericClient for DeadpoolTransaction<'_> { - async fn execute( + async fn prepare(&self, query: &str) -> Result { + DeadpoolTransaction::prepare_cached(self, query).await + } + + fn stmt_cache() -> bool { + true + } + + async fn execute( &self, - query: &str, + query: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { + ) -> Result + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { PgTransaction::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - query: &str, + statement: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { - PgTransaction::query_one(self, query, params).await + ) -> Result + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgTransaction::query_one(self, statement, params).await } - async fn query_opt( + async fn query_opt( &self, - query: &str, + statement: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { - PgTransaction::query_opt(self, query, params).await + ) -> Result, Error> + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { + PgTransaction::query_opt(self, statement, params).await } - async fn query( + async fn query( &self, - query: &str, + query: &T, params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { + ) -> Result, Error> + where + T: ?Sized + tokio_postgres::ToStatement + Sync + Send, + { PgTransaction::query(self, query, params).await } - async fn query_raw(&self, query: &str, params: I) -> Result + async fn query_raw(&self, statement: &T, params: I) -> Result where + T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - PgTransaction::query_raw(self, query, params).await + PgTransaction::query_raw(self, statement, params).await } } diff --git a/clients/async/src/generic_client.rs b/clients/async/src/generic_client.rs index 3cd51156..b44fea5d 100644 --- a/clients/async/src/generic_client.rs +++ b/clients/async/src/generic_client.rs @@ -1,5 +1,8 @@ use async_trait::async_trait; -use tokio_postgres::{types::BorrowToSql, Client, Error, RowStream, Transaction}; +use tokio_postgres::{ + types::{BorrowToSql, ToSql}, + Client, Error, Row, RowStream, Statement, ToStatement, Transaction, +}; /// Abstraction over multiple types of asynchronous clients. /// This allows you to use tokio_postgres clients and transactions interchangeably. @@ -8,28 +11,34 @@ use tokio_postgres::{types::BorrowToSql, Client, Error, RowStream, Transaction}; /// abstracts over deadpool clients and transactions #[async_trait] pub trait GenericClient: Send + Sync { - async fn execute( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result; - async fn query_one( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result; - async fn query_opt( + async fn prepare(&self, query: &str) -> Result; + fn stmt_cache() -> bool { + false + } + async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement + Sync + Send; + async fn query_one( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error>; - async fn query( + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result + where + T: ?Sized + ToStatement + Sync + Send; + async fn query_opt( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error>; - async fn query_raw(&self, query: &str, params: I) -> Result + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send; + async fn query(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send; + + async fn query_raw(&self, statement: &T, params: I) -> Result where + T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator; @@ -37,88 +46,106 @@ pub trait GenericClient: Send + Sync { #[async_trait] impl GenericClient for Transaction<'_> { - async fn execute( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { + async fn prepare(&self, query: &str) -> Result { + Transaction::prepare(self, query).await + } + + async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement + Sync + Send, + { Transaction::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { - Transaction::query_one(self, query, params).await + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result + where + T: ?Sized + ToStatement + Sync + Send, + { + Transaction::query_one(self, statement, params).await } - async fn query_opt( + async fn query_opt( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { - Transaction::query_opt(self, query, params).await + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send, + { + Transaction::query_opt(self, statement, params).await } - async fn query( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { + async fn query(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send, + { Transaction::query(self, query, params).await } - async fn query_raw(&self, query: &str, params: I) -> Result + async fn query_raw(&self, statement: &T, params: I) -> Result where + T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - Transaction::query_raw(self, query, params).await + Transaction::query_raw(self, statement, params).await } } #[async_trait] impl GenericClient for Client { - async fn execute( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { + async fn prepare(&self, query: &str) -> Result { + Client::prepare(self, query).await + } + + async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement + Sync + Send, + { Client::execute(self, query, params).await } - async fn query_one( + async fn query_one( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result { - Client::query_one(self, query, params).await + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result + where + T: ?Sized + ToStatement + Sync + Send, + { + Client::query_one(self, statement, params).await } - async fn query_opt( + async fn query_opt( &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { - Client::query_opt(self, query, params).await + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send, + { + Client::query_opt(self, statement, params).await } - async fn query( - &self, - query: &str, - params: &[&(dyn tokio_postgres::types::ToSql + Sync)], - ) -> Result, Error> { + async fn query(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement + Sync + Send, + { Client::query(self, query, params).await } - async fn query_raw(&self, query: &str, params: I) -> Result + async fn query_raw(&self, statement: &T, params: I) -> Result where + T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql, I: IntoIterator + Sync + Send, I::IntoIter: ExactSizeIterator, { - Client::query_raw(self, query, params).await + Client::query_raw(self, statement, params).await } } diff --git a/clients/async/src/lib.rs b/clients/async/src/lib.rs index 296d6bdd..f2368e3f 100644 --- a/clients/async/src/lib.rs +++ b/clients/async/src/lib.rs @@ -1,8 +1,8 @@ #[doc(hidden)] pub mod private; -pub use crate::generic_client::GenericClient; pub use cornucopia_client_core::{ArrayIterator, ArraySql, BytesSql, IterSql, StringSql}; +pub use generic_client::GenericClient; #[cfg(feature = "with-serde_json-1")] pub use cornucopia_client_core::JsonSql; diff --git a/clients/async/src/private.rs b/clients/async/src/private.rs index 20b8d68d..f05d59c7 100644 --- a/clients/async/src/private.rs +++ b/clients/async/src/private.rs @@ -1 +1,60 @@ pub use cornucopia_client_core::{slice_iter, Domain, DomainArray}; +use tokio_postgres::{ + types::{BorrowToSql, ToSql}, + Error, Row, RowStream, Statement, +}; + +use crate::GenericClient; + +pub async fn one( + client: &C, + query: &str, + params: &[&(dyn ToSql + Sync)], + cached: Option<&Statement>, +) -> Result { + if let Some(cached) = cached { + client.query_one(cached, params).await + } else if C::stmt_cache() { + let cached = client.prepare(query).await?; + client.query_one(&cached, params).await + } else { + client.query_one(query, params).await + } +} + +pub async fn opt( + client: &C, + query: &str, + params: &[&(dyn ToSql + Sync)], + cached: Option<&Statement>, +) -> Result, Error> { + if let Some(cached) = cached { + client.query_opt(cached, params).await + } else if C::stmt_cache() { + let cached = client.prepare(query).await?; + client.query_opt(&cached, params).await + } else { + client.query_opt(query, params).await + } +} + +pub async fn raw( + client: &C, + query: &str, + params: I, + cached: Option<&Statement>, +) -> Result +where + P: BorrowToSql, + I: IntoIterator + Sync + Send, + I::IntoIter: ExactSizeIterator, +{ + if let Some(cached) = cached { + client.query_raw(cached, params).await + } else if C::stmt_cache() { + let cached = client.prepare(query).await?; + client.query_raw(&cached, params).await + } else { + client.query_raw(query, params).await + } +} diff --git a/clients/sync/src/generic_client.rs b/clients/sync/src/generic_client.rs new file mode 100644 index 00000000..eeb764c5 --- /dev/null +++ b/clients/sync/src/generic_client.rs @@ -0,0 +1,132 @@ +use postgres::{ + types::{BorrowToSql, ToSql}, + Client, Error, Row, RowIter, Statement, ToStatement, Transaction, +}; + +/// Abstraction over multiple types of synchronous clients. +/// This allows you to use postgres clients and transactions interchangeably. +pub trait GenericClient { + fn prepare(&mut self, query: &str) -> Result; + fn stmt_cache() -> bool { + false + } + fn execute(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement; + fn query_one(&mut self, statement: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement; + fn query_opt( + &mut self, + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement; + fn query(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement; + + fn query_raw(&mut self, statement: &T, params: I) -> Result, Error> + where + T: ?Sized + ToStatement, + P: BorrowToSql, + I: IntoIterator, + I::IntoIter: ExactSizeIterator; +} + +impl GenericClient for Transaction<'_> { + fn prepare(&mut self, query: &str) -> Result { + Transaction::prepare(self, query) + } + + fn execute(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement, + { + Transaction::execute(self, query, params) + } + + fn query_one(&mut self, statement: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement, + { + Transaction::query_one(self, statement, params) + } + + fn query_opt( + &mut self, + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement, + { + Transaction::query_opt(self, statement, params) + } + + fn query(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement, + { + Transaction::query(self, query, params) + } + + fn query_raw(&mut self, statement: &T, params: I) -> Result, Error> + where + T: ?Sized + ToStatement, + P: BorrowToSql, + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + { + Transaction::query_raw(self, statement, params) + } +} + +impl GenericClient for Client { + fn prepare(&mut self, query: &str) -> Result { + Client::prepare(self, query) + } + + fn execute(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement, + { + Client::execute(self, query, params) + } + + fn query_one(&mut self, statement: &T, params: &[&(dyn ToSql + Sync)]) -> Result + where + T: ?Sized + ToStatement, + { + Client::query_one(self, statement, params) + } + + fn query_opt( + &mut self, + statement: &T, + params: &[&(dyn ToSql + Sync)], + ) -> Result, Error> + where + T: ?Sized + ToStatement, + { + Client::query_opt(self, statement, params) + } + + fn query(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result, Error> + where + T: ?Sized + ToStatement, + { + Client::query(self, query, params) + } + + fn query_raw(&mut self, statement: &T, params: I) -> Result, Error> + where + T: ?Sized + ToStatement, + P: BorrowToSql, + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + { + Client::query_raw(self, statement, params) + } +} diff --git a/clients/sync/src/lib.rs b/clients/sync/src/lib.rs index 8e840021..042ce5a1 100644 --- a/clients/sync/src/lib.rs +++ b/clients/sync/src/lib.rs @@ -2,10 +2,13 @@ pub mod private; pub use cornucopia_client_core::{ArrayIterator, ArraySql, BytesSql, IterSql, StringSql}; +pub use generic_client::GenericClient; #[cfg(feature = "with-serde_json-1")] pub use cornucopia_client_core::JsonSql; +mod generic_client; + /// This trait allows you to bind parameters to a query using a single /// struct, rather than passing each bind parameter as a function parameter. pub trait Params<'a, P, O, C> { diff --git a/clients/sync/src/private.rs b/clients/sync/src/private.rs index 20b8d68d..1bb8e005 100644 --- a/clients/sync/src/private.rs +++ b/clients/sync/src/private.rs @@ -1 +1,60 @@ pub use cornucopia_client_core::{slice_iter, Domain, DomainArray}; +use postgres::{ + types::{BorrowToSql, ToSql}, + Error, Row, RowIter, Statement, +}; + +use crate::GenericClient; + +pub fn one( + client: &mut C, + query: &str, + params: &[&(dyn ToSql + Sync)], + cached: Option<&Statement>, +) -> Result { + if let Some(cached) = cached { + client.query_one(cached, params) + } else if C::stmt_cache() { + let cached = client.prepare(query)?; + client.query_one(&cached, params) + } else { + client.query_one(query, params) + } +} + +pub fn opt( + client: &mut C, + query: &str, + params: &[&(dyn ToSql + Sync)], + cached: Option<&Statement>, +) -> Result, Error> { + if let Some(cached) = cached { + client.query_opt(cached, params) + } else if C::stmt_cache() { + let cached = client.prepare(query)?; + client.query_opt(&cached, params) + } else { + client.query_opt(query, params) + } +} + +pub fn raw<'a, C: GenericClient, P, I>( + client: &'a mut C, + query: &str, + params: I, + cached: Option<&Statement>, +) -> Result, Error> +where + P: BorrowToSql, + I: IntoIterator, + I::IntoIter: ExactSizeIterator, +{ + if let Some(cached) = cached { + client.query_raw(cached, params) + } else if C::stmt_cache() { + let cached = client.prepare(query)?; + client.query_raw(&cached, params) + } else { + client.query_raw(query, params) + } +} diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs index 1cb42f23..fa0970b8 100644 --- a/codegen_test/src/cornucopia.rs +++ b/codegen_test/src/cornucopia.rs @@ -1264,11 +1264,13 @@ pub mod types { pub mod queries { pub mod copy { pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn( &postgres::Row, ) @@ -1287,42 +1289,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct PublicCopyCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::super::super::types::public::CopyComposite, mapper: fn(super::super::super::types::public::CopyComposite) -> T, } @@ -1338,43 +1351,62 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn insert_clone() -> InsertCloneStmt { - InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)") + InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)", None) } - pub struct InsertCloneStmt(&'static str); + pub struct InsertCloneStmt(&'static str, Option); impl InsertCloneStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1384,10 +1416,19 @@ pub mod queries { } } pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt("SELECT * FROM clone") + SelectCloneStmt("SELECT * FROM clone", None) } - pub struct SelectCloneStmt(&'static str); + pub struct SelectCloneStmt(&'static str, Option); impl SelectCloneStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1401,16 +1442,26 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } } } pub fn insert_copy() -> InsertCopyStmt { - InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)") + InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)", None) } - pub struct InsertCopyStmt(&'static str); + pub struct InsertCopyStmt(&'static str, Option); impl InsertCopyStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1420,10 +1471,19 @@ pub mod queries { } } pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt("SELECT * FROM copy") + SelectCopyStmt("SELECT * FROM copy", None) } - pub struct SelectCopyStmt(&'static str); + pub struct SelectCopyStmt(&'static str, Option); impl SelectCopyStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1437,6 +1497,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -1451,6 +1512,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn( &tokio_postgres::Row, ) @@ -1469,23 +1531,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -1493,22 +1565,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct PublicCopyCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::super::super::types::public::CopyComposite, mapper: fn(super::super::super::types::public::CopyComposite) -> T, @@ -1525,23 +1599,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -1549,23 +1633,33 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn insert_clone() -> InsertCloneStmt { - InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)") + InsertCloneStmt("INSERT INTO clone (composite) VALUES ($1)", None) } - pub struct InsertCloneStmt(&'static str); + pub struct InsertCloneStmt(&'static str, Option); impl InsertCloneStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -1575,10 +1669,19 @@ pub mod queries { } } pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt("SELECT * FROM clone") + SelectCloneStmt("SELECT * FROM clone", None) } - pub struct SelectCloneStmt(&'static str); + pub struct SelectCloneStmt(&'static str, Option); impl SelectCloneStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -1592,16 +1695,26 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } } } pub fn insert_copy() -> InsertCopyStmt { - InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)") + InsertCopyStmt("INSERT INTO copy (composite) VALUES ($1)", None) } - pub struct InsertCopyStmt(&'static str); + pub struct InsertCopyStmt(&'static str, Option); impl InsertCopyStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -1611,10 +1724,19 @@ pub mod queries { } } pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt("SELECT * FROM copy") + SelectCopyStmt("SELECT * FROM copy", None) } - pub struct SelectCopyStmt(&'static str); + pub struct SelectCopyStmt(&'static str, Option); impl SelectCopyStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -1628,6 +1750,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -1725,11 +1848,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct SelectNightmareDomainQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::SelectNightmareDomainBorrowed, mapper: fn(super::SelectNightmareDomainBorrowed) -> T, } @@ -1745,42 +1870,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct SelectNightmareDomainNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::SelectNightmareDomainNullBorrowed, mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, } @@ -1796,43 +1932,62 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain") + SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain", None) } - pub struct SelectNightmareDomainStmt(&'static str); + pub struct SelectNightmareDomainStmt(&'static str, Option); impl SelectNightmareDomainStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1842,6 +1997,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -1853,10 +2009,19 @@ pub mod queries { } } pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { - InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)") + InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)", None) } - pub struct InsertNightmareDomainStmt(&'static str); + pub struct InsertNightmareDomainStmt(&'static str, Option); impl InsertNightmareDomainStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -1920,10 +2085,19 @@ pub mod queries { } } pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain") + SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain", None) } - pub struct SelectNightmareDomainNullStmt(&'static str); + pub struct SelectNightmareDomainNullStmt(&'static str, Option); impl SelectNightmareDomainNullStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -1933,6 +2107,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -1953,6 +2128,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainBorrowed, mapper: fn(super::SelectNightmareDomainBorrowed) -> T, } @@ -1968,23 +2144,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -1992,22 +2178,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct SelectNightmareDomainNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainNullBorrowed, mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, } @@ -2023,23 +2211,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -2047,23 +2245,33 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn select_nightmare_domain() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain") + SelectNightmareDomainStmt("SELECT txt, json, nb, arr FROM nightmare_domain", None) } - pub struct SelectNightmareDomainStmt(&'static str); + pub struct SelectNightmareDomainStmt(&'static str, Option); impl SelectNightmareDomainStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2073,6 +2281,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectNightmareDomainBorrowed { txt: row.get(0), json: row.get(1), @@ -2084,10 +2293,19 @@ pub mod queries { } } pub fn insert_nightmare_domain() -> InsertNightmareDomainStmt { - InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)") + InsertNightmareDomainStmt("INSERT INTO nightmare_domain (txt, json, nb, arr, composite) VALUES ($1, $2, $3, $4, $5)", None) } - pub struct InsertNightmareDomainStmt(&'static str); + pub struct InsertNightmareDomainStmt(&'static str, Option); impl InsertNightmareDomainStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -2165,10 +2383,22 @@ pub mod queries { } } pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain") + SelectNightmareDomainNullStmt("SELECT * FROM nightmare_domain", None) } - pub struct SelectNightmareDomainNullStmt(&'static str); + pub struct SelectNightmareDomainNullStmt( + &'static str, + Option, + ); impl SelectNightmareDomainNullStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2178,6 +2408,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectNightmareDomainNullBorrowed { txt: row.get(0), json: row.get(1), @@ -2259,11 +2490,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct IdQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::Id, mapper: fn(super::Id) -> T, } @@ -2276,42 +2509,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct NamedQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::NamedBorrowed, mapper: fn(super::NamedBorrowed) -> T, } @@ -2327,42 +2571,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct NamedComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::NamedComplexBorrowed, mapper: fn(super::NamedComplexBorrowed) -> T, } @@ -2378,45 +2633,65 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn new_named_visible() -> NewNamedVisibleStmt { NewNamedVisibleStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", + None, ) } - pub struct NewNamedVisibleStmt(&'static str); + pub struct NewNamedVisibleStmt(&'static str, Option); impl NewNamedVisibleStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -2427,6 +2702,7 @@ pub mod queries { client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } @@ -2447,10 +2723,20 @@ pub mod queries { pub fn new_named_hidden() -> NewNamedHiddenStmt { NewNamedHiddenStmt( "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NewNamedHiddenStmt(&'static str); + pub struct NewNamedHiddenStmt(&'static str, Option); impl NewNamedHiddenStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -2461,6 +2747,7 @@ pub mod queries { client, params: [price, name], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } @@ -2479,10 +2766,19 @@ pub mod queries { } } pub fn named() -> NamedStmt { - NamedStmt("SELECT * FROM named") + NamedStmt("SELECT * FROM named", None) } - pub struct NamedStmt(&'static str); + pub struct NamedStmt(&'static str, Option); impl NamedStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -2491,6 +2787,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2502,10 +2799,19 @@ pub mod queries { } } pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt("SELECT * FROM named WHERE id = $1") + NamedByIdStmt("SELECT * FROM named WHERE id = $1", None) } - pub struct NamedByIdStmt(&'static str); + pub struct NamedByIdStmt(&'static str, Option); impl NamedByIdStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -2515,6 +2821,7 @@ pub mod queries { client, params: [id], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2528,10 +2835,20 @@ pub mod queries { pub fn new_named_complex() -> NewNamedComplexStmt { NewNamedComplexStmt( "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", + None, ) } - pub struct NewNamedComplexStmt(&'static str); + pub struct NewNamedComplexStmt(&'static str, Option); impl NewNamedComplexStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -2560,10 +2877,19 @@ pub mod queries { } } pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt("SELECT * FROM named_complex") + NamedComplexStmt("SELECT * FROM named_complex", None) } - pub struct NamedComplexStmt(&'static str); + pub struct NamedComplexStmt(&'static str, Option); impl NamedComplexStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -2572,6 +2898,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -2589,6 +2916,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::Id, mapper: fn(super::Id) -> T, } @@ -2601,23 +2929,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -2625,22 +2963,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct NamedQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::NamedBorrowed, mapper: fn(super::NamedBorrowed) -> T, } @@ -2656,23 +2996,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -2680,22 +3030,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct NamedComplexQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::NamedComplexBorrowed, mapper: fn(super::NamedComplexBorrowed) -> T, } @@ -2711,23 +3063,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -2735,25 +3097,36 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn new_named_visible() -> NewNamedVisibleStmt { NewNamedVisibleStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, true) RETURNING id ", + None, ) } - pub struct NewNamedVisibleStmt(&'static str); + pub struct NewNamedVisibleStmt(&'static str, Option); impl NewNamedVisibleStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -2764,6 +3137,7 @@ pub mod queries { client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } @@ -2788,10 +3162,20 @@ pub mod queries { pub fn new_named_hidden() -> NewNamedHiddenStmt { NewNamedHiddenStmt( "INSERT INTO named (price, name, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NewNamedHiddenStmt(&'static str); + pub struct NewNamedHiddenStmt(&'static str, Option); impl NewNamedHiddenStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -2802,6 +3186,7 @@ pub mod queries { client, params: [price, name], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Id { id: row.get(0) }, mapper: |it| ::from(it), } @@ -2824,10 +3209,19 @@ pub mod queries { } } pub fn named() -> NamedStmt { - NamedStmt("SELECT * FROM named") + NamedStmt("SELECT * FROM named", None) } - pub struct NamedStmt(&'static str); + pub struct NamedStmt(&'static str, Option); impl NamedStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2836,6 +3230,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2847,10 +3242,19 @@ pub mod queries { } } pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt("SELECT * FROM named WHERE id = $1") + NamedByIdStmt("SELECT * FROM named WHERE id = $1", None) } - pub struct NamedByIdStmt(&'static str); + pub struct NamedByIdStmt(&'static str, Option); impl NamedByIdStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2860,6 +3264,7 @@ pub mod queries { client, params: [id], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedBorrowed { id: row.get(0), name: row.get(1), @@ -2873,10 +3278,20 @@ pub mod queries { pub fn new_named_complex() -> NewNamedComplexStmt { NewNamedComplexStmt( "INSERT INTO named_complex (named, \"named.with_dot\") VALUES ($1, $2)", + None, ) } - pub struct NewNamedComplexStmt(&'static str); + pub struct NewNamedComplexStmt(&'static str, Option); impl NewNamedComplexStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2917,10 +3332,19 @@ pub mod queries { } } pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt("SELECT * FROM named_complex") + NamedComplexStmt("SELECT * FROM named_complex", None) } - pub struct NamedComplexStmt(&'static str); + pub struct NamedComplexStmt(&'static str, Option); impl NamedComplexStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -2929,6 +3353,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NamedComplexBorrowed { named: row.get(0), named_with_dot: row.get(1), @@ -2978,11 +3403,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct NullityQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::NullityBorrowed, mapper: fn(super::NullityBorrowed) -> T, } @@ -2998,43 +3425,65 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn new_nullity() -> NewNullityStmt { - NewNullityStmt("INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)") + NewNullityStmt( + "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", + None, + ) } - pub struct NewNullityStmt(&'static str); + pub struct NewNullityStmt(&'static str, Option); impl NewNullityStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -3076,10 +3525,19 @@ pub mod queries { } } pub fn nullity() -> NullityStmt { - NullityStmt("SELECT * FROM nullity") + NullityStmt("SELECT * FROM nullity", None) } - pub struct NullityStmt(&'static str); + pub struct NullityStmt(&'static str, Option); impl NullityStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -3088,6 +3546,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3106,6 +3565,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::NullityBorrowed, mapper: fn(super::NullityBorrowed) -> T, } @@ -3121,23 +3581,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -3145,23 +3615,36 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn new_nullity() -> NewNullityStmt { - NewNullityStmt("INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)") + NewNullityStmt( + "INSERT INTO nullity(texts, name, composite) VALUES ($1, $2, $3)", + None, + ) } - pub struct NewNullityStmt(&'static str); + pub struct NewNullityStmt(&'static str, Option); impl NewNullityStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -3215,10 +3698,19 @@ pub mod queries { } } pub fn nullity() -> NullityStmt { - NullityStmt("SELECT * FROM nullity") + NullityStmt("SELECT * FROM nullity", None) } - pub struct NullityStmt(&'static str); + pub struct NullityStmt(&'static str, Option); impl NullityStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -3227,6 +3719,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::NullityBorrowed { texts: row.get(0), name: row.get(1), @@ -3287,11 +3780,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct SelectBookQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::SelectBookBorrowed, mapper: fn(super::SelectBookBorrowed) -> T, } @@ -3307,42 +3802,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct FindBooksQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::FindBooksBorrowed, mapper: fn(super::FindBooksBorrowed) -> T, } @@ -3358,43 +3864,62 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn insert_book() -> InsertBookStmt { - InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)") + InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)", None) } - pub struct InsertBookStmt(&'static str); + pub struct InsertBookStmt(&'static str, Option); impl InsertBookStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -3431,10 +3956,19 @@ pub mod queries { } } pub fn select_book() -> SelectBookStmt { - SelectBookStmt("SELECT * FROM book") + SelectBookStmt("SELECT * FROM book", None) } - pub struct SelectBookStmt(&'static str); + pub struct SelectBookStmt(&'static str, Option); impl SelectBookStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -3443,6 +3977,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3452,10 +3987,19 @@ pub mod queries { } } pub fn find_books() -> FindBooksStmt { - FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)") + FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)", None) } - pub struct FindBooksStmt(&'static str); + pub struct FindBooksStmt(&'static str, Option); impl FindBooksStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -3470,6 +4014,7 @@ pub mod queries { client, params: [title], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3481,10 +4026,20 @@ pub mod queries { pub fn params_use_twice() -> ParamsUseTwiceStmt { ParamsUseTwiceStmt( "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", + None, ) } - pub struct ParamsUseTwiceStmt(&'static str); + pub struct ParamsUseTwiceStmt(&'static str, Option); impl ParamsUseTwiceStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -3494,10 +4049,19 @@ pub mod queries { } } pub fn params_order() -> ParamsOrderStmt { - ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1") + ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", None) } - pub struct ParamsOrderStmt(&'static str); + pub struct ParamsOrderStmt(&'static str, Option); impl ParamsOrderStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -3532,6 +4096,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::SelectBookBorrowed, mapper: fn(super::SelectBookBorrowed) -> T, } @@ -3547,23 +4112,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -3571,22 +4146,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct FindBooksQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::FindBooksBorrowed, mapper: fn(super::FindBooksBorrowed) -> T, } @@ -3602,23 +4179,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -3626,23 +4213,33 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn insert_book() -> InsertBookStmt { - InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)") + InsertBookStmt("INSERT INTO book (author, name) VALUES ($1, $2)", None) } - pub struct InsertBookStmt(&'static str); + pub struct InsertBookStmt(&'static str, Option); impl InsertBookStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -3691,10 +4288,19 @@ pub mod queries { } } pub fn select_book() -> SelectBookStmt { - SelectBookStmt("SELECT * FROM book") + SelectBookStmt("SELECT * FROM book", None) } - pub struct SelectBookStmt(&'static str); + pub struct SelectBookStmt(&'static str, Option); impl SelectBookStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -3703,6 +4309,7 @@ pub mod queries { client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::SelectBookBorrowed { name: row.get(0), author: row.get(1), @@ -3712,10 +4319,19 @@ pub mod queries { } } pub fn find_books() -> FindBooksStmt { - FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)") + FindBooksStmt("SELECT * FROM book WHERE name = ANY ($1)", None) } - pub struct FindBooksStmt(&'static str); + pub struct FindBooksStmt(&'static str, Option); impl FindBooksStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -3730,6 +4346,7 @@ pub mod queries { client, params: [title], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::FindBooksBorrowed { name: row.get(0), author: row.get(1), @@ -3741,10 +4358,20 @@ pub mod queries { pub fn params_use_twice() -> ParamsUseTwiceStmt { ParamsUseTwiceStmt( "UPDATE book SET name = $1 WHERE length(name) > 42 AND length($1) < 42", + None, ) } - pub struct ParamsUseTwiceStmt(&'static str); + pub struct ParamsUseTwiceStmt(&'static str, Option); impl ParamsUseTwiceStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -3754,10 +4381,19 @@ pub mod queries { } } pub fn params_order() -> ParamsOrderStmt { - ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1") + ParamsOrderStmt("UPDATE imaginary SET c=$1, a=$2, z=$2, r=$1", None) } - pub struct ParamsOrderStmt(&'static str); + pub struct ParamsOrderStmt(&'static str, Option); impl ParamsOrderStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -4491,11 +5127,13 @@ pub mod queries { } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct EverythingQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::EverythingBorrowed, mapper: fn(super::EverythingBorrowed) -> T, } @@ -4511,42 +5149,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct EverythingNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::EverythingNullBorrowed, mapper: fn(super::EverythingNullBorrowed) -> T, } @@ -4562,42 +5211,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct EverythingArrayQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::EverythingArrayBorrowed, mapper: fn(super::EverythingArrayBorrowed) -> T, } @@ -4613,42 +5273,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct EverythingArrayNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::EverythingArrayNullBorrowed, mapper: fn(super::EverythingArrayNullBorrowed) -> T, } @@ -4664,42 +5335,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct PublicNightmareCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn( &postgres::Row, ) @@ -4718,36 +5400,46 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn select_everything() -> SelectEverythingStmt { @@ -4756,10 +5448,20 @@ pub mod queries { * FROM Everything", + None, ) } - pub struct SelectEverythingStmt(&'static str); + pub struct SelectEverythingStmt(&'static str, Option); impl SelectEverythingStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -4768,6 +5470,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -4814,10 +5517,20 @@ FROM * FROM Everything", + None, ) } - pub struct SelectEverythingNullStmt(&'static str); + pub struct SelectEverythingNullStmt(&'static str, Option); impl SelectEverythingNullStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -4826,6 +5539,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -4868,10 +5582,19 @@ FROM } pub fn insert_everything() -> InsertEverythingStmt { InsertEverythingStmt("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)") + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)", None) } - pub struct InsertEverythingStmt(&'static str); + pub struct InsertEverythingStmt(&'static str, Option); impl InsertEverythingStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -5025,10 +5748,20 @@ FROM * FROM EverythingArray", + None, ) } - pub struct SelectEverythingArrayStmt(&'static str); + pub struct SelectEverythingArrayStmt(&'static str, Option); impl SelectEverythingArrayStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -5037,6 +5770,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5077,10 +5811,20 @@ FROM * FROM EverythingArray", + None, ) } - pub struct SelectEverythingArrayNullStmt(&'static str); + pub struct SelectEverythingArrayNullStmt(&'static str, Option); impl SelectEverythingArrayNullStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -5090,6 +5834,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5126,10 +5871,19 @@ FROM } pub fn insert_everything_array() -> InsertEverythingArrayStmt { InsertEverythingArrayStmt("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)") + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)", None) } - pub struct InsertEverythingArrayStmt(&'static str); + pub struct InsertEverythingArrayStmt(&'static str, Option); impl InsertEverythingArrayStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind< 'a, C: GenericClient, @@ -5389,10 +6143,20 @@ FROM * FROM nightmare", + None, ) } - pub struct SelectNightmareStmt(&'static str); + pub struct SelectNightmareStmt(&'static str, Option); impl SelectNightmareStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -5406,6 +6170,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -5415,10 +6180,20 @@ FROM InsertNightmareStmt( "INSERT INTO nightmare (composite) VALUES ($1)", + None, ) } - pub struct InsertNightmareStmt(&'static str); + pub struct InsertNightmareStmt(&'static str, Option); impl InsertNightmareStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -5436,6 +6211,7 @@ FROM client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::EverythingBorrowed, mapper: fn(super::EverythingBorrowed) -> T, } @@ -5451,23 +6227,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -5475,22 +6261,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct EverythingNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::EverythingNullBorrowed, mapper: fn(super::EverythingNullBorrowed) -> T, } @@ -5506,23 +6294,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -5530,22 +6328,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct EverythingArrayQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayBorrowed, mapper: fn(super::EverythingArrayBorrowed) -> T, } @@ -5561,23 +6361,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -5585,22 +6395,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct EverythingArrayNullQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayNullBorrowed, mapper: fn(super::EverythingArrayNullBorrowed) -> T, } @@ -5616,23 +6428,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -5640,22 +6462,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct PublicNightmareCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn( &tokio_postgres::Row, ) @@ -5674,23 +6498,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -5698,16 +6532,17 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn select_everything() -> SelectEverythingStmt { @@ -5716,10 +6551,20 @@ FROM * FROM Everything", + None, ) } - pub struct SelectEverythingStmt(&'static str); + pub struct SelectEverythingStmt(&'static str, Option); impl SelectEverythingStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -5728,6 +6573,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5774,10 +6620,20 @@ FROM * FROM Everything", + None, ) } - pub struct SelectEverythingNullStmt(&'static str); + pub struct SelectEverythingNullStmt(&'static str, Option); impl SelectEverythingNullStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -5786,6 +6642,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -5828,10 +6685,19 @@ FROM } pub fn insert_everything() -> InsertEverythingStmt { InsertEverythingStmt("INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)") + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34)", None) } - pub struct InsertEverythingStmt(&'static str); + pub struct InsertEverythingStmt(&'static str, Option); impl InsertEverythingStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -5999,10 +6865,20 @@ FROM * FROM EverythingArray", + None, ) } - pub struct SelectEverythingArrayStmt(&'static str); + pub struct SelectEverythingArrayStmt(&'static str, Option); impl SelectEverythingArrayStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -6011,6 +6887,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingArrayBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6051,10 +6928,23 @@ FROM * FROM EverythingArray", + None, ) } - pub struct SelectEverythingArrayNullStmt(&'static str); + pub struct SelectEverythingArrayNullStmt( + &'static str, + Option, + ); impl SelectEverythingArrayNullStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -6064,6 +6954,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::EverythingArrayNullBorrowed { bool_: row.get(0), boolean_: row.get(1), @@ -6100,10 +6991,19 @@ FROM } pub fn insert_everything_array() -> InsertEverythingArrayStmt { InsertEverythingArrayStmt("INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_, numeric_) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)") + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)", None) } - pub struct InsertEverythingArrayStmt(&'static str); + pub struct InsertEverythingArrayStmt(&'static str, Option); impl InsertEverythingArrayStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind< 'a, C: GenericClient, @@ -6377,10 +7277,20 @@ FROM * FROM nightmare", + None, ) } - pub struct SelectNightmareStmt(&'static str); + pub struct SelectNightmareStmt(&'static str, Option); impl SelectNightmareStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -6394,6 +7304,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -6403,10 +7314,20 @@ FROM InsertNightmareStmt( "INSERT INTO nightmare (composite) VALUES ($1)", + None, ) } - pub struct InsertNightmareStmt(&'static str); + pub struct InsertNightmareStmt(&'static str, Option); impl InsertNightmareStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -6523,11 +7444,13 @@ FROM } } pub mod sync { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct PublicCloneCompositeQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn( &postgres::Row, ) @@ -6546,42 +7469,53 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct Optioni32Query<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> Option, mapper: fn(Option) -> T, } @@ -6594,42 +7528,53 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct RowQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::Row, mapper: fn(super::Row) -> T, } @@ -6642,42 +7587,53 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct RowSpaceQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::RowSpace, mapper: fn(super::RowSpace) -> T, } @@ -6693,42 +7649,53 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct TypeofQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::TypeofBorrowed, mapper: fn(super::TypeofBorrowed) -> T, } @@ -6744,43 +7711,62 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn select_compact() -> SelectCompactStmt { - SelectCompactStmt("SELECT * FROM clone") + SelectCompactStmt("SELECT * FROM clone", None) } - pub struct SelectCompactStmt(&'static str); + pub struct SelectCompactStmt(&'static str, Option); impl SelectCompactStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -6794,16 +7780,26 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } } } pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(" SELECT * FROM clone ") + SelectSpacedStmt(" SELECT * FROM clone ", None) } - pub struct SelectSpacedStmt(&'static str); + pub struct SelectSpacedStmt(&'static str, Option); impl SelectSpacedStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -6817,6 +7813,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -6825,10 +7822,20 @@ FROM pub fn implicit_compact() -> ImplicitCompactStmt { ImplicitCompactStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct ImplicitCompactStmt(&'static str); + pub struct ImplicitCompactStmt(&'static str, Option); impl ImplicitCompactStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -6839,6 +7846,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -6863,10 +7871,20 @@ FROM pub fn implicit_spaced() -> ImplicitSpacedStmt { ImplicitSpacedStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct ImplicitSpacedStmt(&'static str); + pub struct ImplicitSpacedStmt(&'static str, Option); impl ImplicitSpacedStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -6877,6 +7895,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -6901,10 +7920,20 @@ FROM pub fn named_compact() -> NamedCompactStmt { NamedCompactStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NamedCompactStmt(&'static str); + pub struct NamedCompactStmt(&'static str, Option); impl NamedCompactStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -6915,6 +7944,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } @@ -6935,10 +7965,20 @@ FROM pub fn named_spaced() -> NamedSpacedStmt { NamedSpacedStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NamedSpacedStmt(&'static str); + pub struct NamedSpacedStmt(&'static str, Option); impl NamedSpacedStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -6949,6 +7989,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -6971,10 +8012,19 @@ FROM } } pub fn tricky_sql() -> TrickySqlStmt { - TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)") + TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)", None) } - pub struct TrickySqlStmt(&'static str); + pub struct TrickySqlStmt(&'static str, Option); impl TrickySqlStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -6997,10 +8047,19 @@ FROM } } pub fn tricky_sql1() -> TrickySql1Stmt { - TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)") + TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)", None) } - pub struct TrickySql1Stmt(&'static str); + pub struct TrickySql1Stmt(&'static str, Option); impl TrickySql1Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7027,10 +8086,19 @@ FROM } } pub fn tricky_sql2() -> TrickySql2Stmt { - TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)") + TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)", None) } - pub struct TrickySql2Stmt(&'static str); + pub struct TrickySql2Stmt(&'static str, Option); impl TrickySql2Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7057,10 +8125,19 @@ FROM } } pub fn tricky_sql3() -> TrickySql3Stmt { - TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)") + TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)", None) } - pub struct TrickySql3Stmt(&'static str); + pub struct TrickySql3Stmt(&'static str, Option); impl TrickySql3Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7087,10 +8164,19 @@ FROM } } pub fn tricky_sql4() -> TrickySql4Stmt { - TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)") + TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)", None) } - pub struct TrickySql4Stmt(&'static str); + pub struct TrickySql4Stmt(&'static str, Option); impl TrickySql4Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7117,10 +8203,19 @@ FROM } } pub fn tricky_sql6() -> TrickySql6Stmt { - TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)") + TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)", None) } - pub struct TrickySql6Stmt(&'static str); + pub struct TrickySql6Stmt(&'static str, Option); impl TrickySql6Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7147,10 +8242,19 @@ FROM } } pub fn tricky_sql7() -> TrickySql7Stmt { - TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)") + TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql7Stmt(&'static str); + pub struct TrickySql7Stmt(&'static str, Option); impl TrickySql7Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7177,10 +8281,19 @@ FROM } } pub fn tricky_sql8() -> TrickySql8Stmt { - TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)") + TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql8Stmt(&'static str); + pub struct TrickySql8Stmt(&'static str, Option); impl TrickySql8Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7207,10 +8320,19 @@ FROM } } pub fn tricky_sql9() -> TrickySql9Stmt { - TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)") + TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql9Stmt(&'static str); + pub struct TrickySql9Stmt(&'static str, Option); impl TrickySql9Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7237,10 +8359,19 @@ FROM } } pub fn tricky_sql10() -> TrickySql10Stmt { - TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)") + TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)", None) } - pub struct TrickySql10Stmt(&'static str); + pub struct TrickySql10Stmt(&'static str, Option); impl TrickySql10Stmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7267,10 +8398,19 @@ FROM } } pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt("SELECT * FROM syntax") + RTypeofStmt("SELECT * FROM syntax", None) } - pub struct RTypeofStmt(&'static str); + pub struct RTypeofStmt(&'static str, Option); impl RTypeofStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -7279,6 +8419,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), @@ -7297,6 +8438,7 @@ FROM client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn( &tokio_postgres::Row, ) @@ -7315,23 +8457,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -7339,22 +8491,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct Optioni32Query<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> Option, mapper: fn(Option) -> T, } @@ -7367,23 +8521,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -7391,22 +8555,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct RowQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::Row, mapper: fn(super::Row) -> T, } @@ -7419,23 +8585,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -7443,22 +8619,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct RowSpaceQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::RowSpace, mapper: fn(super::RowSpace) -> T, } @@ -7474,23 +8652,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -7498,22 +8686,24 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct TypeofQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::TypeofBorrowed, mapper: fn(super::TypeofBorrowed) -> T, } @@ -7529,23 +8719,33 @@ FROM client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -7553,23 +8753,33 @@ FROM impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn select_compact() -> SelectCompactStmt { - SelectCompactStmt("SELECT * FROM clone") + SelectCompactStmt("SELECT * FROM clone", None) } - pub struct SelectCompactStmt(&'static str); + pub struct SelectCompactStmt(&'static str, Option); impl SelectCompactStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7583,16 +8793,26 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } } } pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(" SELECT * FROM clone ") + SelectSpacedStmt(" SELECT * FROM clone ", None) } - pub struct SelectSpacedStmt(&'static str); + pub struct SelectSpacedStmt(&'static str, Option); impl SelectSpacedStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7606,6 +8826,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -7614,10 +8835,20 @@ FROM pub fn implicit_compact() -> ImplicitCompactStmt { ImplicitCompactStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct ImplicitCompactStmt(&'static str); + pub struct ImplicitCompactStmt(&'static str, Option); impl ImplicitCompactStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -7628,6 +8859,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -7652,10 +8884,20 @@ FROM pub fn implicit_spaced() -> ImplicitSpacedStmt { ImplicitSpacedStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct ImplicitSpacedStmt(&'static str); + pub struct ImplicitSpacedStmt(&'static str, Option); impl ImplicitSpacedStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -7666,6 +8908,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it, } @@ -7690,10 +8933,20 @@ FROM pub fn named_compact() -> NamedCompactStmt { NamedCompactStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NamedCompactStmt(&'static str); + pub struct NamedCompactStmt(&'static str, Option); impl NamedCompactStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -7704,6 +8957,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::Row { id: row.get(0) }, mapper: |it| ::from(it), } @@ -7724,10 +8978,20 @@ FROM pub fn named_spaced() -> NamedSpacedStmt { NamedSpacedStmt( "INSERT INTO named (name, price, show) VALUES ($1, $2, false) RETURNING id", + None, ) } - pub struct NamedSpacedStmt(&'static str); + pub struct NamedSpacedStmt(&'static str, Option); impl NamedSpacedStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -7738,6 +9002,7 @@ FROM client, params: [name, price], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::RowSpace { id: row.get(0) }, mapper: |it| ::from(it), } @@ -7760,10 +9025,19 @@ FROM } } pub fn tricky_sql() -> TrickySqlStmt { - TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)") + TrickySqlStmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a bind_param\', $1, $2)", None) } - pub struct TrickySqlStmt(&'static str); + pub struct TrickySqlStmt(&'static str, Option); impl TrickySqlStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7802,10 +9076,19 @@ FROM } } pub fn tricky_sql1() -> TrickySql1Stmt { - TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)") + TrickySql1Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a :bind_param', $1, $2)", None) } - pub struct TrickySql1Stmt(&'static str); + pub struct TrickySql1Stmt(&'static str, Option); impl TrickySql1Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7844,10 +9127,19 @@ FROM } } pub fn tricky_sql2() -> TrickySql2Stmt { - TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)") + TrickySql2Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is not a '':bind_param''', $1, $2)", None) } - pub struct TrickySql2Stmt(&'static str); + pub struct TrickySql2Stmt(&'static str, Option); impl TrickySql2Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7886,10 +9178,19 @@ FROM } } pub fn tricky_sql3() -> TrickySql3Stmt { - TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)") + TrickySql3Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($$this is not a :bind_param$$, $1, $2)", None) } - pub struct TrickySql3Stmt(&'static str); + pub struct TrickySql3Stmt(&'static str, Option); impl TrickySql3Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7928,10 +9229,19 @@ FROM } } pub fn tricky_sql4() -> TrickySql4Stmt { - TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)") + TrickySql4Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ($tag$this is not a :bind_param$tag$, $1, $2)", None) } - pub struct TrickySql4Stmt(&'static str); + pub struct TrickySql4Stmt(&'static str, Option); impl TrickySql4Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -7970,10 +9280,19 @@ FROM } } pub fn tricky_sql6() -> TrickySql6Stmt { - TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)") + TrickySql6Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is not a '':bind_param''', $1, $2)", None) } - pub struct TrickySql6Stmt(&'static str); + pub struct TrickySql6Stmt(&'static str, Option); impl TrickySql6Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8012,10 +9331,19 @@ FROM } } pub fn tricky_sql7() -> TrickySql7Stmt { - TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)") + TrickySql7Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is not a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql7Stmt(&'static str); + pub struct TrickySql7Stmt(&'static str, Option); impl TrickySql7Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8054,10 +9382,19 @@ FROM } } pub fn tricky_sql8() -> TrickySql8Stmt { - TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)") + TrickySql8Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (e'this is ''not'' a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql8Stmt(&'static str); + pub struct TrickySql8Stmt(&'static str, Option); impl TrickySql8Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8096,10 +9433,19 @@ FROM } } pub fn tricky_sql9() -> TrickySql9Stmt { - TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)") + TrickySql9Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES (E'this is \'not\' a \':bind_param\'', $1, $2)", None) } - pub struct TrickySql9Stmt(&'static str); + pub struct TrickySql9Stmt(&'static str, Option); impl TrickySql9Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8138,10 +9484,19 @@ FROM } } pub fn tricky_sql10() -> TrickySql10Stmt { - TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)") + TrickySql10Stmt("INSERT INTO syntax (\"trick:y\", async, enum) VALUES ('this is just a cast'::text, $1, $2)", None) } - pub struct TrickySql10Stmt(&'static str); + pub struct TrickySql10Stmt(&'static str, Option); impl TrickySql10Stmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8180,10 +9535,19 @@ FROM } } pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt("SELECT * FROM syntax") + RTypeofStmt("SELECT * FROM syntax", None) } - pub struct RTypeofStmt(&'static str); + pub struct RTypeofStmt(&'static str, Option); impl RTypeofStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -8192,6 +9556,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| super::TypeofBorrowed { trick_y: row.get(0), r#async: row.get(1), diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index 3c83c7e6..ae82641b 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -426,6 +426,7 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { client: &'a $client_mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a $backend::Statement>, extractor: fn(&$backend::Row) -> $row_struct, mapper: fn($row_struct) -> T, } @@ -435,13 +436,14 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub $fn_async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)$fn_await?; + let row = $client::private::one(self.client, self.query, &self.params, self.cached)$fn_await?; Ok((self.mapper)((self.extractor)(&row))) } @@ -450,24 +452,19 @@ fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { } pub $fn_async fn opt(self) -> Result, $backend::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - $fn_await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = $client::private::opt(self.client, self.query, &self.params, self.cached)$fn_await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub $fn_async fn iter( self, ) -> Result> + 'a, $backend::Error> { - let it = self - .client - .query_raw(self.query, $client::private::slice_iter(&self.params)) - $fn_await? + let stream = $client::private::raw(self.client, self.query, $client::private::slice_iter(&self.params), self.cached)$fn_await?; + let mapped = stream $raw_pre .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) $raw_post; - Ok(it) + Ok(mapped) } }); } @@ -549,6 +546,7 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu client, params: [$($params_name,)], query: self.0, + cached: self.1.as_ref(), extractor: |row| { $!extractor }, mapper: |it| { $mapper }, } @@ -573,10 +571,17 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu let name = &ident.rs; code!(w => pub fn $name() -> ${struct_name}Stmt { - ${struct_name}Stmt("$sql") + ${struct_name}Stmt("$sql", None) } - pub struct ${struct_name}Stmt(&'static str); + pub struct ${struct_name}Stmt(&'static str, Option<$backend::Statement>); impl ${struct_name}Stmt { + pub $fn_async fn prepare<'a, C: GenericClient>(mut self, client: &'a $client_mut C) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)$fn_await?) + } + Ok(self) + } + $!lazy_impl } ); @@ -774,7 +779,7 @@ pub(crate) fn generate(preparation: Preparation, settings: CodegenSettings) -> S let import = if is_async { "use futures::{StreamExt, TryStreamExt};use futures; use cornucopia_async::GenericClient;" } else { - "use postgres::{fallible_iterator::FallibleIterator,GenericClient};" + "use postgres::{fallible_iterator::FallibleIterator}; use cornucopia_sync::GenericClient;" }; let rows_query_string = module .rows diff --git a/examples/auto_build/src/cornucopia.rs b/examples/auto_build/src/cornucopia.rs index b878b8b4..6f705786 100644 --- a/examples/auto_build/src/cornucopia.rs +++ b/examples/auto_build/src/cornucopia.rs @@ -18,6 +18,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -30,23 +31,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -54,16 +65,17 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn example_query() -> ExampleQueryStmt { @@ -72,10 +84,20 @@ pub mod queries { * FROM example_table", + None, ) } - pub struct ExampleQueryStmt(&'static str); + pub struct ExampleQueryStmt(&'static str, Option); impl ExampleQueryStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -84,6 +106,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index 931ea914..33aec10b 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -216,10 +216,20 @@ pub mod queries { InsertBookStmt( "INSERT INTO Book (title) VALUES ($1)", + None, ) } - pub struct InsertBookStmt(&'static str); + pub struct InsertBookStmt(&'static str, Option); impl InsertBookStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -313,6 +323,7 @@ pub mod queries { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> AuthorsBorrowed, mapper: fn(AuthorsBorrowed) -> T, } @@ -325,23 +336,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -349,22 +370,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct StringQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -377,23 +400,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -401,22 +434,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> AuthorNameStartingWithBorrowed, mapper: fn(AuthorNameStartingWithBorrowed) -> T, } @@ -432,23 +467,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -456,22 +501,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct PublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } @@ -487,23 +534,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -511,22 +568,24 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a tokio_postgres::Statement>, extractor: fn(&tokio_postgres::Row) -> SelectTranslationsBorrowed, mapper: fn(SelectTranslationsBorrowed) -> T, } @@ -542,23 +601,33 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub async fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params).await?; + let row = cornucopia_async::private::one( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; Ok((self.mapper)((self.extractor)(&row))) } pub async fn all(self) -> Result, tokio_postgres::Error> { self.iter().await?.try_collect().await } pub async fn opt(self) -> Result, tokio_postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_async::private::opt( + self.client, + self.query, + &self.params, + self.cached, + ) + .await?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub async fn iter( self, @@ -566,16 +635,17 @@ pub mod queries { impl futures::Stream> + 'a, tokio_postgres::Error, > { - let it = self - .client - .query_raw( - self.query, - cornucopia_async::private::slice_iter(&self.params), - ) - .await? + let stream = cornucopia_async::private::raw( + self.client, + self.query, + cornucopia_async::private::slice_iter(&self.params), + self.cached, + ) + .await?; + let mapped = stream .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) .into_stream(); - Ok(it) + Ok(mapped) } } pub fn authors() -> AuthorsStmt { @@ -584,10 +654,20 @@ pub mod queries { * FROM Author", + None, ) } - pub struct AuthorsStmt(&'static str); + pub struct AuthorsStmt(&'static str, Option); impl AuthorsStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -596,6 +676,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -611,10 +692,20 @@ FROM Title FROM Book", + None, ) } - pub struct BooksStmt(&'static str); + pub struct BooksStmt(&'static str, Option); impl BooksStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -623,6 +714,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -636,10 +728,20 @@ FROM Author WHERE Author.Id = $1", + None, ) } - pub struct AuthorNameByIdStmt(&'static str); + pub struct AuthorNameByIdStmt(&'static str, Option); impl AuthorNameByIdStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -649,6 +751,7 @@ WHERE client, params: [id], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -667,10 +770,20 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", + None, ) } - pub struct AuthorNameStartingWithStmt(&'static str); + pub struct AuthorNameStartingWithStmt(&'static str, Option); impl AuthorNameStartingWithStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( &'a self, client: &'a C, @@ -680,6 +793,7 @@ WHERE client, params: [start_str], query: self.0, + cached: self.1.as_ref(), extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -714,10 +828,23 @@ FROM SpongeBobVoiceActor WHERE character = $1", + None, ) } - pub struct SelectVoiceActorWithCharacterStmt(&'static str); + pub struct SelectVoiceActorWithCharacterStmt( + &'static str, + Option, + ); impl SelectVoiceActorWithCharacterStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -728,6 +855,7 @@ WHERE client, params: [spongebob_character], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -740,10 +868,20 @@ WHERE Translations FROM Book", + None, ) } - pub struct SelectTranslationsStmt(&'static str); + pub struct SelectTranslationsStmt(&'static str, Option); impl SelectTranslationsStmt { + pub async fn prepare<'a, C: GenericClient>( + mut self, + client: &'a C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0).await?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a C, @@ -752,6 +890,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index 1450c670..e8e4b849 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -209,15 +209,26 @@ pub mod types { #[allow(dead_code)] pub mod queries { pub mod module_1 { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub fn insert_book() -> InsertBookStmt { InsertBookStmt( "INSERT INTO Book (title) VALUES ($1)", + None, ) } - pub struct InsertBookStmt(&'static str); + pub struct InsertBookStmt(&'static str, Option); impl InsertBookStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -304,11 +315,13 @@ pub mod queries { } } } - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + use cornucopia_sync::GenericClient; + use postgres::fallible_iterator::FallibleIterator; pub struct AuthorsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> AuthorsBorrowed, mapper: fn(AuthorsBorrowed) -> T, } @@ -321,42 +334,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct StringQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> &str, mapper: fn(&str) -> T, } @@ -369,42 +393,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> AuthorNameStartingWithBorrowed, mapper: fn(AuthorNameStartingWithBorrowed) -> T, } @@ -420,42 +455,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct PublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } @@ -471,42 +517,53 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], query: &'static str, + cached: Option<&'a postgres::Statement>, extractor: fn(&postgres::Row) -> SelectTranslationsBorrowed, mapper: fn(SelectTranslationsBorrowed) -> T, } @@ -522,36 +579,46 @@ pub mod queries { client: self.client, params: self.params, query: self.query, + cached: self.cached, extractor: self.extractor, mapper, } } pub fn one(self) -> Result { - let row = self.client.query_one(self.query, &self.params)?; + let row = cornucopia_sync::private::one( + self.client, + self.query, + &self.params, + self.cached, + )?; Ok((self.mapper)((self.extractor)(&row))) } pub fn all(self) -> Result, postgres::Error> { self.iter()?.collect() } pub fn opt(self) -> Result, postgres::Error> { - Ok(self - .client - .query_opt(self.query, &self.params)? - .map(|row| (self.mapper)((self.extractor)(&row)))) + let opt_row = cornucopia_sync::private::opt( + self.client, + self.query, + &self.params, + self.cached, + )?; + Ok(opt_row.map(|row| (self.mapper)((self.extractor)(&row)))) } pub fn iter( self, ) -> Result> + 'a, postgres::Error> { - let it = self - .client - .query_raw( - self.query, - cornucopia_sync::private::slice_iter(&self.params), - )? + let stream = cornucopia_sync::private::raw( + self.client, + self.query, + cornucopia_sync::private::slice_iter(&self.params), + self.cached, + )?; + let mapped = stream .iterator() .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) + Ok(mapped) } } pub fn authors() -> AuthorsStmt { @@ -560,10 +627,20 @@ pub mod queries { * FROM Author", + None, ) } - pub struct AuthorsStmt(&'static str); + pub struct AuthorsStmt(&'static str, Option); impl AuthorsStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -572,6 +649,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| AuthorsBorrowed { id: row.get(0), name: row.get(1), @@ -587,10 +665,20 @@ FROM Title FROM Book", + None, ) } - pub struct BooksStmt(&'static str); + pub struct BooksStmt(&'static str, Option); impl BooksStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -599,6 +687,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -612,10 +701,20 @@ FROM Author WHERE Author.Id = $1", + None, ) } - pub struct AuthorNameByIdStmt(&'static str); + pub struct AuthorNameByIdStmt(&'static str, Option); impl AuthorNameByIdStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -625,6 +724,7 @@ WHERE client, params: [id], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -643,10 +743,20 @@ FROM INNER JOIN Book ON Book.Id = BookAuthor.BookId WHERE Author.Name LIKE CONCAT($1::text, '%')", + None, ) } - pub struct AuthorNameStartingWithStmt(&'static str); + pub struct AuthorNameStartingWithStmt(&'static str, Option); impl AuthorNameStartingWithStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( &'a self, client: &'a mut C, @@ -656,6 +766,7 @@ WHERE client, params: [start_str], query: self.0, + cached: self.1.as_ref(), extractor: |row| AuthorNameStartingWithBorrowed { authorid: row.get(0), name: row.get(1), @@ -690,10 +801,20 @@ FROM SpongeBobVoiceActor WHERE character = $1", + None, ) } - pub struct SelectVoiceActorWithCharacterStmt(&'static str); + pub struct SelectVoiceActorWithCharacterStmt(&'static str, Option); impl SelectVoiceActorWithCharacterStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -704,6 +825,7 @@ WHERE client, params: [spongebob_character], query: self.0, + cached: self.1.as_ref(), extractor: |row| row.get(0), mapper: |it| it.into(), } @@ -716,10 +838,20 @@ WHERE Translations FROM Book", + None, ) } - pub struct SelectTranslationsStmt(&'static str); + pub struct SelectTranslationsStmt(&'static str, Option); impl SelectTranslationsStmt { + pub fn prepare<'a, C: GenericClient>( + mut self, + client: &'a mut C, + ) -> Result { + if self.1.is_none() { + self.1 = Some(client.prepare(self.0)?) + } + Ok(self) + } pub fn bind<'a, C: GenericClient>( &'a self, client: &'a mut C, @@ -728,6 +860,7 @@ FROM client, params: [], query: self.0, + cached: self.1.as_ref(), extractor: |row| SelectTranslationsBorrowed { title: row.get(0), translations: row.get(1), From 51b55df6b82230007c2ba8c893af3625115cd93b Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 04:13:43 +0100 Subject: [PATCH 5/7] clippy fix --- cornucopia/src/type_registrar.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cornucopia/src/type_registrar.rs b/cornucopia/src/type_registrar.rs index c26b538a..1b7ca70f 100644 --- a/cornucopia/src/type_registrar.rs +++ b/cornucopia/src/type_registrar.rs @@ -242,7 +242,7 @@ impl CornucopiaType { } => { if !is_copy && !is_params { let path = custom_ty_path(pg_ty.schema(), struct_name, ctx); - format!("{}Params<'a>", path) + format!("{path}Params<'a>") } else { self.brw_ty(is_inner_nullable, true, ctx) } @@ -293,7 +293,7 @@ impl CornucopiaType { if *is_copy { path } else { - format!("{}Borrowed<{lifetime}>", path) + format!("{path}Borrowed<{lifetime}>") } } } @@ -302,14 +302,11 @@ impl CornucopiaType { pub fn custom_ty_path(schema: &str, struct_name: &str, ctx: &GenCtx) -> String { if ctx.depth == 0 { - format!("{}::{}", schema, struct_name) + format!("{schema}::{struct_name}") } else if ctx.depth == 1 { - format!("super::{}::{}", schema, struct_name) + format!("super::{schema}::{struct_name}") } else { - ctx.path( - ctx.depth, - format_args!("types::{}::{}", schema, struct_name), - ) + ctx.path(ctx.depth, format_args!("types::{schema}::{struct_name}")) } } From 410d856761fdd2d23468749576e00166ab642656 Mon Sep 17 00:00:00 2001 From: Virgiel <> Date: Sun, 5 Feb 2023 19:47:43 +0100 Subject: [PATCH 6/7] Enable preparation with another client --- bench/usage/cornucopia_benches/generated.rs | 56 +-- codegen_test/src/cornucopia.rs | 360 +++++--------------- cornucopia/src/codegen.rs | 4 +- examples/auto_build/src/cornucopia.rs | 4 +- examples/basic_async/src/cornucopia.rs | 28 +- examples/basic_sync/src/cornucopia.rs | 28 +- 6 files changed, 120 insertions(+), 360 deletions(-) diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs index dd8b5231..efe2e69a 100644 --- a/bench/usage/cornucopia_benches/generated.rs +++ b/bench/usage/cornucopia_benches/generated.rs @@ -397,9 +397,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -429,9 +427,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -478,9 +474,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -511,9 +505,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( @@ -545,9 +537,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -577,9 +567,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::ArraySql>( @@ -610,9 +598,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -919,9 +905,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -951,9 +935,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -1012,9 +994,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1045,9 +1025,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( @@ -1079,9 +1057,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1111,9 +1087,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::ArraySql>( @@ -1144,9 +1118,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs index fa0970b8..f2c796d9 100644 --- a/codegen_test/src/cornucopia.rs +++ b/codegen_test/src/cornucopia.rs @@ -1402,9 +1402,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1424,9 +1422,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1457,9 +1453,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1479,9 +1473,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1655,9 +1647,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -1677,9 +1667,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1710,9 +1698,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -1732,9 +1718,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -1983,9 +1967,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2017,9 +1999,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -2093,9 +2073,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2267,9 +2245,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2301,9 +2277,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -2394,9 +2368,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2687,9 +2659,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -2732,9 +2702,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -2774,9 +2742,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2807,9 +2773,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2844,9 +2808,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -2885,9 +2847,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3122,9 +3082,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -3171,9 +3129,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -3217,9 +3173,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3250,9 +3204,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3287,9 +3239,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -3340,9 +3290,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3479,9 +3427,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -3533,9 +3479,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3640,9 +3584,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -3706,9 +3648,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3915,9 +3855,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -3964,9 +3902,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -3995,9 +3931,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -4035,9 +3969,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -4057,9 +3989,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -4235,9 +4165,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -4296,9 +4224,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -4327,9 +4253,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind< @@ -4367,9 +4291,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -4389,9 +4311,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -5457,9 +5377,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -5526,9 +5444,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -5590,9 +5506,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -5757,9 +5671,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -5820,9 +5732,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -5879,9 +5789,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind< @@ -6152,9 +6060,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6189,9 +6095,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6560,9 +6464,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6629,9 +6531,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6693,9 +6593,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -6874,9 +6772,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6940,9 +6836,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -6999,9 +6893,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind< @@ -7286,9 +7178,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -7323,9 +7213,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -7762,9 +7650,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -7795,9 +7681,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -7831,9 +7715,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -7880,9 +7762,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -7929,9 +7809,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -7974,9 +7852,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -8020,9 +7896,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8055,9 +7929,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8094,9 +7966,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8133,9 +8003,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8172,9 +8040,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8211,9 +8077,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8250,9 +8114,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8289,9 +8151,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8328,9 +8188,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8367,9 +8225,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8406,9 +8262,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8775,9 +8629,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8808,9 +8660,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -8844,9 +8694,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -8893,9 +8741,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -8942,9 +8788,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -8987,9 +8831,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -9033,9 +8875,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9084,9 +8924,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9135,9 +8973,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9186,9 +9022,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9237,9 +9071,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9288,9 +9120,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9339,9 +9169,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9390,9 +9218,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9441,9 +9267,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9492,9 +9316,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient>( @@ -9543,9 +9365,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index ae82641b..10798c98 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -576,9 +576,7 @@ fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQu pub struct ${struct_name}Stmt(&'static str, Option<$backend::Statement>); impl ${struct_name}Stmt { pub $fn_async fn prepare<'a, C: GenericClient>(mut self, client: &'a $client_mut C) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)$fn_await?) - } + self.1 = Some(client.prepare(self.0)$fn_await?); Ok(self) } diff --git a/examples/auto_build/src/cornucopia.rs b/examples/auto_build/src/cornucopia.rs index 6f705786..4b184292 100644 --- a/examples/auto_build/src/cornucopia.rs +++ b/examples/auto_build/src/cornucopia.rs @@ -93,9 +93,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index 33aec10b..782f9bb4 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -225,9 +225,7 @@ pub mod queries { mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -663,9 +661,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -701,9 +697,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -737,9 +731,7 @@ WHERE mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -779,9 +771,7 @@ WHERE mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( @@ -840,9 +830,7 @@ WHERE mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -877,9 +865,7 @@ FROM mut self, client: &'a C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0).await?) - } + self.1 = Some(client.prepare(self.0).await?); Ok(self) } pub fn bind<'a, C: GenericClient>( diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index e8e4b849..955a90d3 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -224,9 +224,7 @@ pub mod queries { mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -636,9 +634,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -674,9 +670,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -710,9 +704,7 @@ WHERE mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -752,9 +744,7 @@ WHERE mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( @@ -810,9 +800,7 @@ WHERE mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( @@ -847,9 +835,7 @@ FROM mut self, client: &'a mut C, ) -> Result { - if self.1.is_none() { - self.1 = Some(client.prepare(self.0)?) - } + self.1 = Some(client.prepare(self.0)?); Ok(self) } pub fn bind<'a, C: GenericClient>( From a1b64daa01b2ab9f7c776c068c1a888f62d01028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Gari=C3=A9py?= Date: Wed, 8 Feb 2023 05:02:50 -0500 Subject: [PATCH 7/7] Fix path. --- benches/execution/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benches/execution/main.rs b/benches/execution/main.rs index 64d07a86..6db5f5be 100644 --- a/benches/execution/main.rs +++ b/benches/execution/main.rs @@ -126,8 +126,8 @@ fn prepare_full(client: &mut Client) { } fn bench(c: &mut Criterion) { - cornucopia::container::cleanup(false).ok(); - cornucopia::container::setup(false).unwrap(); + cornucopia::container::cleanup(true).ok(); + cornucopia::container::setup(true).unwrap(); let client = &mut cornucopia_conn().unwrap(); let rt: &'static Runtime = Box::leak(Box::new(Runtime::new().unwrap())); let async_client = &mut rt.block_on(async { @@ -144,7 +144,7 @@ fn bench(c: &mut Criterion) { &mut PgConnection::establish("postgresql://postgres:postgres@127.0.0.1:5435/postgres") .unwrap(); - cornucopia::load_schema(client, &["usage/cornucopia_benches/schema.sql"]).unwrap(); + cornucopia::load_schema(client, &["execution/cornucopia_benches/schema.sql"]).unwrap(); { let mut group = c.benchmark_group("bench_trivial_query"); for size in QUERY_SIZE { @@ -237,7 +237,7 @@ fn bench(c: &mut Criterion) { group.finish(); } - cornucopia::container::cleanup(false).unwrap(); + cornucopia::container::cleanup(true).unwrap(); } criterion::criterion_group!(benches, bench); criterion::criterion_main!(benches);