diff --git a/bench/codegen.rs b/bench/codegen.rs index 75993b55..37e333bf 100644 --- a/bench/codegen.rs +++ b/bench/codegen.rs @@ -14,7 +14,8 @@ fn bench(c: &mut Criterion) { "../codegen_test/queries", None, CodegenSettings { - is_async: false, + gen_sync: true, + gen_async: false, derive_ser: true, }, ) @@ -28,7 +29,8 @@ fn bench(c: &mut Criterion) { "../codegen_test/queries", None, CodegenSettings { - is_async: true, + gen_sync: true, + gen_async: false, derive_ser: true, }, ) diff --git a/bench/usage/cornucopia_benches/generated.rs b/bench/usage/cornucopia_benches/generated.rs new file mode 100644 index 00000000..33f68dd2 --- /dev/null +++ b/bench/usage/cornucopia_benches/generated.rs @@ -0,0 +1,963 @@ +// This file was generated with `cornucopia`. Do not modify. + +#[allow(clippy::all, clippy::pedantic)] +#[allow(unused_variables)] +#[allow(unused_imports)] +#[allow(dead_code)] +pub mod types {} +#[allow(clippy::all, clippy::pedantic)] +#[allow(unused_variables)] +#[allow(unused_imports)] +#[allow(dead_code)] +pub mod queries { + pub mod bench { + #[derive(Debug)] + pub struct InsertUserParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > { + pub name: T1, + pub hair_color: Option, + } + #[derive(Debug, Clone, PartialEq)] + pub struct User { + pub id: i32, + pub name: String, + pub hair_color: Option, + } + pub struct UserBorrowed<'a> { + pub id: i32, + pub name: &'a str, + pub hair_color: Option<&'a str>, + } + impl<'a> From> for User { + fn from( + UserBorrowed { + id, + name, + hair_color, + }: UserBorrowed<'a>, + ) -> Self { + Self { + id, + name: name.into(), + hair_color: hair_color.map(|v| v.into()), + } + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Post { + pub id: i32, + pub user_id: i32, + pub title: String, + pub body: Option, + } + pub struct PostBorrowed<'a> { + pub id: i32, + pub user_id: i32, + pub title: &'a str, + pub body: Option<&'a str>, + } + impl<'a> From> for Post { + fn from( + PostBorrowed { + id, + user_id, + title, + body, + }: PostBorrowed<'a>, + ) -> Self { + Self { + id, + user_id, + title: title.into(), + body: body.map(|v| v.into()), + } + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct Comment { + pub id: i32, + pub post_id: i32, + pub text: String, + } + pub struct CommentBorrowed<'a> { + pub id: i32, + pub post_id: i32, + pub text: &'a str, + } + impl<'a> From> for Comment { + fn from(CommentBorrowed { id, post_id, text }: CommentBorrowed<'a>) -> Self { + Self { + id, + post_id, + text: text.into(), + } + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct SelectComplex { + pub myuser_id: i32, + pub name: String, + pub hair_color: Option, + pub post_id: Option, + pub user_id: Option, + pub title: Option, + pub body: Option, + } + pub struct SelectComplexBorrowed<'a> { + pub myuser_id: i32, + pub name: &'a str, + pub hair_color: Option<&'a str>, + pub post_id: Option, + pub user_id: Option, + pub title: Option<&'a str>, + pub body: Option<&'a str>, + } + impl<'a> From> for SelectComplex { + fn from( + SelectComplexBorrowed { + myuser_id, + name, + hair_color, + post_id, + user_id, + title, + body, + }: SelectComplexBorrowed<'a>, + ) -> Self { + Self { + myuser_id, + name: name.into(), + hair_color: hair_color.map(|v| v.into()), + post_id, + user_id, + title: title.map(|v| v.into()), + body: body.map(|v| v.into()), + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::UserBorrowed, + mapper: fn(super::UserBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> UserQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::UserBorrowed) -> R, + ) -> UserQuery<'a, C, R, N> { + UserQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::PostBorrowed, + mapper: fn(super::PostBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PostQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::PostBorrowed) -> R, + ) -> PostQuery<'a, C, R, N> { + PostQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::CommentBorrowed, + mapper: fn(super::CommentBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CommentQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::CommentBorrowed) -> R, + ) -> CommentQuery<'a, C, R, N> { + CommentQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::SelectComplexBorrowed, + mapper: fn(super::SelectComplexBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectComplexQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectComplexBorrowed) -> R, + ) -> SelectComplexQuery<'a, C, R, N> { + SelectComplexQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> 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> { + UserQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::UserBorrowed { + id: row.get(0), + name: row.get(1), + hair_color: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + 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, + >( + &'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]) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::StringSql, + > + cornucopia_sync::Params< + 'a, + super::InsertUserParams, + Result, + C, + > for InsertUserStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::InsertUserParams, + ) -> Result { + self.bind(client, ¶ms.name, ¶ms.hair_color) + } + } + pub fn posts() -> PostsStmt { + PostsStmt(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> { + PostQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::PostBorrowed { + id: row.get(0), + user_id: row.get(1), + title: row.get(2), + body: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + 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>( + &'a mut self, + client: &'a mut C, + ids: &'a T1, + ) -> PostQuery<'a, C, super::Post, 1> { + PostQuery { + client, + params: [ids], + stmt: &mut self.0, + extractor: |row| super::PostBorrowed { + id: row.get(0), + user_id: row.get(1), + title: row.get(2), + body: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn comments() -> CommentsStmt { + CommentsStmt(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> { + CommentQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::CommentBorrowed { + id: row.get(0), + post_id: row.get(1), + text: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + 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>( + &'a mut self, + client: &'a mut C, + ids: &'a T1, + ) -> CommentQuery<'a, C, super::Comment, 1> { + CommentQuery { + client, + params: [ids], + stmt: &mut self.0, + extractor: |row| super::CommentBorrowed { + id: row.get(0), + post_id: row.get(1), + text: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + 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> { + SelectComplexQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectComplexBorrowed { + myuser_id: row.get(0), + name: row.get(1), + hair_color: row.get(2), + post_id: row.get(3), + user_id: row.get(4), + title: row.get(5), + body: row.get(6), + }, + mapper: |it| ::from(it), + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::UserBorrowed, + mapper: fn(super::UserBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> UserQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::UserBorrowed) -> R, + ) -> UserQuery<'a, C, R, N> { + UserQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::PostBorrowed, + mapper: fn(super::PostBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PostQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::PostBorrowed) -> R, + ) -> PostQuery<'a, C, R, N> { + PostQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::CommentBorrowed, + mapper: fn(super::CommentBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CommentQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::CommentBorrowed) -> R, + ) -> CommentQuery<'a, C, R, N> { + CommentQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::SelectComplexBorrowed, + mapper: fn(super::SelectComplexBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectComplexQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectComplexBorrowed) -> R, + ) -> SelectComplexQuery<'a, C, R, N> { + SelectComplexQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> UsersStmt { + UsersStmt(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> { + UserQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::UserBorrowed { + id: row.get(0), + name: row.get(1), + hair_color: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + pub fn insert_user() -> InsertUserStmt { + InsertUserStmt(cornucopia_async::private::Stmt::new( + "INSERT INTO users (name, hair_color) VALUES ($1, $2)", + )) + } + pub struct InsertUserStmt(cornucopia_async::private::Stmt); + impl InsertUserStmt { + 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 + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + super::InsertUserParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for InsertUserStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::InsertUserParams, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.name, ¶ms.hair_color)) + } + } + pub fn posts() -> PostsStmt { + PostsStmt(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> { + PostQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::PostBorrowed { + id: row.get(0), + user_id: row.get(1), + title: row.get(2), + body: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + 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>( + &'a mut self, + client: &'a C, + ids: &'a T1, + ) -> PostQuery<'a, C, super::Post, 1> { + PostQuery { + client, + params: [ids], + stmt: &mut self.0, + extractor: |row| super::PostBorrowed { + id: row.get(0), + user_id: row.get(1), + title: row.get(2), + body: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn comments() -> CommentsStmt { + CommentsStmt(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> { + CommentQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::CommentBorrowed { + id: row.get(0), + post_id: row.get(1), + text: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + 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>( + &'a mut self, + client: &'a C, + ids: &'a T1, + ) -> CommentQuery<'a, C, super::Comment, 1> { + CommentQuery { + client, + params: [ids], + stmt: &mut self.0, + extractor: |row| super::CommentBorrowed { + id: row.get(0), + post_id: row.get(1), + text: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + 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 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> { + SelectComplexQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectComplexBorrowed { + myuser_id: row.get(0), + name: row.get(1), + hair_color: row.get(2), + post_id: row.get(3), + user_id: row.get(4), + title: row.get(5), + body: row.get(6), + }, + mapper: |it| ::from(it), + } + } + } + } + } +} diff --git a/bench/usage/cornucopia_benches/generated_async.rs b/bench/usage/cornucopia_benches/generated_async.rs deleted file mode 100644 index be12bb7e..00000000 --- a/bench/usage/cornucopia_benches/generated_async.rs +++ /dev/null @@ -1,552 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types {} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod bench { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct InsertUserParams< - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - > { - pub name: T1, - pub hair_color: Option, - } - #[derive(Debug, Clone, PartialEq)] - pub struct User { - pub id: i32, - pub name: String, - pub hair_color: Option, - } - pub struct UserBorrowed<'a> { - pub id: i32, - pub name: &'a str, - pub hair_color: Option<&'a str>, - } - impl<'a> From> for User { - fn from( - UserBorrowed { - id, - name, - hair_color, - }: UserBorrowed<'a>, - ) -> Self { - Self { - id, - name: name.into(), - hair_color: hair_color.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> UserBorrowed, - mapper: fn(UserBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> UserQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(UserBorrowed) -> R) -> UserQuery<'a, C, R, N> { - UserQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Post { - pub id: i32, - pub user_id: i32, - pub title: String, - pub body: Option, - } - pub struct PostBorrowed<'a> { - pub id: i32, - pub user_id: i32, - pub title: &'a str, - pub body: Option<&'a str>, - } - impl<'a> From> for Post { - fn from( - PostBorrowed { - id, - user_id, - title, - body, - }: PostBorrowed<'a>, - ) -> Self { - Self { - id, - user_id, - title: title.into(), - body: body.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> PostBorrowed, - mapper: fn(PostBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> PostQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(PostBorrowed) -> R) -> PostQuery<'a, C, R, N> { - PostQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Comment { - pub id: i32, - pub post_id: i32, - pub text: String, - } - pub struct CommentBorrowed<'a> { - pub id: i32, - pub post_id: i32, - pub text: &'a str, - } - impl<'a> From> for Comment { - fn from(CommentBorrowed { id, post_id, text }: CommentBorrowed<'a>) -> Self { - Self { - id, - post_id, - text: text.into(), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> CommentBorrowed, - mapper: fn(CommentBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> CommentQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(CommentBorrowed) -> R) -> CommentQuery<'a, C, R, N> { - CommentQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct SelectComplex { - pub myuser_id: i32, - pub name: String, - pub hair_color: Option, - pub post_id: Option, - pub user_id: Option, - pub title: Option, - pub body: Option, - } - pub struct SelectComplexBorrowed<'a> { - pub myuser_id: i32, - pub name: &'a str, - pub hair_color: Option<&'a str>, - pub post_id: Option, - pub user_id: Option, - pub title: Option<&'a str>, - pub body: Option<&'a str>, - } - impl<'a> From> for SelectComplex { - fn from( - SelectComplexBorrowed { - myuser_id, - name, - hair_color, - post_id, - user_id, - title, - body, - }: SelectComplexBorrowed<'a>, - ) -> Self { - Self { - myuser_id, - name: name.into(), - hair_color: hair_color.map(|v| v.into()), - post_id, - user_id, - title: title.map(|v| v.into()), - body: body.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> SelectComplexBorrowed, - mapper: fn(SelectComplexBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectComplexQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectComplexBorrowed) -> R, - ) -> SelectComplexQuery<'a, C, R, N> { - SelectComplexQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> UsersStmt { - UsersStmt(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, User, 0> { - UserQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| UserBorrowed { - id: row.get(0), - name: row.get(1), - hair_color: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - pub fn insert_user() -> InsertUserStmt { - InsertUserStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO users (name, hair_color) VALUES ($1, $2)", - )) - } - pub struct InsertUserStmt(cornucopia_async::private::Stmt); - impl InsertUserStmt { - 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 - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - > - cornucopia_async::Params< - 'a, - InsertUserParams, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for InsertUserStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a InsertUserParams, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.name, ¶ms.hair_color)) - } - } - pub fn posts() -> PostsStmt { - PostsStmt(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, Post, 0> { - PostQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| PostBorrowed { - id: row.get(0), - user_id: row.get(1), - title: row.get(2), - body: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - 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>( - &'a mut self, - client: &'a C, - ids: &'a T1, - ) -> PostQuery<'a, C, Post, 1> { - PostQuery { - client, - params: [ids], - stmt: &mut self.0, - extractor: |row| PostBorrowed { - id: row.get(0), - user_id: row.get(1), - title: row.get(2), - body: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn comments() -> CommentsStmt { - CommentsStmt(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, Comment, 0> { - CommentQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| CommentBorrowed { - id: row.get(0), - post_id: row.get(1), - text: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - 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>( - &'a mut self, - client: &'a C, - ids: &'a T1, - ) -> CommentQuery<'a, C, Comment, 1> { - CommentQuery { - client, - params: [ids], - stmt: &mut self.0, - extractor: |row| CommentBorrowed { - id: row.get(0), - post_id: row.get(1), - text: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - 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 struct SelectComplexStmt(cornucopia_async::private::Stmt); - impl SelectComplexStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SelectComplexQuery<'a, C, SelectComplex, 0> { - SelectComplexQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectComplexBorrowed { - myuser_id: row.get(0), - name: row.get(1), - hair_color: row.get(2), - post_id: row.get(3), - user_id: row.get(4), - title: row.get(5), - body: row.get(6), - }, - mapper: |it| ::from(it), - } - } - } - } -} diff --git a/bench/usage/cornucopia_benches/generated_sync.rs b/bench/usage/cornucopia_benches/generated_sync.rs deleted file mode 100644 index 785ca302..00000000 --- a/bench/usage/cornucopia_benches/generated_sync.rs +++ /dev/null @@ -1,519 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types {} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod bench { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct InsertUserParams { - pub name: T1, - pub hair_color: Option, - } - #[derive(Debug, Clone, PartialEq)] - pub struct User { - pub id: i32, - pub name: String, - pub hair_color: Option, - } - pub struct UserBorrowed<'a> { - pub id: i32, - pub name: &'a str, - pub hair_color: Option<&'a str>, - } - impl<'a> From> for User { - fn from( - UserBorrowed { - id, - name, - hair_color, - }: UserBorrowed<'a>, - ) -> Self { - Self { - id, - name: name.into(), - hair_color: hair_color.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> UserBorrowed, - mapper: fn(UserBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> UserQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(UserBorrowed) -> R) -> UserQuery<'a, C, R, N> { - UserQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Post { - pub id: i32, - pub user_id: i32, - pub title: String, - pub body: Option, - } - pub struct PostBorrowed<'a> { - pub id: i32, - pub user_id: i32, - pub title: &'a str, - pub body: Option<&'a str>, - } - impl<'a> From> for Post { - fn from( - PostBorrowed { - id, - user_id, - title, - body, - }: PostBorrowed<'a>, - ) -> Self { - Self { - id, - user_id, - title: title.into(), - body: body.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> PostBorrowed, - mapper: fn(PostBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> PostQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(PostBorrowed) -> R) -> PostQuery<'a, C, R, N> { - PostQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct Comment { - pub id: i32, - pub post_id: i32, - pub text: String, - } - pub struct CommentBorrowed<'a> { - pub id: i32, - pub post_id: i32, - pub text: &'a str, - } - impl<'a> From> for Comment { - fn from(CommentBorrowed { id, post_id, text }: CommentBorrowed<'a>) -> Self { - Self { - id, - post_id, - text: text.into(), - } - } - } - 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, - extractor: fn(&postgres::Row) -> CommentBorrowed, - mapper: fn(CommentBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> CommentQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(CommentBorrowed) -> R) -> CommentQuery<'a, C, R, N> { - CommentQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(Debug, Clone, PartialEq)] - pub struct SelectComplex { - pub myuser_id: i32, - pub name: String, - pub hair_color: Option, - pub post_id: Option, - pub user_id: Option, - pub title: Option, - pub body: Option, - } - pub struct SelectComplexBorrowed<'a> { - pub myuser_id: i32, - pub name: &'a str, - pub hair_color: Option<&'a str>, - pub post_id: Option, - pub user_id: Option, - pub title: Option<&'a str>, - pub body: Option<&'a str>, - } - impl<'a> From> for SelectComplex { - fn from( - SelectComplexBorrowed { - myuser_id, - name, - hair_color, - post_id, - user_id, - title, - body, - }: SelectComplexBorrowed<'a>, - ) -> Self { - Self { - myuser_id, - name: name.into(), - hair_color: hair_color.map(|v| v.into()), - post_id, - user_id, - title: title.map(|v| v.into()), - body: body.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> SelectComplexBorrowed, - mapper: fn(SelectComplexBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectComplexQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectComplexBorrowed) -> R, - ) -> SelectComplexQuery<'a, C, R, N> { - SelectComplexQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> 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, User, 0> { - UserQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| UserBorrowed { - id: row.get(0), - name: row.get(1), - hair_color: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - 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, - >( - &'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]) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - > - cornucopia_sync::Params<'a, InsertUserParams, Result, C> - for InsertUserStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a InsertUserParams, - ) -> Result { - self.bind(client, ¶ms.name, ¶ms.hair_color) - } - } - pub fn posts() -> PostsStmt { - PostsStmt(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, Post, 0> { - PostQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| PostBorrowed { - id: row.get(0), - user_id: row.get(1), - title: row.get(2), - body: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - 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>( - &'a mut self, - client: &'a mut C, - ids: &'a T1, - ) -> PostQuery<'a, C, Post, 1> { - PostQuery { - client, - params: [ids], - stmt: &mut self.0, - extractor: |row| PostBorrowed { - id: row.get(0), - user_id: row.get(1), - title: row.get(2), - body: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn comments() -> CommentsStmt { - CommentsStmt(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, Comment, 0> { - CommentQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| CommentBorrowed { - id: row.get(0), - post_id: row.get(1), - text: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - 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>( - &'a mut self, - client: &'a mut C, - ids: &'a T1, - ) -> CommentQuery<'a, C, Comment, 1> { - CommentQuery { - client, - params: [ids], - stmt: &mut self.0, - extractor: |row| CommentBorrowed { - id: row.get(0), - post_id: row.get(1), - text: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - 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, SelectComplex, 0> { - SelectComplexQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectComplexBorrowed { - myuser_id: row.get(0), - name: row.get(1), - hair_color: row.get(2), - post_id: row.get(3), - user_id: row.get(4), - title: row.get(5), - body: row.get(6), - }, - mapper: |it| ::from(it), - } - } - } - } -} diff --git a/bench/usage/cornucopia_benches/mod.rs b/bench/usage/cornucopia_benches/mod.rs index 79814d7f..d81081f7 100644 --- a/bench/usage/cornucopia_benches/mod.rs +++ b/bench/usage/cornucopia_benches/mod.rs @@ -4,12 +4,12 @@ use criterion::Bencher; use futures::executor::block_on; use tokio_postgres::Client; -use self::generated_async::queries::bench::{ - comments_by_post_id, insert_user, post_by_user_ids, select_complex, users, Comment, Post, User, +use self::generated::queries::bench::{ + async_::{comments_by_post_id, insert_user, post_by_user_ids, select_complex, users}, + Comment, Post, User, }; -mod generated_async; -mod generated_sync; +mod generated; pub fn bench_trivial_query(b: &mut Bencher, client: &Client) { let mut stmt = users(); @@ -118,9 +118,9 @@ pub mod sync { use criterion::Bencher; use postgres::Client; - use super::generated_sync::queries::bench::{ - comments_by_post_id, insert_user, post_by_user_ids, select_complex, users, Comment, Post, - User, + use super::generated::queries::bench::{ + sync::{comments_by_post_id, insert_user, post_by_user_ids, select_complex, users}, + Comment, Post, User, }; pub fn bench_trivial_query(b: &mut Bencher, client: &mut Client) { let mut stmt = users(); diff --git a/codegen_template/src/lib.rs b/codegen_template/src/lib.rs index 4547a1b9..6e1e940f 100644 --- a/codegen_template/src/lib.rs +++ b/codegen_template/src/lib.rs @@ -36,6 +36,20 @@ fn parse_ident<'a>(scan: &mut Scanner<'a>) -> Option<&'a str> { } } +/// Parse out identifier 'ident =>' +fn parse_out<'a>(scan: &mut Scanner<'a>) -> Option<&'a str> { + let start = scan.cursor(); + scan.eat_whitespace(); + if let Some(ident) = parse_ident(scan) { + scan.eat_whitespace(); + if scan.eat_if("=>") { + return Some(ident); + } + } + scan.jump(start); + None +} + /// Parse the next raw string and optional pattern pair from `scan` /// Return ("", None) when reach EOF fn parse_next<'a>(scan: &mut Scanner<'a>) -> (&'a str, Option>) { @@ -203,15 +217,17 @@ fn gen_recursive(scan: &mut Scanner, s: &mut String, out: &str) { pub fn code(pattern: TokenStream) -> TokenStream { let pattern = pattern.to_string(); let mut scan = unscanny::Scanner::new(&pattern); - scan.eat_whitespace(); - let out = scan.eat_while(id_continue); - scan.eat_whitespace(); - scan.expect("=>"); - scan.eat_whitespace(); + let out = parse_out(&mut scan); let mut s = String::new(); s.push('{'); - gen_recursive(&mut scan, &mut s, out); + if let Some(out) = out { + gen_recursive(&mut scan, &mut s, out); + } else { + s.push_str("let mut out = String::new();\n"); + gen_recursive(&mut scan, &mut s, "out"); + s.push_str("out") + } s.push('}'); s.parse().unwrap() } diff --git a/codegen_test/src/cornucopia.rs b/codegen_test/src/cornucopia.rs new file mode 100644 index 00000000..38df419d --- /dev/null +++ b/codegen_test/src/cornucopia.rs @@ -0,0 +1,8294 @@ +// This file was generated with `cornucopia`. Do not modify. + +#[allow(clippy::all, clippy::pedantic)] +#[allow(unused_variables)] +#[allow(unused_imports)] +#[allow(dead_code)] +pub mod types { + pub mod public { + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "clone_composite")] + pub struct CloneComposite { + #[postgres(name = "first")] + pub first: i32, + #[postgres(name = "second")] + pub second: String, + } + #[derive(Debug)] + pub struct CloneCompositeBorrowed<'a> { + pub first: i32, + pub second: &'a str, + } + impl<'a> From> for CloneComposite { + fn from(CloneCompositeBorrowed { first, second }: CloneCompositeBorrowed<'a>) -> Self { + Self { + first, + second: second.into(), + } + } + } + impl<'a> postgres_types::FromSql<'a> for CloneCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let first = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let second = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + Ok(CloneCompositeBorrowed { first, second }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "clone_composite" && ty.schema() == "public" + } + } + impl<'a> postgres_types::ToSql for CloneCompositeBorrowed<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let CloneCompositeBorrowed { first, second } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), + "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "clone_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 2 { + return false; + } + fields.iter().all(|f| match f.name() { + "first" => ::accepts(f.type_()), + "second" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[postgres(name = "copy_composite")] + pub struct CopyComposite { + #[postgres(name = "first")] + pub first: i32, + #[postgres(name = "second")] + pub second: f64, + } + impl<'a> postgres_types::ToSql for CopyComposite { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let CopyComposite { first, second } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), + "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "copy_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 2 { + return false; + } + fields.iter().all(|f| match f.name() { + "first" => ::accepts(f.type_()), + "second" => ::accepts(f.type_()), + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "domain_composite")] + pub struct DomainComposite { + #[postgres(name = "txt")] + pub txt: String, + #[postgres(name = "json")] + pub json: serde_json::Value, + #[postgres(name = "nb")] + pub nb: i32, + #[postgres(name = "arr")] + pub arr: Vec, + } + #[derive(Debug)] + pub struct DomainCompositeBorrowed<'a> { + pub txt: &'a str, + pub json: postgres_types::Json<&'a serde_json::value::RawValue>, + pub nb: i32, + pub arr: cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + } + impl<'a> From> for DomainComposite { + fn from( + DomainCompositeBorrowed { txt, json, nb, arr }: DomainCompositeBorrowed<'a>, + ) -> Self { + Self { + txt: txt.into(), + json: serde_json::from_str(json.0.get()).unwrap(), + nb, + arr: arr + .map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect(), + } + } + } + impl<'a> postgres_types::FromSql<'a> for DomainCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let txt = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let json = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let nb = postgres_types::private::read_value(fields[2].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let arr = postgres_types::private::read_value(fields[3].type_(), &mut out)?; + Ok(DomainCompositeBorrowed { txt, json, nb, arr }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "domain_composite" && ty.schema() == "public" + } + } + #[derive(Debug)] + pub struct DomainCompositeParams<'a> { + pub txt: &'a str, + pub json: &'a serde_json::value::Value, + pub nb: i32, + pub arr: &'a [&'a serde_json::value::Value], + } + impl<'a> postgres_types::ToSql for DomainCompositeParams<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let DomainCompositeParams { txt, json, nb, arr } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "txt" => postgres_types::ToSql::to_sql( + &cornucopia_async::private::Domain(txt), + field.type_(), + out, + ), + "json" => postgres_types::ToSql::to_sql( + &cornucopia_async::private::Domain(json), + field.type_(), + out, + ), + "nb" => postgres_types::ToSql::to_sql( + &cornucopia_async::private::Domain(nb), + field.type_(), + out, + ), + "arr" => postgres_types::ToSql::to_sql( + &cornucopia_async::private::Domain( + &cornucopia_async::private::DomainArray(arr), + ), + field.type_(), + out, + ), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "domain_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 4 { + return false; + } + fields.iter().all(| f | match f.name() + { + "txt" => < cornucopia_async::private::Domain::<&'a str> as postgres_types :: + ToSql > :: accepts(f.type_()),"json" => < cornucopia_async::private::Domain::<&'a serde_json::value::Value> as postgres_types :: + ToSql > :: accepts(f.type_()),"nb" => < cornucopia_async::private::Domain:: as postgres_types :: + ToSql > :: accepts(f.type_()),"arr" => < cornucopia_async::private::Domain::> as postgres_types :: + ToSql > :: accepts(f.type_()),_ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "named_composite")] + pub struct NamedComposite { + #[postgres(name = "wow")] + pub wow: Option, + #[postgres(name = "such_cool")] + pub such_cool: Option, + } + #[derive(Debug)] + pub struct NamedCompositeBorrowed<'a> { + pub wow: Option<&'a str>, + pub such_cool: Option, + } + impl<'a> From> for NamedComposite { + fn from(NamedCompositeBorrowed { wow, such_cool }: NamedCompositeBorrowed<'a>) -> Self { + Self { + wow: wow.map(|v| v.into()), + such_cool, + } + } + } + impl<'a> postgres_types::FromSql<'a> for NamedCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + Ok(NamedCompositeBorrowed { wow, such_cool }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "named_composite" && ty.schema() == "public" + } + } + impl<'a> postgres_types::ToSql for NamedCompositeBorrowed<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let NamedCompositeBorrowed { wow, such_cool } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), + "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "named_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 2 { + return false; + } + fields.iter().all(|f| match f.name() { + "wow" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), + "such_cool" => ::accepts(f.type_()), + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[allow(non_camel_case_types)] + pub enum EnumWithDot { + variant_with_dot, + } + impl<'a> postgres_types::ToSql for EnumWithDot { + fn to_sql( + &self, + ty: &postgres_types::Type, + buf: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let s = match *self { + EnumWithDot::variant_with_dot => "variant.with_dot", + }; + buf.extend_from_slice(s.as_bytes()); + std::result::Result::Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "enum.with_dot" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 1 { + return false; + } + variants.iter().all(|v| match &**v { + "variant.with_dot" => true, + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + impl<'a> postgres_types::FromSql<'a> for EnumWithDot { + fn from_sql( + ty: &postgres_types::Type, + buf: &'a [u8], + ) -> Result> { + match std::str::from_utf8(buf)? { + "variant.with_dot" => Ok(EnumWithDot::variant_with_dot), + s => Result::Err(Into::into(format!("invalid variant `{}`", s))), + } + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "enum.with_dot" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 1 { + return false; + } + variants.iter().all(|v| match &**v { + "variant.with_dot" => true, + _ => false, + }) + } + _ => false, + } + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[postgres(name = "named_composite.with_dot")] + pub struct NamedCompositeWithDot { + #[postgres(name = "this.is.inconceivable")] + pub this_is_inconceivable: Option, + } + impl<'a> postgres_types::ToSql for NamedCompositeWithDot { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let NamedCompositeWithDot { + this_is_inconceivable, + } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "this.is.inconceivable" => { + postgres_types::ToSql::to_sql(this_is_inconceivable, field.type_(), out) + } + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "named_composite.with_dot" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 1 { + return false; + } + fields.iter().all(|f| match f.name() { + "this.is.inconceivable" => { + ::accepts( + f.type_(), + ) + } + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "nullity_composite")] + pub struct NullityComposite { + #[postgres(name = "jsons")] + pub jsons: Option>>, + #[postgres(name = "id")] + pub id: i32, + } + #[derive(Debug)] + pub struct NullityCompositeBorrowed<'a> { + pub jsons: Option< + cornucopia_async::ArrayIterator< + 'a, + Option>, + >, + >, + pub id: i32, + } + impl<'a> From> for NullityComposite { + fn from(NullityCompositeBorrowed { jsons, id }: NullityCompositeBorrowed<'a>) -> Self { + Self { + jsons: jsons.map(|v| { + v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) + .collect() + }), + id, + } + } + } + impl<'a> postgres_types::FromSql<'a> for NullityCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let jsons = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let id = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + Ok(NullityCompositeBorrowed { jsons, id }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "nullity_composite" && ty.schema() == "public" + } + } + #[derive(Debug)] + pub struct NullityCompositeParams<'a> { + pub jsons: Option<&'a [Option<&'a serde_json::value::Value>]>, + pub id: i32, + } + impl<'a> postgres_types::ToSql for NullityCompositeParams<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let NullityCompositeParams { jsons, id } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "jsons" => postgres_types::ToSql::to_sql(jsons, field.type_(), out), + "id" => postgres_types::ToSql::to_sql(id, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "nullity_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 2 { + return false; + } + fields.iter().all(|f| { + match f.name() + { + "jsons" => < &'a [&'a serde_json::value::Value] as postgres_types :: + ToSql > :: accepts(f.type_()),"id" => < i32 as postgres_types :: + ToSql > :: accepts(f.type_()),_ => false, + } + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[allow(non_camel_case_types)] + pub enum SpongebobCharacter { + Bob, + Patrick, + Squidward, + } + impl<'a> postgres_types::ToSql for SpongebobCharacter { + fn to_sql( + &self, + ty: &postgres_types::Type, + buf: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let s = match *self { + SpongebobCharacter::Bob => "Bob", + SpongebobCharacter::Patrick => "Patrick", + SpongebobCharacter::Squidward => "Squidward", + }; + buf.extend_from_slice(s.as_bytes()); + std::result::Result::Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "spongebob_character" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 3 { + return false; + } + variants.iter().all(|v| match &**v { + "Bob" => true, + "Patrick" => true, + "Squidward" => true, + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + impl<'a> postgres_types::FromSql<'a> for SpongebobCharacter { + fn from_sql( + ty: &postgres_types::Type, + buf: &'a [u8], + ) -> Result> { + match std::str::from_utf8(buf)? { + "Bob" => Ok(SpongebobCharacter::Bob), + "Patrick" => Ok(SpongebobCharacter::Patrick), + "Squidward" => Ok(SpongebobCharacter::Squidward), + s => Result::Err(Into::into(format!("invalid variant `{}`", s))), + } + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "spongebob_character" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 3 { + return false; + } + variants.iter().all(|v| match &**v { + "Bob" => true, + "Patrick" => true, + "Squidward" => true, + _ => false, + }) + } + _ => false, + } + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "custom_composite")] + pub struct CustomComposite { + #[postgres(name = "wow")] + pub wow: String, + #[postgres(name = "such_cool")] + pub such_cool: i32, + #[postgres(name = "nice")] + pub nice: super::public::SpongebobCharacter, + } + #[derive(Debug)] + pub struct CustomCompositeBorrowed<'a> { + pub wow: &'a str, + pub such_cool: i32, + pub nice: super::public::SpongebobCharacter, + } + impl<'a> From> for CustomComposite { + fn from( + CustomCompositeBorrowed { + wow, + such_cool, + nice, + }: CustomCompositeBorrowed<'a>, + ) -> Self { + Self { + wow: wow.into(), + such_cool, + nice, + } + } + } + impl<'a> postgres_types::FromSql<'a> for CustomCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let nice = postgres_types::private::read_value(fields[2].type_(), &mut out)?; + Ok(CustomCompositeBorrowed { + wow, + such_cool, + nice, + }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "custom_composite" && ty.schema() == "public" + } + } + impl<'a> postgres_types::ToSql for CustomCompositeBorrowed<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let CustomCompositeBorrowed { + wow, + such_cool, + nice, + } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), + "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), + "nice" => postgres_types::ToSql::to_sql(nice, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "custom_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 3 { + return false; + } + fields.iter().all(| f | match f.name() + { + "wow" => < &'a str as postgres_types :: + ToSql > :: accepts(f.type_()),"such_cool" => < i32 as postgres_types :: + ToSql > :: accepts(f.type_()),"nice" => < super::public::SpongebobCharacter as postgres_types :: + ToSql > :: accepts(f.type_()),_ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] + #[postgres(name = "nightmare_composite")] + pub struct NightmareComposite { + #[postgres(name = "custom")] + pub custom: Vec, + #[postgres(name = "spongebob")] + pub spongebob: Vec, + #[postgres(name = "domain")] + pub domain: String, + } + #[derive(Debug)] + pub struct NightmareCompositeBorrowed<'a> { + pub custom: + cornucopia_async::ArrayIterator<'a, super::public::CustomCompositeBorrowed<'a>>, + pub spongebob: cornucopia_async::ArrayIterator<'a, super::public::SpongebobCharacter>, + pub domain: &'a str, + } + impl<'a> From> for NightmareComposite { + fn from( + NightmareCompositeBorrowed { + custom, + spongebob, + domain, + }: NightmareCompositeBorrowed<'a>, + ) -> Self { + Self { + custom: custom.map(|v| v.into()).collect(), + spongebob: spongebob.map(|v| v).collect(), + domain: domain.into(), + } + } + } + impl<'a> postgres_types::FromSql<'a> for NightmareCompositeBorrowed<'a> { + fn from_sql( + ty: &postgres_types::Type, + out: &'a [u8], + ) -> Result, Box> + { + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + let mut out = out; + let num_fields = postgres_types::private::read_be_i32(&mut out)?; + if num_fields as usize != fields.len() { + return std::result::Result::Err(std::convert::Into::into(format!( + "invalid field count: {} vs {}", + num_fields, + fields.len() + ))); + } + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let custom = postgres_types::private::read_value(fields[0].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let spongebob = postgres_types::private::read_value(fields[1].type_(), &mut out)?; + let _oid = postgres_types::private::read_be_i32(&mut out)?; + let domain = postgres_types::private::read_value(fields[2].type_(), &mut out)?; + Ok(NightmareCompositeBorrowed { + custom, + spongebob, + domain, + }) + } + fn accepts(ty: &postgres_types::Type) -> bool { + ty.name() == "nightmare_composite" && ty.schema() == "public" + } + } + #[derive(Debug)] + pub struct NightmareCompositeParams<'a> { + pub custom: &'a [super::public::CustomCompositeBorrowed<'a>], + pub spongebob: &'a [super::public::SpongebobCharacter], + pub domain: &'a str, + } + impl<'a> postgres_types::ToSql for NightmareCompositeParams<'a> { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let NightmareCompositeParams { + custom, + spongebob, + domain, + } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "custom" => postgres_types::ToSql::to_sql(custom, field.type_(), out), + "spongebob" => postgres_types::ToSql::to_sql(spongebob, field.type_(), out), + "domain" => postgres_types::ToSql::to_sql( + &cornucopia_async::private::Domain(domain), + field.type_(), + out, + ), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "nightmare_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 3 { + return false; + } + fields.iter().all(| f | match f.name() + { + "custom" => < &'a [super::public::CustomCompositeBorrowed<'a>] as postgres_types :: + ToSql > :: accepts(f.type_()),"spongebob" => < &'a [super::public::SpongebobCharacter] as postgres_types :: + ToSql > :: accepts(f.type_()),"domain" => < cornucopia_async::private::Domain::<&'a str> as postgres_types :: + ToSql > :: accepts(f.type_()),_ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] + #[postgres(name = "syntax_composite")] + pub struct SyntaxComposite { + #[postgres(name = "async")] + pub r#async: i32, + } + impl<'a> postgres_types::ToSql for SyntaxComposite { + fn to_sql( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let SyntaxComposite { r#async } = self; + let fields = match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => fields, + _ => unreachable!(), + }; + out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); + for field in fields { + out.extend_from_slice(&field.type_().oid().to_be_bytes()); + let base = out.len(); + out.extend_from_slice(&[0; 4]); + let r = match field.name() { + "async" => postgres_types::ToSql::to_sql(r#async, field.type_(), out), + _ => unreachable!(), + }; + let count = match r? { + postgres_types::IsNull::Yes => -1, + postgres_types::IsNull::No => { + let len = out.len() - base - 4; + if len > i32::max_value() as usize { + return Err(Into::into("value too large to transmit")); + } + len as i32 + } + }; + out[base..base + 4].copy_from_slice(&count.to_be_bytes()); + } + Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "syntax_composite" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Composite(ref fields) => { + if fields.len() != 1 { + return false; + } + fields.iter().all(|f| match f.name() { + "async" => ::accepts(f.type_()), + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] + #[allow(non_camel_case_types)] + pub enum SyntaxEnum { + r#async, + r#box, + I_Love_Chocolate, + } + impl<'a> postgres_types::ToSql for SyntaxEnum { + fn to_sql( + &self, + ty: &postgres_types::Type, + buf: &mut postgres_types::private::BytesMut, + ) -> Result> + { + let s = match *self { + SyntaxEnum::r#async => "async", + SyntaxEnum::r#box => "box", + SyntaxEnum::I_Love_Chocolate => "I Love Chocolate", + }; + buf.extend_from_slice(s.as_bytes()); + std::result::Result::Ok(postgres_types::IsNull::No) + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "syntax_enum" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 3 { + return false; + } + variants.iter().all(|v| match &**v { + "async" => true, + "box" => true, + "I Love Chocolate" => true, + _ => false, + }) + } + _ => false, + } + } + fn to_sql_checked( + &self, + ty: &postgres_types::Type, + out: &mut postgres_types::private::BytesMut, + ) -> Result> + { + postgres_types::__to_sql_checked(self, ty, out) + } + } + impl<'a> postgres_types::FromSql<'a> for SyntaxEnum { + fn from_sql( + ty: &postgres_types::Type, + buf: &'a [u8], + ) -> Result> { + match std::str::from_utf8(buf)? { + "async" => Ok(SyntaxEnum::r#async), + "box" => Ok(SyntaxEnum::r#box), + "I Love Chocolate" => Ok(SyntaxEnum::I_Love_Chocolate), + s => Result::Err(Into::into(format!("invalid variant `{}`", s))), + } + } + fn accepts(ty: &postgres_types::Type) -> bool { + if ty.name() != "syntax_enum" { + return false; + } + match *ty.kind() { + postgres_types::Kind::Enum(ref variants) => { + if variants.len() != 3 { + return false; + } + variants.iter().all(|v| match &**v { + "async" => true, + "box" => true, + "I Love Chocolate" => true, + _ => false, + }) + } + _ => false, + } + } + } + } +} +#[allow(clippy::all, clippy::pedantic)] +#[allow(unused_variables)] +#[allow(unused_imports)] +#[allow(dead_code)] +pub mod queries { + pub mod copy { + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn( + &postgres::Row, + ) + -> super::super::super::types::public::CloneCompositeBorrowed, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCloneCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> R, + ) -> PublicCloneCompositeQuery<'a, C, R, N> { + PublicCloneCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::super::super::types::public::CopyComposite, + mapper: fn(super::super::super::types::public::CopyComposite) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCopyCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CopyComposite) -> R, + ) -> PublicCopyCompositeQuery<'a, C, R, N> { + PublicCopyCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> 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>( + &'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]) + } + } + pub fn select_clone() -> SelectCloneStmt { + SelectCloneStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) + } + pub struct SelectCloneStmt(cornucopia_sync::private::Stmt); + impl SelectCloneStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + 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 struct InsertCopyStmt(cornucopia_sync::private::Stmt); + impl InsertCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + pub fn select_copy() -> SelectCopyStmt { + SelectCopyStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM copy")) + } + pub struct SelectCopyStmt(cornucopia_sync::private::Stmt); + impl SelectCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> PublicCopyCompositeQuery< + 'a, + C, + super::super::super::types::public::CopyComposite, + 0, + > { + PublicCopyCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn( + &tokio_postgres::Row, + ) + -> super::super::super::types::public::CloneCompositeBorrowed, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCloneCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> R, + ) -> PublicCloneCompositeQuery<'a, C, R, N> { + PublicCloneCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: + fn(&tokio_postgres::Row) -> super::super::super::types::public::CopyComposite, + mapper: fn(super::super::super::types::public::CopyComposite) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCopyCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CopyComposite) -> R, + ) -> PublicCopyCompositeQuery<'a, C, R, N> { + PublicCopyCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> InsertCloneStmt { + InsertCloneStmt(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>( + &'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 + } + } + pub fn select_clone() -> SelectCloneStmt { + SelectCloneStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) + } + pub struct SelectCloneStmt(cornucopia_async::private::Stmt); + impl SelectCloneStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + 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 struct InsertCopyStmt(cornucopia_async::private::Stmt); + impl InsertCopyStmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + pub fn select_copy() -> SelectCopyStmt { + SelectCopyStmt(cornucopia_async::private::Stmt::new("SELECT * FROM copy")) + } + pub struct SelectCopyStmt(cornucopia_async::private::Stmt); + impl SelectCopyStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> PublicCopyCompositeQuery< + 'a, + C, + super::super::super::types::public::CopyComposite, + 0, + > { + PublicCopyCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + } + } + pub mod domain { + #[derive(Debug)] + pub struct InsertNightmareDomainParams< + 'a, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::JsonSql, + T3: cornucopia_async::JsonSql, + T4: cornucopia_async::ArraySql, + > { + pub txt: T1, + pub json: T2, + pub nb: i32, + pub arr: T4, + pub composite: Option>, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct SelectNightmareDomain { + pub txt: String, + pub json: serde_json::Value, + pub nb: i32, + pub arr: Vec, + } + pub struct SelectNightmareDomainBorrowed<'a> { + pub txt: &'a str, + pub json: postgres_types::Json<&'a serde_json::value::RawValue>, + pub nb: i32, + pub arr: cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + } + impl<'a> From> for SelectNightmareDomain { + fn from( + SelectNightmareDomainBorrowed { txt, json, nb, arr }: SelectNightmareDomainBorrowed< + 'a, + >, + ) -> Self { + Self { + txt: txt.into(), + json: serde_json::from_str(json.0.get()).unwrap(), + nb, + arr: arr + .map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect(), + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct SelectNightmareDomainNull { + pub txt: Option, + pub json: Option, + pub nb: Option, + pub arr: Option>>, + pub composite: Option, + } + pub struct SelectNightmareDomainNullBorrowed<'a> { + pub txt: Option<&'a str>, + pub json: Option>, + pub nb: Option, + pub arr: Option< + cornucopia_async::ArrayIterator< + 'a, + Option>, + >, + >, + pub composite: Option>, + } + impl<'a> From> for SelectNightmareDomainNull { + fn from( + SelectNightmareDomainNullBorrowed { + txt, + json, + nb, + arr, + composite, + }: SelectNightmareDomainNullBorrowed<'a>, + ) -> Self { + Self { + txt: txt.map(|v| v.into()), + json: json.map(|v| serde_json::from_str(v.0.get()).unwrap()), + nb, + arr: arr.map(|v| { + v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) + .collect() + }), + composite: composite.map(|v| v.into()), + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::SelectNightmareDomainBorrowed, + mapper: fn(super::SelectNightmareDomainBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectNightmareDomainBorrowed) -> R, + ) -> SelectNightmareDomainQuery<'a, C, R, N> { + SelectNightmareDomainQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::SelectNightmareDomainNullBorrowed, + mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectNightmareDomainNullBorrowed) -> R, + ) -> SelectNightmareDomainNullQuery<'a, C, R, N> { + SelectNightmareDomainNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> SelectNightmareDomainStmt { + SelectNightmareDomainStmt(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>( + &'a mut self, + client: &'a mut C, + ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> + { + SelectNightmareDomainQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectNightmareDomainBorrowed { + txt: row.get(0), + json: row.get(1), + nb: row.get(2), + arr: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + 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 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, + arr: &'a T4, + composite: &'a Option< + super::super::super::types::public::DomainCompositeParams<'a>, + >, + ) -> Result { + let stmt = self.0.prepare(client)?; + client.execute( + stmt, + &[ + &cornucopia_sync::private::Domain(txt), + &cornucopia_sync::private::Domain(json), + &cornucopia_sync::private::Domain(nb), + &cornucopia_sync::private::Domain( + &cornucopia_sync::private::DomainArray(arr), + ), + composite, + ], + ) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::JsonSql, + T3: cornucopia_sync::JsonSql, + T4: cornucopia_sync::ArraySql, + > + cornucopia_sync::Params< + 'a, + super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, + Result, + C, + > for InsertNightmareDomainStmt + { + 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, + ¶ms.arr, + ¶ms.composite, + ) + } + } + pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { + SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt::new( + "SELECT * FROM nightmare_domain", + )) + } + pub struct SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt); + impl SelectNightmareDomainNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> + { + SelectNightmareDomainNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectNightmareDomainNullBorrowed { + txt: row.get(0), + json: row.get(1), + nb: row.get(2), + arr: row.get(3), + composite: row.get(4), + }, + mapper: |it| ::from(it), + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainBorrowed, + mapper: fn(super::SelectNightmareDomainBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectNightmareDomainBorrowed) -> R, + ) -> SelectNightmareDomainQuery<'a, C, R, N> { + SelectNightmareDomainQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::SelectNightmareDomainNullBorrowed, + mapper: fn(super::SelectNightmareDomainNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectNightmareDomainNullBorrowed) -> R, + ) -> SelectNightmareDomainNullQuery<'a, C, R, N> { + SelectNightmareDomainNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> SelectNightmareDomainStmt { + SelectNightmareDomainStmt(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>( + &'a mut self, + client: &'a C, + ) -> SelectNightmareDomainQuery<'a, C, super::SelectNightmareDomain, 0> + { + SelectNightmareDomainQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectNightmareDomainBorrowed { + txt: row.get(0), + json: row.get(1), + nb: row.get(2), + arr: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + 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 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, + arr: &'a T4, + composite: &'a Option< + super::super::super::types::public::DomainCompositeParams<'a>, + >, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute( + stmt, + &[ + &cornucopia_async::private::Domain(txt), + &cornucopia_async::private::Domain(json), + &cornucopia_async::private::Domain(nb), + &cornucopia_async::private::Domain( + &cornucopia_async::private::DomainArray(arr), + ), + composite, + ], + ) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::JsonSql, + T3: cornucopia_async::JsonSql, + T4: cornucopia_async::ArraySql, + > + cornucopia_async::Params< + 'a, + super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for InsertNightmareDomainStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::InsertNightmareDomainParams<'a, T1, T2, T3, T4>, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind( + client, + ¶ms.txt, + ¶ms.json, + ¶ms.nb, + ¶ms.arr, + ¶ms.composite, + )) + } + } + pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { + SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM nightmare_domain", + )) + } + pub struct SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt); + impl SelectNightmareDomainNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> SelectNightmareDomainNullQuery<'a, C, super::SelectNightmareDomainNull, 0> + { + SelectNightmareDomainNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectNightmareDomainNullBorrowed { + txt: row.get(0), + json: row.get(1), + nb: row.get(2), + arr: row.get(3), + composite: row.get(4), + }, + mapper: |it| ::from(it), + } + } + } + } + } + pub mod named { + #[derive(Debug)] + pub struct NamedParams { + pub name: T1, + pub price: Option, + } + #[derive(Debug)] + pub struct NamedComplexParams<'a> { + pub named: super::super::types::public::NamedCompositeBorrowed<'a>, + pub named_with_dot: Option, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + pub struct Id { + pub id: i32, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct Named { + pub id: i32, + pub name: String, + pub price: Option, + pub show: bool, + } + pub struct NamedBorrowed<'a> { + pub id: i32, + pub name: &'a str, + pub price: Option, + pub show: bool, + } + impl<'a> From> for Named { + fn from( + NamedBorrowed { + id, + name, + price, + show, + }: NamedBorrowed<'a>, + ) -> Self { + Self { + id, + name: name.into(), + price, + show, + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct NamedComplex { + pub named: super::super::types::public::NamedComposite, + pub named_with_dot: Option, + } + pub struct NamedComplexBorrowed<'a> { + pub named: super::super::types::public::NamedCompositeBorrowed<'a>, + pub named_with_dot: Option, + } + impl<'a> From> for NamedComplex { + fn from( + NamedComplexBorrowed { + named, + named_with_dot, + }: NamedComplexBorrowed<'a>, + ) -> Self { + Self { + named: named.into(), + named_with_dot, + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::Id, + mapper: fn(super::Id) -> T, + } + impl<'a, C, T: 'a, const N: usize> IdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(super::Id) -> R) -> IdQuery<'a, C, R, N> { + IdQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::NamedBorrowed, + mapper: fn(super::NamedBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NamedQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NamedBorrowed) -> R, + ) -> NamedQuery<'a, C, R, N> { + NamedQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::NamedComplexBorrowed, + mapper: fn(super::NamedComplexBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NamedComplexQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NamedComplexBorrowed) -> R, + ) -> NamedComplexQuery<'a, C, R, N> { + NamedComplexQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> NewNamedVisibleStmt { + NewNamedVisibleStmt(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>( + &'a mut self, + client: &'a mut C, + name: &'a T1, + price: &'a Option, + ) -> IdQuery<'a, C, super::Id, 2> { + IdQuery { + client, + params: [name, price], + stmt: &mut 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>, C> + for NewNamedVisibleStmt + { + 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) + } + } + 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 struct NewNamedHiddenStmt(cornucopia_sync::private::Stmt); + impl NewNamedHiddenStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a mut self, + client: &'a mut C, + price: &'a Option, + name: &'a T1, + ) -> IdQuery<'a, C, super::Id, 2> { + IdQuery { + client, + params: [price, name], + stmt: &mut 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>, C> + for NewNamedHiddenStmt + { + 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) + } + } + pub fn named() -> NamedStmt { + NamedStmt(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> { + NamedQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NamedBorrowed { + id: row.get(0), + name: row.get(1), + price: row.get(2), + show: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn named_by_id() -> NamedByIdStmt { + NamedByIdStmt(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> { + NamedQuery { + client, + params: [id], + stmt: &mut self.0, + extractor: |row| super::NamedBorrowed { + id: row.get(0), + name: row.get(1), + price: row.get(2), + show: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn new_named_complex() -> NewNamedComplexStmt { + NewNamedComplexStmt(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>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::NamedComplexParams<'a>, + Result, + C, + > for NewNamedComplexStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::NamedComplexParams<'a>, + ) -> Result { + self.bind(client, ¶ms.named, ¶ms.named_with_dot) + } + } + pub fn named_complex() -> NamedComplexStmt { + NamedComplexStmt(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> { + NamedComplexQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NamedComplexBorrowed { + named: row.get(0), + named_with_dot: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::Id, + mapper: fn(super::Id) -> T, + } + impl<'a, C, T: 'a, const N: usize> IdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(super::Id) -> R) -> IdQuery<'a, C, R, N> { + IdQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::NamedBorrowed, + mapper: fn(super::NamedBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NamedQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NamedBorrowed) -> R, + ) -> NamedQuery<'a, C, R, N> { + NamedQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::NamedComplexBorrowed, + mapper: fn(super::NamedComplexBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NamedComplexQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NamedComplexBorrowed) -> R, + ) -> NamedComplexQuery<'a, C, R, N> { + NamedComplexQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> NewNamedVisibleStmt { + NewNamedVisibleStmt(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>( + &'a mut self, + client: &'a C, + name: &'a T1, + price: &'a Option, + ) -> IdQuery<'a, C, super::Id, 2> { + IdQuery { + client, + params: [name, price], + stmt: &mut 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>, + C, + > for NewNamedVisibleStmt + { + 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) + } + } + 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 struct NewNamedHiddenStmt(cornucopia_async::private::Stmt); + impl NewNamedHiddenStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + price: &'a Option, + name: &'a T1, + ) -> IdQuery<'a, C, super::Id, 2> { + IdQuery { + client, + params: [price, name], + stmt: &mut 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>, + C, + > for NewNamedHiddenStmt + { + 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) + } + } + pub fn named() -> NamedStmt { + NamedStmt(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> { + NamedQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NamedBorrowed { + id: row.get(0), + name: row.get(1), + price: row.get(2), + show: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn named_by_id() -> NamedByIdStmt { + NamedByIdStmt(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> { + NamedQuery { + client, + params: [id], + stmt: &mut self.0, + extractor: |row| super::NamedBorrowed { + id: row.get(0), + name: row.get(1), + price: row.get(2), + show: row.get(3), + }, + mapper: |it| ::from(it), + } + } + } + pub fn new_named_complex() -> NewNamedComplexStmt { + NewNamedComplexStmt(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>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::NamedComplexParams<'a>, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for NewNamedComplexStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::NamedComplexParams<'a>, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.named, ¶ms.named_with_dot)) + } + } + pub fn named_complex() -> NamedComplexStmt { + NamedComplexStmt(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> { + NamedComplexQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NamedComplexBorrowed { + named: row.get(0), + named_with_dot: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + } + } + pub mod nullity { + #[derive(Debug)] + pub struct NullityParams< + 'a, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::ArraySql>, + T3: cornucopia_async::StringSql, + > { + pub texts: T2, + pub name: T3, + pub composite: Option>, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct Nullity { + pub texts: Vec>, + pub name: String, + pub composite: Option, + } + pub struct NullityBorrowed<'a> { + pub texts: cornucopia_async::ArrayIterator<'a, Option<&'a str>>, + pub name: &'a str, + pub composite: Option>, + } + impl<'a> From> for Nullity { + fn from( + NullityBorrowed { + texts, + name, + composite, + }: NullityBorrowed<'a>, + ) -> Self { + Self { + texts: texts.map(|v| v.map(|v| v.into())).collect(), + name: name.into(), + composite: composite.map(|v| v.into()), + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::NullityBorrowed, + mapper: fn(super::NullityBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NullityQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NullityBorrowed) -> R, + ) -> NullityQuery<'a, C, R, N> { + NullityQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> NewNullityStmt { + NewNullityStmt(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 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]) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::ArraySql>, + T3: cornucopia_sync::StringSql, + > + cornucopia_sync::Params< + 'a, + super::NullityParams<'a, T1, T2, T3>, + Result, + C, + > for NewNullityStmt + { + 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) + } + } + pub fn nullity() -> NullityStmt { + NullityStmt(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> { + NullityQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NullityBorrowed { + texts: row.get(0), + name: row.get(1), + composite: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::NullityBorrowed, + mapper: fn(super::NullityBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> NullityQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::NullityBorrowed) -> R, + ) -> NullityQuery<'a, C, R, N> { + NullityQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> NewNullityStmt { + NewNullityStmt(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 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 + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::ArraySql>, + T3: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + super::NullityParams<'a, T1, T2, T3>, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for NewNullityStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::NullityParams<'a, T1, T2, T3>, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite)) + } + } + pub fn nullity() -> NullityStmt { + NullityStmt(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> { + NullityQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::NullityBorrowed { + texts: row.get(0), + name: row.get(1), + composite: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + } + } + pub mod params { + #[derive(Debug)] + pub struct InsertBookParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > { + pub author: Option, + pub name: T2, + } + #[derive(Clone, Copy, Debug)] + pub struct ParamsOrderParams { + pub c: i32, + pub a: i32, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct SelectBook { + pub name: String, + pub author: Option, + } + pub struct SelectBookBorrowed<'a> { + pub name: &'a str, + pub author: Option<&'a str>, + } + impl<'a> From> for SelectBook { + fn from(SelectBookBorrowed { name, author }: SelectBookBorrowed<'a>) -> Self { + Self { + name: name.into(), + author: author.map(|v| v.into()), + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct FindBooks { + pub name: String, + pub author: Option, + } + pub struct FindBooksBorrowed<'a> { + pub name: &'a str, + pub author: Option<&'a str>, + } + impl<'a> From> for FindBooks { + fn from(FindBooksBorrowed { name, author }: FindBooksBorrowed<'a>) -> Self { + Self { + name: name.into(), + author: author.map(|v| v.into()), + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::SelectBookBorrowed, + mapper: fn(super::SelectBookBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectBookQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectBookBorrowed) -> R, + ) -> SelectBookQuery<'a, C, R, N> { + SelectBookQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::FindBooksBorrowed, + mapper: fn(super::FindBooksBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> FindBooksQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::FindBooksBorrowed) -> R, + ) -> FindBooksQuery<'a, C, R, N> { + FindBooksQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> InsertBookStmt { + InsertBookStmt(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, + >( + &'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]) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::StringSql, + > + cornucopia_sync::Params< + 'a, + super::InsertBookParams, + Result, + C, + > for InsertBookStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::InsertBookParams, + ) -> Result { + self.bind(client, ¶ms.author, ¶ms.name) + } + } + pub fn select_book() -> SelectBookStmt { + SelectBookStmt(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> { + SelectBookQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectBookBorrowed { + name: row.get(0), + author: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + pub fn find_books() -> FindBooksStmt { + FindBooksStmt(cornucopia_sync::private::Stmt::new( + "SELECT * FROM book WHERE name = ANY ($1)", + )) + } + pub struct FindBooksStmt(cornucopia_sync::private::Stmt); + impl FindBooksStmt { + 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, + params: [title], + stmt: &mut self.0, + extractor: |row| super::FindBooksBorrowed { + name: row.get(0), + author: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + 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 struct ParamsUseTwiceStmt(cornucopia_sync::private::Stmt); + impl ParamsUseTwiceStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a mut self, + client: &'a mut C, + name: &'a T1, + ) -> Result { + let stmt = self.0.prepare(client)?; + client.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 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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::ParamsOrderParams, + Result, + C, + > for ParamsOrderStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::ParamsOrderParams, + ) -> Result { + self.bind(client, ¶ms.c, ¶ms.a) + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::SelectBookBorrowed, + mapper: fn(super::SelectBookBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectBookQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::SelectBookBorrowed) -> R, + ) -> SelectBookQuery<'a, C, R, N> { + SelectBookQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::FindBooksBorrowed, + mapper: fn(super::FindBooksBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> FindBooksQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::FindBooksBorrowed) -> R, + ) -> FindBooksQuery<'a, C, R, N> { + FindBooksQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> InsertBookStmt { + InsertBookStmt(cornucopia_async::private::Stmt::new( + "INSERT INTO book (author, name) VALUES ($1, $2)", + )) + } + pub struct InsertBookStmt(cornucopia_async::private::Stmt); + impl InsertBookStmt { + 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 + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + super::InsertBookParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for InsertBookStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::InsertBookParams, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.author, ¶ms.name)) + } + } + pub fn select_book() -> SelectBookStmt { + SelectBookStmt(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> { + SelectBookQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::SelectBookBorrowed { + name: row.get(0), + author: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + pub fn find_books() -> FindBooksStmt { + FindBooksStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM book WHERE name = ANY ($1)", + )) + } + pub struct FindBooksStmt(cornucopia_async::private::Stmt); + impl FindBooksStmt { + 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, + params: [title], + stmt: &mut self.0, + extractor: |row| super::FindBooksBorrowed { + name: row.get(0), + author: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } + 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 struct ParamsUseTwiceStmt(cornucopia_async::private::Stmt); + impl ParamsUseTwiceStmt { + pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + name: &'a T1, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client.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 struct ParamsOrderStmt(cornucopia_async::private::Stmt); + impl ParamsOrderStmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::ParamsOrderParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for ParamsOrderStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::ParamsOrderParams, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.c, ¶ms.a)) + } + } + } + } + pub mod stress { + #[derive(Debug)] + pub struct EverythingParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::BytesSql, + T4: cornucopia_async::JsonSql, + T5: cornucopia_async::JsonSql, + > { + pub bool_: bool, + pub boolean_: bool, + pub char_: i8, + pub smallint_: i16, + pub int2_: i16, + pub smallserial_: i16, + pub serial2_: i16, + pub int_: i32, + pub int4_: i32, + pub serial_: i32, + pub serial4_: i32, + pub bingint_: i64, + pub int8_: i64, + pub bigserial_: i64, + pub serial8_: i64, + pub float4_: f32, + pub real_: f32, + pub float8_: f64, + pub double_precision_: f64, + pub text_: T1, + pub varchar_: T2, + pub bytea_: T3, + pub timestamp_: time::PrimitiveDateTime, + pub timestamp_without_time_zone_: time::PrimitiveDateTime, + pub timestamptz_: time::OffsetDateTime, + pub timestamp_with_time_zone_: time::OffsetDateTime, + pub date_: time::Date, + pub time_: time::Time, + pub json_: T4, + pub jsonb_: T5, + pub uuid_: uuid::Uuid, + pub inet_: std::net::IpAddr, + pub macaddr_: eui48::MacAddress, + pub numeric_: rust_decimal::Decimal, + } + #[derive(Debug)] + pub struct EverythingArrayParams< + T1: cornucopia_async::ArraySql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::ArraySql, + T4: cornucopia_async::ArraySql, + T5: cornucopia_async::ArraySql, + T6: cornucopia_async::ArraySql, + T7: cornucopia_async::ArraySql, + T8: cornucopia_async::ArraySql, + T9: cornucopia_async::ArraySql, + T10: cornucopia_async::ArraySql, + T11: cornucopia_async::ArraySql, + T12: cornucopia_async::ArraySql, + T13: cornucopia_async::ArraySql, + T14: cornucopia_async::StringSql, + T15: cornucopia_async::ArraySql, + T16: cornucopia_async::StringSql, + T17: cornucopia_async::ArraySql, + T18: cornucopia_async::BytesSql, + T19: cornucopia_async::ArraySql, + T20: cornucopia_async::ArraySql, + T21: cornucopia_async::ArraySql, + T22: cornucopia_async::ArraySql, + T23: cornucopia_async::ArraySql, + T24: cornucopia_async::ArraySql, + T25: cornucopia_async::ArraySql, + T26: cornucopia_async::JsonSql, + T27: cornucopia_async::ArraySql, + T28: cornucopia_async::JsonSql, + T29: cornucopia_async::ArraySql, + T30: cornucopia_async::ArraySql, + T31: cornucopia_async::ArraySql, + T32: cornucopia_async::ArraySql, + T33: cornucopia_async::ArraySql, + > { + pub bool_: T1, + pub boolean_: T2, + pub char_: T3, + pub smallint_: T4, + pub int2_: T5, + pub int_: T6, + pub int4_: T7, + pub bingint_: T8, + pub int8_: T9, + pub float4_: T10, + pub real_: T11, + pub float8_: T12, + pub double_precision_: T13, + pub text_: T15, + pub varchar_: T17, + pub bytea_: T19, + pub timestamp_: T20, + pub timestamp_without_time_zone_: T21, + pub timestamptz_: T22, + pub timestamp_with_time_zone_: T23, + pub date_: T24, + pub time_: T25, + pub json_: T27, + pub jsonb_: T29, + pub uuid_: T30, + pub inet_: T31, + pub macaddr_: T32, + pub numeric_: T33, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct Everything { + pub bool_: bool, + pub boolean_: bool, + pub char_: i8, + pub smallint_: i16, + pub int2_: i16, + pub smallserial_: i16, + pub serial2_: i16, + pub int_: i32, + pub int4_: i32, + pub serial_: i32, + pub serial4_: i32, + pub bingint_: i64, + pub int8_: i64, + pub bigserial_: i64, + pub serial8_: i64, + pub float4_: f32, + pub real_: f32, + pub float8_: f64, + pub double_precision_: f64, + pub text_: String, + pub varchar_: String, + pub bytea_: Vec, + pub timestamp_: time::PrimitiveDateTime, + pub timestamp_without_time_zone_: time::PrimitiveDateTime, + pub timestamptz_: time::OffsetDateTime, + pub timestamp_with_time_zone_: time::OffsetDateTime, + pub date_: time::Date, + pub time_: time::Time, + pub json_: serde_json::Value, + pub jsonb_: serde_json::Value, + pub uuid_: uuid::Uuid, + pub inet_: std::net::IpAddr, + pub macaddr_: eui48::MacAddress, + pub numeric_: rust_decimal::Decimal, + } + pub struct EverythingBorrowed<'a> { + pub bool_: bool, + pub boolean_: bool, + pub char_: i8, + pub smallint_: i16, + pub int2_: i16, + pub smallserial_: i16, + pub serial2_: i16, + pub int_: i32, + pub int4_: i32, + pub serial_: i32, + pub serial4_: i32, + pub bingint_: i64, + pub int8_: i64, + pub bigserial_: i64, + pub serial8_: i64, + pub float4_: f32, + pub real_: f32, + pub float8_: f64, + pub double_precision_: f64, + pub text_: &'a str, + pub varchar_: &'a str, + pub bytea_: &'a [u8], + pub timestamp_: time::PrimitiveDateTime, + pub timestamp_without_time_zone_: time::PrimitiveDateTime, + pub timestamptz_: time::OffsetDateTime, + pub timestamp_with_time_zone_: time::OffsetDateTime, + pub date_: time::Date, + pub time_: time::Time, + pub json_: postgres_types::Json<&'a serde_json::value::RawValue>, + pub jsonb_: postgres_types::Json<&'a serde_json::value::RawValue>, + pub uuid_: uuid::Uuid, + pub inet_: std::net::IpAddr, + pub macaddr_: eui48::MacAddress, + pub numeric_: rust_decimal::Decimal, + } + impl<'a> From> for Everything { + fn from( + EverythingBorrowed { + 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_, + }: EverythingBorrowed<'a>, + ) -> Self { + Self { + bool_, + boolean_, + char_, + smallint_, + int2_, + smallserial_, + serial2_, + int_, + int4_, + serial_, + serial4_, + bingint_, + int8_, + bigserial_, + serial8_, + float4_, + real_, + float8_, + double_precision_, + text_: text_.into(), + varchar_: varchar_.into(), + bytea_: bytea_.into(), + timestamp_, + timestamp_without_time_zone_, + timestamptz_, + timestamp_with_time_zone_, + date_, + time_, + json_: serde_json::from_str(json_.0.get()).unwrap(), + jsonb_: serde_json::from_str(jsonb_.0.get()).unwrap(), + uuid_, + inet_, + macaddr_, + numeric_, + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct EverythingNull { + pub bool_: Option, + pub boolean_: Option, + pub char_: Option, + pub smallint_: Option, + pub int2_: Option, + pub smallserial_: Option, + pub serial2_: Option, + pub int_: Option, + pub int4_: Option, + pub serial_: Option, + pub serial4_: Option, + pub bingint_: Option, + pub int8_: Option, + pub bigserial_: Option, + pub serial8_: Option, + pub float4_: Option, + pub real_: Option, + pub float8_: Option, + pub double_precision_: Option, + pub text_: Option, + pub varchar_: Option, + pub bytea_: Option>, + pub timestamp_: Option, + pub timestamp_without_time_zone_: Option, + pub timestamptz_: Option, + pub timestamp_with_time_zone_: Option, + pub date_: Option, + pub time_: Option, + pub json_: Option, + pub jsonb_: Option, + pub uuid_: Option, + pub inet_: Option, + pub macaddr_: Option, + pub numeric_: Option, + } + pub struct EverythingNullBorrowed<'a> { + pub bool_: Option, + pub boolean_: Option, + pub char_: Option, + pub smallint_: Option, + pub int2_: Option, + pub smallserial_: Option, + pub serial2_: Option, + pub int_: Option, + pub int4_: Option, + pub serial_: Option, + pub serial4_: Option, + pub bingint_: Option, + pub int8_: Option, + pub bigserial_: Option, + pub serial8_: Option, + pub float4_: Option, + pub real_: Option, + pub float8_: Option, + pub double_precision_: Option, + pub text_: Option<&'a str>, + pub varchar_: Option<&'a str>, + pub bytea_: Option<&'a [u8]>, + pub timestamp_: Option, + pub timestamp_without_time_zone_: Option, + pub timestamptz_: Option, + pub timestamp_with_time_zone_: Option, + pub date_: Option, + pub time_: Option, + pub json_: Option>, + pub jsonb_: Option>, + pub uuid_: Option, + pub inet_: Option, + pub macaddr_: Option, + pub numeric_: Option, + } + impl<'a> From> for EverythingNull { + fn from( + EverythingNullBorrowed { + 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_, + }: EverythingNullBorrowed<'a>, + ) -> Self { + Self { + bool_, + boolean_, + char_, + smallint_, + int2_, + smallserial_, + serial2_, + int_, + int4_, + serial_, + serial4_, + bingint_, + int8_, + bigserial_, + serial8_, + float4_, + real_, + float8_, + double_precision_, + text_: text_.map(|v| v.into()), + varchar_: varchar_.map(|v| v.into()), + bytea_: bytea_.map(|v| v.into()), + timestamp_, + timestamp_without_time_zone_, + timestamptz_, + timestamp_with_time_zone_, + date_, + time_, + json_: json_.map(|v| serde_json::from_str(v.0.get()).unwrap()), + jsonb_: jsonb_.map(|v| serde_json::from_str(v.0.get()).unwrap()), + uuid_, + inet_, + macaddr_, + numeric_, + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct EverythingArray { + pub bool_: Vec, + pub boolean_: Vec, + pub char_: Vec, + pub smallint_: Vec, + pub int2_: Vec, + pub int_: Vec, + pub int4_: Vec, + pub bingint_: Vec, + pub int8_: Vec, + pub float4_: Vec, + pub real_: Vec, + pub float8_: Vec, + pub double_precision_: Vec, + pub text_: Vec, + pub varchar_: Vec, + pub bytea_: Vec>, + pub timestamp_: Vec, + pub timestamp_without_time_zone_: Vec, + pub timestamptz_: Vec, + pub timestamp_with_time_zone_: Vec, + pub date_: Vec, + pub time_: Vec, + pub json_: Vec, + pub jsonb_: Vec, + pub uuid_: Vec, + pub inet_: Vec, + pub macaddr_: Vec, + pub numeric_: Vec, + } + pub struct EverythingArrayBorrowed<'a> { + pub bool_: cornucopia_async::ArrayIterator<'a, bool>, + pub boolean_: cornucopia_async::ArrayIterator<'a, bool>, + pub char_: cornucopia_async::ArrayIterator<'a, i8>, + pub smallint_: cornucopia_async::ArrayIterator<'a, i16>, + pub int2_: cornucopia_async::ArrayIterator<'a, i16>, + pub int_: cornucopia_async::ArrayIterator<'a, i32>, + pub int4_: cornucopia_async::ArrayIterator<'a, i32>, + pub bingint_: cornucopia_async::ArrayIterator<'a, i64>, + pub int8_: cornucopia_async::ArrayIterator<'a, i64>, + pub float4_: cornucopia_async::ArrayIterator<'a, f32>, + pub real_: cornucopia_async::ArrayIterator<'a, f32>, + pub float8_: cornucopia_async::ArrayIterator<'a, f64>, + pub double_precision_: cornucopia_async::ArrayIterator<'a, f64>, + pub text_: cornucopia_async::ArrayIterator<'a, &'a str>, + pub varchar_: cornucopia_async::ArrayIterator<'a, &'a str>, + pub bytea_: cornucopia_async::ArrayIterator<'a, &'a [u8]>, + pub timestamp_: cornucopia_async::ArrayIterator<'a, time::PrimitiveDateTime>, + pub timestamp_without_time_zone_: + cornucopia_async::ArrayIterator<'a, time::PrimitiveDateTime>, + pub timestamptz_: cornucopia_async::ArrayIterator<'a, time::OffsetDateTime>, + pub timestamp_with_time_zone_: + cornucopia_async::ArrayIterator<'a, time::OffsetDateTime>, + pub date_: cornucopia_async::ArrayIterator<'a, time::Date>, + pub time_: cornucopia_async::ArrayIterator<'a, time::Time>, + pub json_: cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + pub jsonb_: cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + pub uuid_: cornucopia_async::ArrayIterator<'a, uuid::Uuid>, + pub inet_: cornucopia_async::ArrayIterator<'a, std::net::IpAddr>, + pub macaddr_: cornucopia_async::ArrayIterator<'a, eui48::MacAddress>, + pub numeric_: cornucopia_async::ArrayIterator<'a, rust_decimal::Decimal>, + } + impl<'a> From> for EverythingArray { + fn from( + EverythingArrayBorrowed { + 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_, + }: EverythingArrayBorrowed<'a>, + ) -> Self { + Self { + bool_: bool_.map(|v| v).collect(), + boolean_: boolean_.map(|v| v).collect(), + char_: char_.map(|v| v).collect(), + smallint_: smallint_.map(|v| v).collect(), + int2_: int2_.map(|v| v).collect(), + int_: int_.map(|v| v).collect(), + int4_: int4_.map(|v| v).collect(), + bingint_: bingint_.map(|v| v).collect(), + int8_: int8_.map(|v| v).collect(), + float4_: float4_.map(|v| v).collect(), + real_: real_.map(|v| v).collect(), + float8_: float8_.map(|v| v).collect(), + double_precision_: double_precision_.map(|v| v).collect(), + text_: text_.map(|v| v.into()).collect(), + varchar_: varchar_.map(|v| v.into()).collect(), + bytea_: bytea_.map(|v| v.into()).collect(), + timestamp_: timestamp_.map(|v| v).collect(), + timestamp_without_time_zone_: timestamp_without_time_zone_.map(|v| v).collect(), + timestamptz_: timestamptz_.map(|v| v).collect(), + timestamp_with_time_zone_: timestamp_with_time_zone_.map(|v| v).collect(), + date_: date_.map(|v| v).collect(), + time_: time_.map(|v| v).collect(), + json_: json_ + .map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect(), + jsonb_: jsonb_ + .map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect(), + uuid_: uuid_.map(|v| v).collect(), + inet_: inet_.map(|v| v).collect(), + macaddr_: macaddr_.map(|v| v).collect(), + numeric_: numeric_.map(|v| v).collect(), + } + } + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct EverythingArrayNull { + pub bool_: Option>, + pub boolean_: Option>, + pub char_: Option>, + pub smallint_: Option>, + pub int2_: Option>, + pub int_: Option>, + pub int4_: Option>, + pub bingint_: Option>, + pub int8_: Option>, + pub float4_: Option>, + pub real_: Option>, + pub float8_: Option>, + pub double_precision_: Option>, + pub text_: Option>, + pub varchar_: Option>, + pub bytea_: Option>>, + pub timestamp_: Option>, + pub timestamp_without_time_zone_: Option>, + pub timestamptz_: Option>, + pub timestamp_with_time_zone_: Option>, + pub date_: Option>, + pub time_: Option>, + pub json_: Option>, + pub jsonb_: Option>, + pub uuid_: Option>, + pub inet_: Option>, + pub macaddr_: Option>, + pub numeric_: Option>, + } + pub struct EverythingArrayNullBorrowed<'a> { + pub bool_: Option>, + pub boolean_: Option>, + pub char_: Option>, + pub smallint_: Option>, + pub int2_: Option>, + pub int_: Option>, + pub int4_: Option>, + pub bingint_: Option>, + pub int8_: Option>, + pub float4_: Option>, + pub real_: Option>, + pub float8_: Option>, + pub double_precision_: Option>, + pub text_: Option>, + pub varchar_: Option>, + pub bytea_: Option>, + pub timestamp_: Option>, + pub timestamp_without_time_zone_: + Option>, + pub timestamptz_: Option>, + pub timestamp_with_time_zone_: + Option>, + pub date_: Option>, + pub time_: Option>, + pub json_: Option< + cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + >, + pub jsonb_: Option< + cornucopia_async::ArrayIterator< + 'a, + postgres_types::Json<&'a serde_json::value::RawValue>, + >, + >, + pub uuid_: Option>, + pub inet_: Option>, + pub macaddr_: Option>, + pub numeric_: Option>, + } + impl<'a> From> for EverythingArrayNull { + fn from( + EverythingArrayNullBorrowed { + 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_, + }: EverythingArrayNullBorrowed<'a>, + ) -> Self { + Self { + bool_: bool_.map(|v| v.map(|v| v).collect()), + boolean_: boolean_.map(|v| v.map(|v| v).collect()), + char_: char_.map(|v| v.map(|v| v).collect()), + smallint_: smallint_.map(|v| v.map(|v| v).collect()), + int2_: int2_.map(|v| v.map(|v| v).collect()), + int_: int_.map(|v| v.map(|v| v).collect()), + int4_: int4_.map(|v| v.map(|v| v).collect()), + bingint_: bingint_.map(|v| v.map(|v| v).collect()), + int8_: int8_.map(|v| v.map(|v| v).collect()), + float4_: float4_.map(|v| v.map(|v| v).collect()), + real_: real_.map(|v| v.map(|v| v).collect()), + float8_: float8_.map(|v| v.map(|v| v).collect()), + double_precision_: double_precision_.map(|v| v.map(|v| v).collect()), + text_: text_.map(|v| v.map(|v| v.into()).collect()), + varchar_: varchar_.map(|v| v.map(|v| v.into()).collect()), + bytea_: bytea_.map(|v| v.map(|v| v.into()).collect()), + timestamp_: timestamp_.map(|v| v.map(|v| v).collect()), + timestamp_without_time_zone_: timestamp_without_time_zone_ + .map(|v| v.map(|v| v).collect()), + timestamptz_: timestamptz_.map(|v| v.map(|v| v).collect()), + timestamp_with_time_zone_: timestamp_with_time_zone_ + .map(|v| v.map(|v| v).collect()), + date_: date_.map(|v| v.map(|v| v).collect()), + time_: time_.map(|v| v.map(|v| v).collect()), + json_: json_.map(|v| { + v.map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect() + }), + jsonb_: jsonb_.map(|v| { + v.map(|v| serde_json::from_str(v.0.get()).unwrap()) + .collect() + }), + uuid_: uuid_.map(|v| v.map(|v| v).collect()), + inet_: inet_.map(|v| v.map(|v| v).collect()), + macaddr_: macaddr_.map(|v| v.map(|v| v).collect()), + numeric_: numeric_.map(|v| v.map(|v| v).collect()), + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn(&postgres::Row) -> super::EverythingBorrowed, + mapper: fn(super::EverythingBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingBorrowed) -> R, + ) -> EverythingQuery<'a, C, R, N> { + EverythingQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::EverythingNullBorrowed, + mapper: fn(super::EverythingNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingNullBorrowed) -> R, + ) -> EverythingNullQuery<'a, C, R, N> { + EverythingNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::EverythingArrayBorrowed, + mapper: fn(super::EverythingArrayBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingArrayQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingArrayBorrowed) -> R, + ) -> EverythingArrayQuery<'a, C, R, N> { + EverythingArrayQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::EverythingArrayNullBorrowed, + mapper: fn(super::EverythingArrayNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingArrayNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingArrayNullBorrowed) -> R, + ) -> EverythingArrayNullQuery<'a, C, R, N> { + EverythingArrayNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn( + &postgres::Row, + ) + -> super::super::super::types::public::NightmareCompositeBorrowed, + mapper: fn(super::super::super::types::public::NightmareCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicNightmareCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::NightmareCompositeBorrowed) -> R, + ) -> PublicNightmareCompositeQuery<'a, C, R, N> { + PublicNightmareCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> SelectEverythingStmt { + SelectEverythingStmt(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> { + EverythingQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + smallserial_: row.get(5), + serial2_: row.get(6), + int_: row.get(7), + int4_: row.get(8), + serial_: row.get(9), + serial4_: row.get(10), + bingint_: row.get(11), + int8_: row.get(12), + bigserial_: row.get(13), + serial8_: row.get(14), + float4_: row.get(15), + real_: row.get(16), + float8_: row.get(17), + double_precision_: row.get(18), + text_: row.get(19), + varchar_: row.get(20), + bytea_: row.get(21), + timestamp_: row.get(22), + timestamp_without_time_zone_: row.get(23), + timestamptz_: row.get(24), + timestamp_with_time_zone_: row.get(25), + date_: row.get(26), + time_: row.get(27), + json_: row.get(28), + jsonb_: row.get(29), + uuid_: row.get(30), + inet_: row.get(31), + macaddr_: row.get(32), + numeric_: row.get(33), + }, + mapper: |it| ::from(it), + } + } + } + pub fn select_everything_null() -> SelectEverythingNullStmt { + SelectEverythingNullStmt(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> { + EverythingNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingNullBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + smallserial_: row.get(5), + serial2_: row.get(6), + int_: row.get(7), + int4_: row.get(8), + serial_: row.get(9), + serial4_: row.get(10), + bingint_: row.get(11), + int8_: row.get(12), + bigserial_: row.get(13), + serial8_: row.get(14), + float4_: row.get(15), + real_: row.get(16), + float8_: row.get(17), + double_precision_: row.get(18), + text_: row.get(19), + varchar_: row.get(20), + bytea_: row.get(21), + timestamp_: row.get(22), + timestamp_without_time_zone_: row.get(23), + timestamptz_: row.get(24), + timestamp_with_time_zone_: row.get(25), + date_: row.get(26), + time_: row.get(27), + json_: row.get(28), + jsonb_: row.get(29), + uuid_: row.get(30), + inet_: row.get(31), + macaddr_: row.get(32), + numeric_: row.get(33), + }, + mapper: |it| ::from(it), + } + } + } + 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_) + 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 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, + client: &'a mut C, + bool_: &'a bool, + boolean_: &'a bool, + char_: &'a i8, + smallint_: &'a i16, + int2_: &'a i16, + smallserial_: &'a i16, + serial2_: &'a i16, + int_: &'a i32, + int4_: &'a i32, + serial_: &'a i32, + serial4_: &'a i32, + bingint_: &'a i64, + int8_: &'a i64, + bigserial_: &'a i64, + serial8_: &'a i64, + float4_: &'a f32, + real_: &'a f32, + float8_: &'a f64, + double_precision_: &'a f64, + text_: &'a T1, + varchar_: &'a T2, + bytea_: &'a T3, + timestamp_: &'a time::PrimitiveDateTime, + timestamp_without_time_zone_: &'a time::PrimitiveDateTime, + timestamptz_: &'a time::OffsetDateTime, + timestamp_with_time_zone_: &'a time::OffsetDateTime, + date_: &'a time::Date, + time_: &'a time::Time, + json_: &'a T4, + jsonb_: &'a T5, + uuid_: &'a uuid::Uuid, + inet_: &'a std::net::IpAddr, + macaddr_: &'a eui48::MacAddress, + numeric_: &'a rust_decimal::Decimal, + ) -> Result { + let stmt = self.0.prepare(client)?; + client.execute( + stmt, + &[ + 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_, + ], + ) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::StringSql, + T2: cornucopia_sync::StringSql, + T3: cornucopia_sync::BytesSql, + T4: cornucopia_sync::JsonSql, + T5: cornucopia_sync::JsonSql, + > + cornucopia_sync::Params< + 'a, + super::EverythingParams, + Result, + C, + > for InsertEverythingStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::EverythingParams, + ) -> Result { + self.bind( + client, + ¶ms.bool_, + ¶ms.boolean_, + ¶ms.char_, + ¶ms.smallint_, + ¶ms.int2_, + ¶ms.smallserial_, + ¶ms.serial2_, + ¶ms.int_, + ¶ms.int4_, + ¶ms.serial_, + ¶ms.serial4_, + ¶ms.bingint_, + ¶ms.int8_, + ¶ms.bigserial_, + ¶ms.serial8_, + ¶ms.float4_, + ¶ms.real_, + ¶ms.float8_, + ¶ms.double_precision_, + ¶ms.text_, + ¶ms.varchar_, + ¶ms.bytea_, + ¶ms.timestamp_, + ¶ms.timestamp_without_time_zone_, + ¶ms.timestamptz_, + ¶ms.timestamp_with_time_zone_, + ¶ms.date_, + ¶ms.time_, + ¶ms.json_, + ¶ms.jsonb_, + ¶ms.uuid_, + ¶ms.inet_, + ¶ms.macaddr_, + ¶ms.numeric_, + ) + } + } + pub fn select_everything_array() -> SelectEverythingArrayStmt { + SelectEverythingArrayStmt(cornucopia_sync::private::Stmt::new( + "SELECT + * +FROM + EverythingArray", + )) + } + pub struct SelectEverythingArrayStmt(cornucopia_sync::private::Stmt); + impl SelectEverythingArrayStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { + EverythingArrayQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingArrayBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + int_: row.get(5), + int4_: row.get(6), + bingint_: row.get(7), + int8_: row.get(8), + float4_: row.get(9), + real_: row.get(10), + float8_: row.get(11), + double_precision_: row.get(12), + text_: row.get(13), + varchar_: row.get(14), + bytea_: row.get(15), + timestamp_: row.get(16), + timestamp_without_time_zone_: row.get(17), + timestamptz_: row.get(18), + timestamp_with_time_zone_: row.get(19), + date_: row.get(20), + time_: row.get(21), + json_: row.get(22), + jsonb_: row.get(23), + uuid_: row.get(24), + inet_: row.get(25), + macaddr_: row.get(26), + numeric_: row.get(27), + }, + mapper: |it| ::from(it), + } + } + } + pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { + SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt::new( + "SELECT + * +FROM + EverythingArray", + )) + } + pub struct SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt); + impl SelectEverythingArrayNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> + { + EverythingArrayNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingArrayNullBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + int_: row.get(5), + int4_: row.get(6), + bingint_: row.get(7), + int8_: row.get(8), + float4_: row.get(9), + real_: row.get(10), + float8_: row.get(11), + double_precision_: row.get(12), + text_: row.get(13), + varchar_: row.get(14), + bytea_: row.get(15), + timestamp_: row.get(16), + timestamp_without_time_zone_: row.get(17), + timestamptz_: row.get(18), + timestamp_with_time_zone_: row.get(19), + date_: row.get(20), + time_: row.get(21), + json_: row.get(22), + jsonb_: row.get(23), + uuid_: row.get(24), + inet_: row.get(25), + macaddr_: row.get(26), + numeric_: row.get(27), + }, + mapper: |it| ::from(it), + } + } + } + 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_) + 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 fn bind< + 'a, + C: GenericClient, + T1: cornucopia_sync::ArraySql, + T2: cornucopia_sync::ArraySql, + T3: cornucopia_sync::ArraySql, + T4: cornucopia_sync::ArraySql, + T5: cornucopia_sync::ArraySql, + T6: cornucopia_sync::ArraySql, + T7: cornucopia_sync::ArraySql, + T8: cornucopia_sync::ArraySql, + T9: cornucopia_sync::ArraySql, + T10: cornucopia_sync::ArraySql, + T11: cornucopia_sync::ArraySql, + T12: cornucopia_sync::ArraySql, + T13: cornucopia_sync::ArraySql, + T14: cornucopia_sync::StringSql, + T15: cornucopia_sync::ArraySql, + T16: cornucopia_sync::StringSql, + T17: cornucopia_sync::ArraySql, + T18: cornucopia_sync::BytesSql, + T19: cornucopia_sync::ArraySql, + T20: cornucopia_sync::ArraySql, + T21: cornucopia_sync::ArraySql, + T22: cornucopia_sync::ArraySql, + T23: cornucopia_sync::ArraySql, + T24: cornucopia_sync::ArraySql, + T25: cornucopia_sync::ArraySql, + T26: cornucopia_sync::JsonSql, + T27: cornucopia_sync::ArraySql, + T28: cornucopia_sync::JsonSql, + T29: cornucopia_sync::ArraySql, + T30: cornucopia_sync::ArraySql, + T31: cornucopia_sync::ArraySql, + T32: cornucopia_sync::ArraySql, + T33: cornucopia_sync::ArraySql, + >( + &'a mut self, + client: &'a mut C, + bool_: &'a T1, + boolean_: &'a T2, + char_: &'a T3, + smallint_: &'a T4, + int2_: &'a T5, + int_: &'a T6, + int4_: &'a T7, + bingint_: &'a T8, + int8_: &'a T9, + float4_: &'a T10, + real_: &'a T11, + float8_: &'a T12, + double_precision_: &'a T13, + text_: &'a T15, + varchar_: &'a T17, + bytea_: &'a T19, + timestamp_: &'a T20, + timestamp_without_time_zone_: &'a T21, + timestamptz_: &'a T22, + timestamp_with_time_zone_: &'a T23, + date_: &'a T24, + time_: &'a T25, + json_: &'a T27, + jsonb_: &'a T29, + uuid_: &'a T30, + inet_: &'a T31, + macaddr_: &'a T32, + numeric_: &'a T33, + ) -> Result { + let stmt = self.0.prepare(client)?; + client.execute( + stmt, + &[ + 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_, + ], + ) + } + } + impl< + 'a, + C: GenericClient, + T1: cornucopia_sync::ArraySql, + T2: cornucopia_sync::ArraySql, + T3: cornucopia_sync::ArraySql, + T4: cornucopia_sync::ArraySql, + T5: cornucopia_sync::ArraySql, + T6: cornucopia_sync::ArraySql, + T7: cornucopia_sync::ArraySql, + T8: cornucopia_sync::ArraySql, + T9: cornucopia_sync::ArraySql, + T10: cornucopia_sync::ArraySql, + T11: cornucopia_sync::ArraySql, + T12: cornucopia_sync::ArraySql, + T13: cornucopia_sync::ArraySql, + T14: cornucopia_sync::StringSql, + T15: cornucopia_sync::ArraySql, + T16: cornucopia_sync::StringSql, + T17: cornucopia_sync::ArraySql, + T18: cornucopia_sync::BytesSql, + T19: cornucopia_sync::ArraySql, + T20: cornucopia_sync::ArraySql, + T21: cornucopia_sync::ArraySql, + T22: cornucopia_sync::ArraySql, + T23: cornucopia_sync::ArraySql, + T24: cornucopia_sync::ArraySql, + T25: cornucopia_sync::ArraySql, + T26: cornucopia_sync::JsonSql, + T27: cornucopia_sync::ArraySql, + T28: cornucopia_sync::JsonSql, + T29: cornucopia_sync::ArraySql, + T30: cornucopia_sync::ArraySql, + T31: cornucopia_sync::ArraySql, + T32: cornucopia_sync::ArraySql, + T33: cornucopia_sync::ArraySql, + > + cornucopia_sync::Params< + 'a, + super::EverythingArrayParams< + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31, + T32, + T33, + >, + Result, + C, + > for InsertEverythingArrayStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::EverythingArrayParams< + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31, + T32, + T33, + >, + ) -> Result { + self.bind( + client, + ¶ms.bool_, + ¶ms.boolean_, + ¶ms.char_, + ¶ms.smallint_, + ¶ms.int2_, + ¶ms.int_, + ¶ms.int4_, + ¶ms.bingint_, + ¶ms.int8_, + ¶ms.float4_, + ¶ms.real_, + ¶ms.float8_, + ¶ms.double_precision_, + ¶ms.text_, + ¶ms.varchar_, + ¶ms.bytea_, + ¶ms.timestamp_, + ¶ms.timestamp_without_time_zone_, + ¶ms.timestamptz_, + ¶ms.timestamp_with_time_zone_, + ¶ms.date_, + ¶ms.time_, + ¶ms.json_, + ¶ms.jsonb_, + ¶ms.uuid_, + ¶ms.inet_, + ¶ms.macaddr_, + ¶ms.numeric_, + ) + } + } + pub fn select_nightmare() -> SelectNightmareStmt { + SelectNightmareStmt(cornucopia_sync::private::Stmt::new( + "SELECT + * +FROM + nightmare", + )) + } + pub struct SelectNightmareStmt(cornucopia_sync::private::Stmt); + impl SelectNightmareStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> PublicNightmareCompositeQuery< + 'a, + C, + super::super::super::types::public::NightmareComposite, + 0, + > { + PublicNightmareCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it.into(), + } + } + } + pub fn insert_nightmare() -> InsertNightmareStmt { + InsertNightmareStmt(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>( + &'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]) + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn(&tokio_postgres::Row) -> super::EverythingBorrowed, + mapper: fn(super::EverythingBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingBorrowed) -> R, + ) -> EverythingQuery<'a, C, R, N> { + EverythingQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::EverythingNullBorrowed, + mapper: fn(super::EverythingNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingNullBorrowed) -> R, + ) -> EverythingNullQuery<'a, C, R, N> { + EverythingNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayBorrowed, + mapper: fn(super::EverythingArrayBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingArrayQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingArrayBorrowed) -> R, + ) -> EverythingArrayQuery<'a, C, R, N> { + EverythingArrayQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::EverythingArrayNullBorrowed, + mapper: fn(super::EverythingArrayNullBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> EverythingArrayNullQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::EverythingArrayNullBorrowed) -> R, + ) -> EverythingArrayNullQuery<'a, C, R, N> { + EverythingArrayNullQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn( + &tokio_postgres::Row, + ) + -> super::super::super::types::public::NightmareCompositeBorrowed, + mapper: fn(super::super::super::types::public::NightmareCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicNightmareCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::NightmareCompositeBorrowed) -> R, + ) -> PublicNightmareCompositeQuery<'a, C, R, N> { + PublicNightmareCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> SelectEverythingStmt { + SelectEverythingStmt(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> { + EverythingQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + smallserial_: row.get(5), + serial2_: row.get(6), + int_: row.get(7), + int4_: row.get(8), + serial_: row.get(9), + serial4_: row.get(10), + bingint_: row.get(11), + int8_: row.get(12), + bigserial_: row.get(13), + serial8_: row.get(14), + float4_: row.get(15), + real_: row.get(16), + float8_: row.get(17), + double_precision_: row.get(18), + text_: row.get(19), + varchar_: row.get(20), + bytea_: row.get(21), + timestamp_: row.get(22), + timestamp_without_time_zone_: row.get(23), + timestamptz_: row.get(24), + timestamp_with_time_zone_: row.get(25), + date_: row.get(26), + time_: row.get(27), + json_: row.get(28), + jsonb_: row.get(29), + uuid_: row.get(30), + inet_: row.get(31), + macaddr_: row.get(32), + numeric_: row.get(33), + }, + mapper: |it| ::from(it), + } + } + } + pub fn select_everything_null() -> SelectEverythingNullStmt { + SelectEverythingNullStmt(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> { + EverythingNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingNullBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + smallserial_: row.get(5), + serial2_: row.get(6), + int_: row.get(7), + int4_: row.get(8), + serial_: row.get(9), + serial4_: row.get(10), + bingint_: row.get(11), + int8_: row.get(12), + bigserial_: row.get(13), + serial8_: row.get(14), + float4_: row.get(15), + real_: row.get(16), + float8_: row.get(17), + double_precision_: row.get(18), + text_: row.get(19), + varchar_: row.get(20), + bytea_: row.get(21), + timestamp_: row.get(22), + timestamp_without_time_zone_: row.get(23), + timestamptz_: row.get(24), + timestamp_with_time_zone_: row.get(25), + date_: row.get(26), + time_: row.get(27), + json_: row.get(28), + jsonb_: row.get(29), + uuid_: row.get(30), + inet_: row.get(31), + macaddr_: row.get(32), + numeric_: row.get(33), + }, + mapper: |it| ::from(it), + } + } + } + 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_) + 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 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, + client: &'a C, + bool_: &'a bool, + boolean_: &'a bool, + char_: &'a i8, + smallint_: &'a i16, + int2_: &'a i16, + smallserial_: &'a i16, + serial2_: &'a i16, + int_: &'a i32, + int4_: &'a i32, + serial_: &'a i32, + serial4_: &'a i32, + bingint_: &'a i64, + int8_: &'a i64, + bigserial_: &'a i64, + serial8_: &'a i64, + float4_: &'a f32, + real_: &'a f32, + float8_: &'a f64, + double_precision_: &'a f64, + text_: &'a T1, + varchar_: &'a T2, + bytea_: &'a T3, + timestamp_: &'a time::PrimitiveDateTime, + timestamp_without_time_zone_: &'a time::PrimitiveDateTime, + timestamptz_: &'a time::OffsetDateTime, + timestamp_with_time_zone_: &'a time::OffsetDateTime, + date_: &'a time::Date, + time_: &'a time::Time, + json_: &'a T4, + jsonb_: &'a T5, + uuid_: &'a uuid::Uuid, + inet_: &'a std::net::IpAddr, + macaddr_: &'a eui48::MacAddress, + numeric_: &'a rust_decimal::Decimal, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute( + stmt, + &[ + 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_, + ], + ) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::BytesSql, + T4: cornucopia_async::JsonSql, + T5: cornucopia_async::JsonSql, + > + cornucopia_async::Params< + 'a, + super::EverythingParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for InsertEverythingStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::EverythingParams, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind( + client, + ¶ms.bool_, + ¶ms.boolean_, + ¶ms.char_, + ¶ms.smallint_, + ¶ms.int2_, + ¶ms.smallserial_, + ¶ms.serial2_, + ¶ms.int_, + ¶ms.int4_, + ¶ms.serial_, + ¶ms.serial4_, + ¶ms.bingint_, + ¶ms.int8_, + ¶ms.bigserial_, + ¶ms.serial8_, + ¶ms.float4_, + ¶ms.real_, + ¶ms.float8_, + ¶ms.double_precision_, + ¶ms.text_, + ¶ms.varchar_, + ¶ms.bytea_, + ¶ms.timestamp_, + ¶ms.timestamp_without_time_zone_, + ¶ms.timestamptz_, + ¶ms.timestamp_with_time_zone_, + ¶ms.date_, + ¶ms.time_, + ¶ms.json_, + ¶ms.jsonb_, + ¶ms.uuid_, + ¶ms.inet_, + ¶ms.macaddr_, + ¶ms.numeric_, + )) + } + } + pub fn select_everything_array() -> SelectEverythingArrayStmt { + SelectEverythingArrayStmt(cornucopia_async::private::Stmt::new( + "SELECT + * +FROM + EverythingArray", + )) + } + pub struct SelectEverythingArrayStmt(cornucopia_async::private::Stmt); + impl SelectEverythingArrayStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> EverythingArrayQuery<'a, C, super::EverythingArray, 0> { + EverythingArrayQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingArrayBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + int_: row.get(5), + int4_: row.get(6), + bingint_: row.get(7), + int8_: row.get(8), + float4_: row.get(9), + real_: row.get(10), + float8_: row.get(11), + double_precision_: row.get(12), + text_: row.get(13), + varchar_: row.get(14), + bytea_: row.get(15), + timestamp_: row.get(16), + timestamp_without_time_zone_: row.get(17), + timestamptz_: row.get(18), + timestamp_with_time_zone_: row.get(19), + date_: row.get(20), + time_: row.get(21), + json_: row.get(22), + jsonb_: row.get(23), + uuid_: row.get(24), + inet_: row.get(25), + macaddr_: row.get(26), + numeric_: row.get(27), + }, + mapper: |it| ::from(it), + } + } + } + pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { + SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt::new( + "SELECT + * +FROM + EverythingArray", + )) + } + pub struct SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt); + impl SelectEverythingArrayNullStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> EverythingArrayNullQuery<'a, C, super::EverythingArrayNull, 0> + { + EverythingArrayNullQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::EverythingArrayNullBorrowed { + bool_: row.get(0), + boolean_: row.get(1), + char_: row.get(2), + smallint_: row.get(3), + int2_: row.get(4), + int_: row.get(5), + int4_: row.get(6), + bingint_: row.get(7), + int8_: row.get(8), + float4_: row.get(9), + real_: row.get(10), + float8_: row.get(11), + double_precision_: row.get(12), + text_: row.get(13), + varchar_: row.get(14), + bytea_: row.get(15), + timestamp_: row.get(16), + timestamp_without_time_zone_: row.get(17), + timestamptz_: row.get(18), + timestamp_with_time_zone_: row.get(19), + date_: row.get(20), + time_: row.get(21), + json_: row.get(22), + jsonb_: row.get(23), + uuid_: row.get(24), + inet_: row.get(25), + macaddr_: row.get(26), + numeric_: row.get(27), + }, + mapper: |it| ::from(it), + } + } + } + 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_) + 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 async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::ArraySql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::ArraySql, + T4: cornucopia_async::ArraySql, + T5: cornucopia_async::ArraySql, + T6: cornucopia_async::ArraySql, + T7: cornucopia_async::ArraySql, + T8: cornucopia_async::ArraySql, + T9: cornucopia_async::ArraySql, + T10: cornucopia_async::ArraySql, + T11: cornucopia_async::ArraySql, + T12: cornucopia_async::ArraySql, + T13: cornucopia_async::ArraySql, + T14: cornucopia_async::StringSql, + T15: cornucopia_async::ArraySql, + T16: cornucopia_async::StringSql, + T17: cornucopia_async::ArraySql, + T18: cornucopia_async::BytesSql, + T19: cornucopia_async::ArraySql, + T20: cornucopia_async::ArraySql, + T21: cornucopia_async::ArraySql, + T22: cornucopia_async::ArraySql, + T23: cornucopia_async::ArraySql, + T24: cornucopia_async::ArraySql, + T25: cornucopia_async::ArraySql, + T26: cornucopia_async::JsonSql, + T27: cornucopia_async::ArraySql, + T28: cornucopia_async::JsonSql, + T29: cornucopia_async::ArraySql, + T30: cornucopia_async::ArraySql, + T31: cornucopia_async::ArraySql, + T32: cornucopia_async::ArraySql, + T33: cornucopia_async::ArraySql, + >( + &'a mut self, + client: &'a C, + bool_: &'a T1, + boolean_: &'a T2, + char_: &'a T3, + smallint_: &'a T4, + int2_: &'a T5, + int_: &'a T6, + int4_: &'a T7, + bingint_: &'a T8, + int8_: &'a T9, + float4_: &'a T10, + real_: &'a T11, + float8_: &'a T12, + double_precision_: &'a T13, + text_: &'a T15, + varchar_: &'a T17, + bytea_: &'a T19, + timestamp_: &'a T20, + timestamp_without_time_zone_: &'a T21, + timestamptz_: &'a T22, + timestamp_with_time_zone_: &'a T23, + date_: &'a T24, + time_: &'a T25, + json_: &'a T27, + jsonb_: &'a T29, + uuid_: &'a T30, + inet_: &'a T31, + macaddr_: &'a T32, + numeric_: &'a T33, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute( + stmt, + &[ + 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_, + ], + ) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::ArraySql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::ArraySql, + T4: cornucopia_async::ArraySql, + T5: cornucopia_async::ArraySql, + T6: cornucopia_async::ArraySql, + T7: cornucopia_async::ArraySql, + T8: cornucopia_async::ArraySql, + T9: cornucopia_async::ArraySql, + T10: cornucopia_async::ArraySql, + T11: cornucopia_async::ArraySql, + T12: cornucopia_async::ArraySql, + T13: cornucopia_async::ArraySql, + T14: cornucopia_async::StringSql, + T15: cornucopia_async::ArraySql, + T16: cornucopia_async::StringSql, + T17: cornucopia_async::ArraySql, + T18: cornucopia_async::BytesSql, + T19: cornucopia_async::ArraySql, + T20: cornucopia_async::ArraySql, + T21: cornucopia_async::ArraySql, + T22: cornucopia_async::ArraySql, + T23: cornucopia_async::ArraySql, + T24: cornucopia_async::ArraySql, + T25: cornucopia_async::ArraySql, + T26: cornucopia_async::JsonSql, + T27: cornucopia_async::ArraySql, + T28: cornucopia_async::JsonSql, + T29: cornucopia_async::ArraySql, + T30: cornucopia_async::ArraySql, + T31: cornucopia_async::ArraySql, + T32: cornucopia_async::ArraySql, + T33: cornucopia_async::ArraySql, + > + cornucopia_async::Params< + 'a, + super::EverythingArrayParams< + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31, + T32, + T33, + >, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for InsertEverythingArrayStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::EverythingArrayParams< + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + T9, + T10, + T11, + T12, + T13, + T14, + T15, + T16, + T17, + T18, + T19, + T20, + T21, + T22, + T23, + T24, + T25, + T26, + T27, + T28, + T29, + T30, + T31, + T32, + T33, + >, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind( + client, + ¶ms.bool_, + ¶ms.boolean_, + ¶ms.char_, + ¶ms.smallint_, + ¶ms.int2_, + ¶ms.int_, + ¶ms.int4_, + ¶ms.bingint_, + ¶ms.int8_, + ¶ms.float4_, + ¶ms.real_, + ¶ms.float8_, + ¶ms.double_precision_, + ¶ms.text_, + ¶ms.varchar_, + ¶ms.bytea_, + ¶ms.timestamp_, + ¶ms.timestamp_without_time_zone_, + ¶ms.timestamptz_, + ¶ms.timestamp_with_time_zone_, + ¶ms.date_, + ¶ms.time_, + ¶ms.json_, + ¶ms.jsonb_, + ¶ms.uuid_, + ¶ms.inet_, + ¶ms.macaddr_, + ¶ms.numeric_, + )) + } + } + pub fn select_nightmare() -> SelectNightmareStmt { + SelectNightmareStmt(cornucopia_async::private::Stmt::new( + "SELECT + * +FROM + nightmare", + )) + } + pub struct SelectNightmareStmt(cornucopia_async::private::Stmt); + impl SelectNightmareStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> PublicNightmareCompositeQuery< + 'a, + C, + super::super::super::types::public::NightmareComposite, + 0, + > { + PublicNightmareCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it.into(), + } + } + } + pub fn insert_nightmare() -> InsertNightmareStmt { + InsertNightmareStmt(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>( + &'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 + } + } + } + } + pub mod syntax { + #[derive(Debug)] + pub struct ImplicitCompactParams { + pub name: Option, + pub price: Option, + } + #[derive(Debug)] + pub struct ImplicitSpacedParams { + pub name: Option, + pub price: Option, + } + #[derive(Debug)] + pub struct Params { + pub name: T1, + pub price: f64, + } + #[derive(Debug)] + pub struct ParamsSpace { + pub name: T1, + pub price: f64, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySqlParams { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql1Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql2Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql3Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql4Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql6Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql7Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql8Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql9Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(Clone, Copy, Debug)] + pub struct TrickySql10Params { + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + pub struct Row { + pub id: i32, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] + pub struct RowSpace { + pub id: i32, + } + #[derive(serde::Serialize, Debug, Clone, PartialEq)] + pub struct Typeof { + pub trick_y: String, + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + pub struct TypeofBorrowed<'a> { + pub trick_y: &'a str, + pub r#async: super::super::types::public::SyntaxComposite, + pub r#enum: super::super::types::public::SyntaxEnum, + } + impl<'a> From> for Typeof { + fn from( + TypeofBorrowed { + trick_y, + r#async, + r#enum, + }: TypeofBorrowed<'a>, + ) -> Self { + Self { + trick_y: trick_y.into(), + r#async, + r#enum, + } + } + } + pub mod sync { + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; + 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, + extractor: fn( + &postgres::Row, + ) + -> super::super::super::types::public::CloneCompositeBorrowed, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCloneCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> R, + ) -> PublicCloneCompositeQuery<'a, C, R, N> { + PublicCloneCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> Option, + mapper: fn(Option) -> T, + } + impl<'a, C, T: 'a, const N: usize> Optioni32Query<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(Option) -> R) -> Optioni32Query<'a, C, R, N> { + Optioni32Query { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::Row, + mapper: fn(super::Row) -> T, + } + impl<'a, C, T: 'a, const N: usize> RowQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(super::Row) -> R) -> RowQuery<'a, C, R, N> { + RowQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::RowSpace, + mapper: fn(super::RowSpace) -> T, + } + impl<'a, C, T: 'a, const N: usize> RowSpaceQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::RowSpace) -> R, + ) -> RowSpaceQuery<'a, C, R, N> { + RowSpaceQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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 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, + extractor: fn(&postgres::Row) -> super::TypeofBorrowed, + mapper: fn(super::TypeofBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> TypeofQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::TypeofBorrowed) -> R, + ) -> TypeofQuery<'a, C, R, N> { + TypeofQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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)?; + 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)?; + Ok(self + .client + .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 it = self + .client + .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() -> SelectCompactStmt { + SelectCompactStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) + } + pub struct SelectCompactStmt(cornucopia_sync::private::Stmt); + impl SelectCompactStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it.into(), + } + } + } + pub fn select_spaced() -> SelectSpacedStmt { + SelectSpacedStmt(cornucopia_sync::private::Stmt::new( + " SELECT * FROM clone ", + )) + } + pub struct SelectSpacedStmt(cornucopia_sync::private::Stmt); + impl SelectSpacedStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a mut C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + 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 struct ImplicitCompactStmt(cornucopia_sync::private::Stmt); + impl ImplicitCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( + &'a mut self, + client: &'a mut C, + name: &'a Option, + price: &'a Option, + ) -> Optioni32Query<'a, C, Option, 2> { + Optioni32Query { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> + cornucopia_sync::Params< + 'a, + super::ImplicitCompactParams, + Optioni32Query<'a, C, Option, 2>, + C, + > for ImplicitCompactStmt + { + 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) + } + } + pub fn implicit_spaced() -> ImplicitSpacedStmt { + ImplicitSpacedStmt(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>( + &'a mut self, + client: &'a mut C, + name: &'a Option, + price: &'a Option, + ) -> Optioni32Query<'a, C, Option, 2> { + Optioni32Query { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> + cornucopia_sync::Params< + 'a, + super::ImplicitSpacedParams, + Optioni32Query<'a, C, Option, 2>, + C, + > for ImplicitSpacedStmt + { + 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) + } + } + pub fn named_compact() -> NamedCompactStmt { + NamedCompactStmt(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>( + &'a mut self, + client: &'a mut C, + name: &'a T1, + price: &'a f64, + ) -> RowQuery<'a, C, super::Row, 2> { + RowQuery { + client, + params: [name, price], + stmt: &mut 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>, C> + for NamedCompactStmt + { + 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) + } + } + pub fn named_spaced() -> NamedSpacedStmt { + NamedSpacedStmt(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>( + &'a mut self, + client: &'a mut C, + name: &'a T1, + price: &'a f64, + ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { + RowSpaceQuery { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| super::RowSpace { id: row.get(0) }, + mapper: |it| ::from(it), + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> + cornucopia_sync::Params< + 'a, + super::ParamsSpace, + RowSpaceQuery<'a, C, super::RowSpace, 2>, + C, + > for NamedSpacedStmt + { + 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) + } + } + 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 struct TrickySqlStmt(cornucopia_sync::private::Stmt); + impl TrickySqlStmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params<'a, super::TrickySqlParams, Result, C> + for TrickySqlStmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySqlParams, + ) -> Result { + self.bind(client, ¶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 struct TrickySql1Stmt(cornucopia_sync::private::Stmt); + impl TrickySql1Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql1Params, + Result, + C, + > for TrickySql1Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql1Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql2Stmt(cornucopia_sync::private::Stmt); + impl TrickySql2Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql2Params, + Result, + C, + > for TrickySql2Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql2Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql3Stmt(cornucopia_sync::private::Stmt); + impl TrickySql3Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql3Params, + Result, + C, + > for TrickySql3Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql3Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql4Stmt(cornucopia_sync::private::Stmt); + impl TrickySql4Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql4Params, + Result, + C, + > for TrickySql4Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql4Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql6Stmt(cornucopia_sync::private::Stmt); + impl TrickySql6Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql6Params, + Result, + C, + > for TrickySql6Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql6Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql7Stmt(cornucopia_sync::private::Stmt); + impl TrickySql7Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql7Params, + Result, + C, + > for TrickySql7Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql7Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql8Stmt(cornucopia_sync::private::Stmt); + impl TrickySql8Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql8Params, + Result, + C, + > for TrickySql8Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql8Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql9Stmt(cornucopia_sync::private::Stmt); + impl TrickySql9Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql9Params, + Result, + C, + > for TrickySql9Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql9Params, + ) -> Result { + self.bind(client, ¶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 struct TrickySql10Stmt(cornucopia_sync::private::Stmt); + impl TrickySql10Stmt { + pub fn bind<'a, C: GenericClient>( + &'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]) + } + } + impl<'a, C: GenericClient> + cornucopia_sync::Params< + 'a, + super::TrickySql10Params, + Result, + C, + > for TrickySql10Stmt + { + fn params( + &'a mut self, + client: &'a mut C, + params: &'a super::TrickySql10Params, + ) -> Result { + self.bind(client, ¶ms.r#async, ¶ms.r#enum) + } + } + pub fn r#typeof() -> RTypeofStmt { + RTypeofStmt(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> { + TypeofQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::TypeofBorrowed { + trick_y: row.get(0), + r#async: row.get(1), + r#enum: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + } + pub mod async_ { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + 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, + extractor: fn( + &tokio_postgres::Row, + ) + -> super::super::super::types::public::CloneCompositeBorrowed, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> PublicCloneCompositeQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::super::super::types::public::CloneCompositeBorrowed) -> R, + ) -> PublicCloneCompositeQuery<'a, C, R, N> { + PublicCloneCompositeQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> Option, + mapper: fn(Option) -> T, + } + impl<'a, C, T: 'a, const N: usize> Optioni32Query<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(Option) -> R) -> Optioni32Query<'a, C, R, N> { + Optioni32Query { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::Row, + mapper: fn(super::Row) -> T, + } + impl<'a, C, T: 'a, const N: usize> RowQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map(self, mapper: fn(super::Row) -> R) -> RowQuery<'a, C, R, N> { + RowQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::RowSpace, + mapper: fn(super::RowSpace) -> T, + } + impl<'a, C, T: 'a, const N: usize> RowSpaceQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::RowSpace) -> R, + ) -> RowSpaceQuery<'a, C, R, N> { + RowSpaceQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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 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, + extractor: fn(&tokio_postgres::Row) -> super::TypeofBorrowed, + mapper: fn(super::TypeofBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> TypeofQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(super::TypeofBorrowed) -> R, + ) -> TypeofQuery<'a, C, R, N> { + TypeofQuery { + client: self.client, + params: self.params, + stmt: self.stmt, + 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?; + 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?; + Ok(self + .client + .query_opt(stmt, &self.params) + .await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + pub async fn iter( + self, + ) -> Result< + impl futures::Stream> + 'a, + tokio_postgres::Error, + > { + let stmt = self.stmt.prepare(self.client).await?; + let it = self + .client + .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() -> SelectCompactStmt { + SelectCompactStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) + } + pub struct SelectCompactStmt(cornucopia_async::private::Stmt); + impl SelectCompactStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it.into(), + } + } + } + pub fn select_spaced() -> SelectSpacedStmt { + SelectSpacedStmt(cornucopia_async::private::Stmt::new( + " SELECT * FROM clone ", + )) + } + pub struct SelectSpacedStmt(cornucopia_async::private::Stmt); + impl SelectSpacedStmt { + pub fn bind<'a, C: GenericClient>( + &'a mut self, + client: &'a C, + ) -> PublicCloneCompositeQuery< + 'a, + C, + super::super::super::types::public::CloneComposite, + 0, + > { + PublicCloneCompositeQuery { + client, + params: [], + stmt: &mut self.0, + 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 struct ImplicitCompactStmt(cornucopia_async::private::Stmt); + impl ImplicitCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + name: &'a Option, + price: &'a Option, + ) -> Optioni32Query<'a, C, Option, 2> { + Optioni32Query { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + super::ImplicitCompactParams, + Optioni32Query<'a, C, Option, 2>, + C, + > for ImplicitCompactStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::ImplicitCompactParams, + ) -> Optioni32Query<'a, C, Option, 2> { + self.bind(client, ¶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 struct ImplicitSpacedStmt(cornucopia_async::private::Stmt); + impl ImplicitSpacedStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + name: &'a Option, + price: &'a Option, + ) -> Optioni32Query<'a, C, Option, 2> { + Optioni32Query { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + super::ImplicitSpacedParams, + Optioni32Query<'a, C, Option, 2>, + C, + > for ImplicitSpacedStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::ImplicitSpacedParams, + ) -> Optioni32Query<'a, C, Option, 2> { + self.bind(client, ¶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 struct NamedCompactStmt(cornucopia_async::private::Stmt); + impl NamedCompactStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + name: &'a T1, + price: &'a f64, + ) -> RowQuery<'a, C, super::Row, 2> { + RowQuery { + client, + params: [name, price], + stmt: &mut 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>, C> + for NamedCompactStmt + { + 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) + } + } + pub fn named_spaced() -> NamedSpacedStmt { + NamedSpacedStmt(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>( + &'a mut self, + client: &'a C, + name: &'a T1, + price: &'a f64, + ) -> RowSpaceQuery<'a, C, super::RowSpace, 2> { + RowSpaceQuery { + client, + params: [name, price], + stmt: &mut self.0, + extractor: |row| super::RowSpace { id: row.get(0) }, + mapper: |it| ::from(it), + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + super::ParamsSpace, + RowSpaceQuery<'a, C, super::RowSpace, 2>, + C, + > for NamedSpacedStmt + { + 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) + } + } + 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 struct TrickySqlStmt(cornucopia_async::private::Stmt); + impl TrickySqlStmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySqlParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySqlStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySqlParams, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql1Stmt(cornucopia_async::private::Stmt); + impl TrickySql1Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql1Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql1Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql1Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql2Stmt(cornucopia_async::private::Stmt); + impl TrickySql2Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql2Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql2Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql2Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql3Stmt(cornucopia_async::private::Stmt); + impl TrickySql3Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql3Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql3Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql3Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql4Stmt(cornucopia_async::private::Stmt); + impl TrickySql4Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql4Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql4Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql4Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql6Stmt(cornucopia_async::private::Stmt); + impl TrickySql6Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql6Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql6Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql6Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql7Stmt(cornucopia_async::private::Stmt); + impl TrickySql7Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql7Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql7Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql7Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql8Stmt(cornucopia_async::private::Stmt); + impl TrickySql8Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql8Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql8Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql8Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql9Stmt(cornucopia_async::private::Stmt); + impl TrickySql9Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql9Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql9Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql9Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶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 struct TrickySql10Stmt(cornucopia_async::private::Stmt); + impl TrickySql10Stmt { + pub async fn bind<'a, C: GenericClient>( + &'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 + } + } + impl<'a, C: GenericClient + Send + Sync> + cornucopia_async::Params< + 'a, + super::TrickySql10Params, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for TrickySql10Stmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a super::TrickySql10Params, + ) -> std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + > { + Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) + } + } + pub fn r#typeof() -> RTypeofStmt { + RTypeofStmt(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> { + TypeofQuery { + client, + params: [], + stmt: &mut self.0, + extractor: |row| super::TypeofBorrowed { + trick_y: row.get(0), + r#async: row.get(1), + r#enum: row.get(2), + }, + mapper: |it| ::from(it), + } + } + } + } + } +} diff --git a/codegen_test/src/cornucopia_async.rs b/codegen_test/src/cornucopia_async.rs deleted file mode 100644 index 7506e40f..00000000 --- a/codegen_test/src/cornucopia_async.rs +++ /dev/null @@ -1,5345 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types { - pub mod public { - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "clone_composite")] - pub struct CloneComposite { - #[postgres(name = "first")] - pub first: i32, - #[postgres(name = "second")] - pub second: String, - } - #[derive(Debug)] - pub struct CloneCompositeBorrowed<'a> { - pub first: i32, - pub second: &'a str, - } - impl<'a> From> for CloneComposite { - fn from(CloneCompositeBorrowed { first, second }: CloneCompositeBorrowed<'a>) -> Self { - Self { - first, - second: second.into(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for CloneCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let first = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let second = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(CloneCompositeBorrowed { first, second }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "clone_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for CloneCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CloneCompositeBorrowed { first, second } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), - "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "clone_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "first" => ::accepts(f.type_()), - "second" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "copy_composite")] - pub struct CopyComposite { - #[postgres(name = "first")] - pub first: i32, - #[postgres(name = "second")] - pub second: f64, - } - impl<'a> postgres_types::ToSql for CopyComposite { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CopyComposite { first, second } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), - "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "copy_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "first" => ::accepts(f.type_()), - "second" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "domain_composite")] - pub struct DomainComposite { - #[postgres(name = "txt")] - pub txt: String, - #[postgres(name = "json")] - pub json: serde_json::Value, - #[postgres(name = "nb")] - pub nb: i32, - #[postgres(name = "arr")] - pub arr: Vec, - } - #[derive(Debug)] - pub struct DomainCompositeBorrowed<'a> { - pub txt: &'a str, - pub json: postgres_types::Json<&'a serde_json::value::RawValue>, - pub nb: i32, - pub arr: cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - } - impl<'a> From> for DomainComposite { - fn from( - DomainCompositeBorrowed { txt, json, nb, arr }: DomainCompositeBorrowed<'a>, - ) -> Self { - Self { - txt: txt.into(), - json: serde_json::from_str(json.0.get()).unwrap(), - nb, - arr: arr - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for DomainCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let txt = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let json = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let nb = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let arr = postgres_types::private::read_value(fields[3].type_(), &mut out)?; - Ok(DomainCompositeBorrowed { txt, json, nb, arr }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "domain_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct DomainCompositeParams<'a> { - pub txt: &'a str, - pub json: &'a serde_json::value::Value, - pub nb: i32, - pub arr: &'a [&'a serde_json::value::Value], - } - impl<'a> postgres_types::ToSql for DomainCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let DomainCompositeParams { txt, json, nb, arr } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "txt" => postgres_types::ToSql::to_sql( - &cornucopia_async::private::Domain(txt), - field.type_(), - out, - ), - "json" => postgres_types::ToSql::to_sql( - &cornucopia_async::private::Domain(json), - field.type_(), - out, - ), - "nb" => postgres_types::ToSql::to_sql( - &cornucopia_async::private::Domain(nb), - field.type_(), - out, - ), - "arr" => postgres_types::ToSql::to_sql( - &cornucopia_async::private::Domain( - &cornucopia_async::private::DomainArray(arr), - ), - field.type_(), - out, - ), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "domain_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 4 { - return false; - } - fields.iter().all(| f | match f.name() - { - "txt" => < cornucopia_async::private::Domain::<&'a str> as postgres_types :: - ToSql > :: accepts(f.type_()),"json" => < cornucopia_async::private::Domain::<&'a serde_json::value::Value> as postgres_types :: - ToSql > :: accepts(f.type_()),"nb" => < cornucopia_async::private::Domain:: as postgres_types :: - ToSql > :: accepts(f.type_()),"arr" => < cornucopia_async::private::Domain::> as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "named_composite")] - pub struct NamedComposite { - #[postgres(name = "wow")] - pub wow: Option, - #[postgres(name = "such_cool")] - pub such_cool: Option, - } - #[derive(Debug)] - pub struct NamedCompositeBorrowed<'a> { - pub wow: Option<&'a str>, - pub such_cool: Option, - } - impl<'a> From> for NamedComposite { - fn from(NamedCompositeBorrowed { wow, such_cool }: NamedCompositeBorrowed<'a>) -> Self { - Self { - wow: wow.map(|v| v.into()), - such_cool, - } - } - } - impl<'a> postgres_types::FromSql<'a> for NamedCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(NamedCompositeBorrowed { wow, such_cool }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "named_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for NamedCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NamedCompositeBorrowed { wow, such_cool } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), - "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "named_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "wow" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), - "such_cool" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum EnumWithDot { - variant_with_dot, - } - impl<'a> postgres_types::ToSql for EnumWithDot { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - EnumWithDot::variant_with_dot => "variant.with_dot", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "enum.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 1 { - return false; - } - variants.iter().all(|v| match &**v { - "variant.with_dot" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for EnumWithDot { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "variant.with_dot" => Ok(EnumWithDot::variant_with_dot), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "enum.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 1 { - return false; - } - variants.iter().all(|v| match &**v { - "variant.with_dot" => true, - _ => false, - }) - } - _ => false, - } - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "named_composite.with_dot")] - pub struct NamedCompositeWithDot { - #[postgres(name = "this.is.inconceivable")] - pub this_is_inconceivable: Option, - } - impl<'a> postgres_types::ToSql for NamedCompositeWithDot { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NamedCompositeWithDot { - this_is_inconceivable, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "this.is.inconceivable" => { - postgres_types::ToSql::to_sql(this_is_inconceivable, field.type_(), out) - } - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "named_composite.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 1 { - return false; - } - fields.iter().all(| f | match f.name() - { - "this.is.inconceivable" => < super::super::types::public::EnumWithDot as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "nullity_composite")] - pub struct NullityComposite { - #[postgres(name = "jsons")] - pub jsons: Option>>, - #[postgres(name = "id")] - pub id: i32, - } - #[derive(Debug)] - pub struct NullityCompositeBorrowed<'a> { - pub jsons: Option< - cornucopia_async::ArrayIterator< - 'a, - Option>, - >, - >, - pub id: i32, - } - impl<'a> From> for NullityComposite { - fn from(NullityCompositeBorrowed { jsons, id }: NullityCompositeBorrowed<'a>) -> Self { - Self { - jsons: jsons.map(|v| { - v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) - .collect() - }), - id, - } - } - } - impl<'a> postgres_types::FromSql<'a> for NullityCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let jsons = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let id = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(NullityCompositeBorrowed { jsons, id }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "nullity_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct NullityCompositeParams<'a> { - pub jsons: Option<&'a [Option<&'a serde_json::value::Value>]>, - pub id: i32, - } - impl<'a> postgres_types::ToSql for NullityCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NullityCompositeParams { jsons, id } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "jsons" => postgres_types::ToSql::to_sql(jsons, field.type_(), out), - "id" => postgres_types::ToSql::to_sql(id, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "nullity_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| { - match f.name() - { - "jsons" => < &'a [&'a serde_json::value::Value] as postgres_types :: - ToSql > :: accepts(f.type_()),"id" => < i32 as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - } - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum SpongebobCharacter { - Bob, - Patrick, - Squidward, - } - impl<'a> postgres_types::ToSql for SpongebobCharacter { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - SpongebobCharacter::Bob => "Bob", - SpongebobCharacter::Patrick => "Patrick", - SpongebobCharacter::Squidward => "Squidward", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "spongebob_character" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "Bob" => true, - "Patrick" => true, - "Squidward" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for SpongebobCharacter { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "Bob" => Ok(SpongebobCharacter::Bob), - "Patrick" => Ok(SpongebobCharacter::Patrick), - "Squidward" => Ok(SpongebobCharacter::Squidward), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "spongebob_character" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "Bob" => true, - "Patrick" => true, - "Squidward" => true, - _ => false, - }) - } - _ => false, - } - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "custom_composite")] - pub struct CustomComposite { - #[postgres(name = "wow")] - pub wow: String, - #[postgres(name = "such_cool")] - pub such_cool: i32, - #[postgres(name = "nice")] - pub nice: super::super::types::public::SpongebobCharacter, - } - #[derive(Debug)] - pub struct CustomCompositeBorrowed<'a> { - pub wow: &'a str, - pub such_cool: i32, - pub nice: super::super::types::public::SpongebobCharacter, - } - impl<'a> From> for CustomComposite { - fn from( - CustomCompositeBorrowed { - wow, - such_cool, - nice, - }: CustomCompositeBorrowed<'a>, - ) -> Self { - Self { - wow: wow.into(), - such_cool, - nice, - } - } - } - impl<'a> postgres_types::FromSql<'a> for CustomCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let nice = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - Ok(CustomCompositeBorrowed { - wow, - such_cool, - nice, - }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "custom_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for CustomCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CustomCompositeBorrowed { - wow, - such_cool, - nice, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), - "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), - "nice" => postgres_types::ToSql::to_sql(nice, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "custom_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 3 { - return false; - } - fields.iter().all(| f | match f.name() - { - "wow" => < &'a str as postgres_types :: - ToSql > :: accepts(f.type_()),"such_cool" => < i32 as postgres_types :: - ToSql > :: accepts(f.type_()),"nice" => < super::super::types::public::SpongebobCharacter as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "nightmare_composite")] - pub struct NightmareComposite { - #[postgres(name = "custom")] - pub custom: Vec, - #[postgres(name = "spongebob")] - pub spongebob: Vec, - #[postgres(name = "domain")] - pub domain: String, - } - #[derive(Debug)] - pub struct NightmareCompositeBorrowed<'a> { - pub custom: cornucopia_async::ArrayIterator< - 'a, - super::super::types::public::CustomCompositeBorrowed<'a>, - >, - pub spongebob: cornucopia_async::ArrayIterator< - 'a, - super::super::types::public::SpongebobCharacter, - >, - pub domain: &'a str, - } - impl<'a> From> for NightmareComposite { - fn from( - NightmareCompositeBorrowed { - custom, - spongebob, - domain, - }: NightmareCompositeBorrowed<'a>, - ) -> Self { - Self { - custom: custom.map(|v| v.into()).collect(), - spongebob: spongebob.map(|v| v).collect(), - domain: domain.into(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for NightmareCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let custom = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let spongebob = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let domain = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - Ok(NightmareCompositeBorrowed { - custom, - spongebob, - domain, - }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "nightmare_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct NightmareCompositeParams<'a> { - pub custom: &'a [super::super::types::public::CustomCompositeBorrowed<'a>], - pub spongebob: &'a [super::super::types::public::SpongebobCharacter], - pub domain: &'a str, - } - impl<'a> postgres_types::ToSql for NightmareCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NightmareCompositeParams { - custom, - spongebob, - domain, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "custom" => postgres_types::ToSql::to_sql(custom, field.type_(), out), - "spongebob" => postgres_types::ToSql::to_sql(spongebob, field.type_(), out), - "domain" => postgres_types::ToSql::to_sql( - &cornucopia_async::private::Domain(domain), - field.type_(), - out, - ), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "nightmare_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 3 { - return false; - } - fields.iter().all(| f | match f.name() - { - "custom" => < &'a [super::super::types::public::CustomCompositeBorrowed<'a>] as postgres_types :: - ToSql > :: accepts(f.type_()),"spongebob" => < &'a [super::super::types::public::SpongebobCharacter] as postgres_types :: - ToSql > :: accepts(f.type_()),"domain" => < cornucopia_async::private::Domain::<&'a str> as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "syntax_composite")] - pub struct SyntaxComposite { - #[postgres(name = "async")] - pub r#async: i32, - } - impl<'a> postgres_types::ToSql for SyntaxComposite { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let SyntaxComposite { r#async } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "async" => postgres_types::ToSql::to_sql(r#async, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 1 { - return false; - } - fields.iter().all(|f| match f.name() { - "async" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum SyntaxEnum { - r#async, - r#box, - I_Love_Chocolate, - } - impl<'a> postgres_types::ToSql for SyntaxEnum { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - SyntaxEnum::r#async => "async", - SyntaxEnum::r#box => "box", - SyntaxEnum::I_Love_Chocolate => "I Love Chocolate", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_enum" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "async" => true, - "box" => true, - "I Love Chocolate" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for SyntaxEnum { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "async" => Ok(SyntaxEnum::r#async), - "box" => Ok(SyntaxEnum::r#box), - "I Love Chocolate" => Ok(SyntaxEnum::I_Love_Chocolate), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_enum" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "async" => true, - "box" => true, - "I Love Chocolate" => true, - _ => false, - }) - } - _ => false, - } - } - } - } -} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod copy { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - pub struct SuperSuperTypesPublicCloneCompositeQuery<'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, - extractor: - fn(&tokio_postgres::Row) -> super::super::types::public::CloneCompositeBorrowed, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCloneCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicCloneCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCloneCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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 struct SuperSuperTypesPublicCopyCompositeQuery<'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, - extractor: fn(&tokio_postgres::Row) -> super::super::types::public::CopyComposite, - mapper: fn(super::super::types::public::CopyComposite) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCopyCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CopyComposite) -> R, - ) -> SuperSuperTypesPublicCopyCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCopyCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> InsertCloneStmt { - InsertCloneStmt(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>( - &'a mut self, - client: &'a C, - composite: &'a super::super::types::public::CloneCompositeBorrowed<'a>, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await - } - } - pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) - } - pub struct SelectCloneStmt(cornucopia_async::private::Stmt); - impl SelectCloneStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - 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 struct InsertCopyStmt(cornucopia_async::private::Stmt); - impl InsertCopyStmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - composite: &'a super::super::types::public::CopyComposite, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await - } - } - pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt(cornucopia_async::private::Stmt::new("SELECT * FROM copy")) - } - pub struct SelectCopyStmt(cornucopia_async::private::Stmt); - impl SelectCopyStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SuperSuperTypesPublicCopyCompositeQuery< - 'a, - C, - super::super::types::public::CopyComposite, - 0, - > { - SuperSuperTypesPublicCopyCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - } - pub mod domain { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct InsertNightmareDomainParams< - 'a, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::JsonSql, - T3: cornucopia_async::JsonSql, - T4: cornucopia_async::ArraySql, - > { - pub txt: T1, - pub json: T2, - pub nb: i32, - pub arr: T4, - pub composite: Option>, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectNightmareDomain { - pub txt: String, - pub json: serde_json::Value, - pub nb: i32, - pub arr: Vec, - } - pub struct SelectNightmareDomainBorrowed<'a> { - pub txt: &'a str, - pub json: postgres_types::Json<&'a serde_json::value::RawValue>, - pub nb: i32, - pub arr: cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - } - impl<'a> From> for SelectNightmareDomain { - fn from( - SelectNightmareDomainBorrowed { txt, json, nb, arr }: SelectNightmareDomainBorrowed< - 'a, - >, - ) -> Self { - Self { - txt: txt.into(), - json: serde_json::from_str(json.0.get()).unwrap(), - nb, - arr: arr - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> SelectNightmareDomainBorrowed, - mapper: fn(SelectNightmareDomainBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectNightmareDomainBorrowed) -> R, - ) -> SelectNightmareDomainQuery<'a, C, R, N> { - SelectNightmareDomainQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectNightmareDomainNull { - pub txt: Option, - pub json: Option, - pub nb: Option, - pub arr: Option>>, - pub composite: Option, - } - pub struct SelectNightmareDomainNullBorrowed<'a> { - pub txt: Option<&'a str>, - pub json: Option>, - pub nb: Option, - pub arr: Option< - cornucopia_async::ArrayIterator< - 'a, - Option>, - >, - >, - pub composite: Option>, - } - impl<'a> From> for SelectNightmareDomainNull { - fn from( - SelectNightmareDomainNullBorrowed { - txt, - json, - nb, - arr, - composite, - }: SelectNightmareDomainNullBorrowed<'a>, - ) -> Self { - Self { - txt: txt.map(|v| v.into()), - json: json.map(|v| serde_json::from_str(v.0.get()).unwrap()), - nb, - arr: arr.map(|v| { - v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) - .collect() - }), - composite: composite.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> SelectNightmareDomainNullBorrowed, - mapper: fn(SelectNightmareDomainNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectNightmareDomainNullBorrowed) -> R, - ) -> SelectNightmareDomainNullQuery<'a, C, R, N> { - SelectNightmareDomainNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt(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>( - &'a mut self, - client: &'a C, - ) -> SelectNightmareDomainQuery<'a, C, SelectNightmareDomain, 0> { - SelectNightmareDomainQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectNightmareDomainBorrowed { - txt: row.get(0), - json: row.get(1), - nb: row.get(2), - arr: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - 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 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, - arr: &'a T4, - composite: &'a Option>, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client - .execute( - stmt, - &[ - &cornucopia_async::private::Domain(txt), - &cornucopia_async::private::Domain(json), - &cornucopia_async::private::Domain(nb), - &cornucopia_async::private::Domain( - &cornucopia_async::private::DomainArray(arr), - ), - composite, - ], - ) - .await - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::JsonSql, - T3: cornucopia_async::JsonSql, - T4: cornucopia_async::ArraySql, - > - cornucopia_async::Params< - 'a, - InsertNightmareDomainParams<'a, T1, T2, T3, T4>, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for InsertNightmareDomainStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a InsertNightmareDomainParams<'a, T1, T2, T3, T4>, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind( - client, - ¶ms.txt, - ¶ms.json, - ¶ms.nb, - ¶ms.arr, - ¶ms.composite, - )) - } - } - pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM nightmare_domain", - )) - } - pub struct SelectNightmareDomainNullStmt(cornucopia_async::private::Stmt); - impl SelectNightmareDomainNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SelectNightmareDomainNullQuery<'a, C, SelectNightmareDomainNull, 0> { - SelectNightmareDomainNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectNightmareDomainNullBorrowed { - txt: row.get(0), - json: row.get(1), - nb: row.get(2), - arr: row.get(3), - composite: row.get(4), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod named { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct NamedParams { - pub name: T1, - pub price: Option, - } - #[derive(Debug)] - pub struct NamedComplexParams<'a> { - pub named: super::super::types::public::NamedCompositeBorrowed<'a>, - pub named_with_dot: Option, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct Id { - pub id: i32, - } - 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, - extractor: fn(&tokio_postgres::Row) -> Id, - mapper: fn(Id) -> T, - } - impl<'a, C, T: 'a, const N: usize> IdQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Id) -> R) -> IdQuery<'a, C, R, N> { - IdQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Named { - pub id: i32, - pub name: String, - pub price: Option, - pub show: bool, - } - pub struct NamedBorrowed<'a> { - pub id: i32, - pub name: &'a str, - pub price: Option, - pub show: bool, - } - impl<'a> From> for Named { - fn from( - NamedBorrowed { - id, - name, - price, - show, - }: NamedBorrowed<'a>, - ) -> Self { - Self { - id, - name: name.into(), - price, - show, - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> NamedBorrowed, - mapper: fn(NamedBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NamedQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(NamedBorrowed) -> R) -> NamedQuery<'a, C, R, N> { - NamedQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct NamedComplex { - pub named: super::super::types::public::NamedComposite, - pub named_with_dot: Option, - } - pub struct NamedComplexBorrowed<'a> { - pub named: super::super::types::public::NamedCompositeBorrowed<'a>, - pub named_with_dot: Option, - } - impl<'a> From> for NamedComplex { - fn from( - NamedComplexBorrowed { - named, - named_with_dot, - }: NamedComplexBorrowed<'a>, - ) -> Self { - Self { - named: named.into(), - named_with_dot, - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> NamedComplexBorrowed, - mapper: fn(NamedComplexBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NamedComplexQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(NamedComplexBorrowed) -> R, - ) -> NamedComplexQuery<'a, C, R, N> { - NamedComplexQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> NewNamedVisibleStmt { - NewNamedVisibleStmt(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>( - &'a mut self, - client: &'a C, - name: &'a T1, - price: &'a Option, - ) -> IdQuery<'a, C, Id, 2> { - IdQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| Id { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, NamedParams, IdQuery<'a, C, Id, 2>, C> - for NewNamedVisibleStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a NamedParams, - ) -> IdQuery<'a, C, Id, 2> { - self.bind(client, ¶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 struct NewNamedHiddenStmt(cornucopia_async::private::Stmt); - impl NewNamedHiddenStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - price: &'a Option, - name: &'a T1, - ) -> IdQuery<'a, C, Id, 2> { - IdQuery { - client, - params: [price, name], - stmt: &mut self.0, - extractor: |row| Id { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, NamedParams, IdQuery<'a, C, Id, 2>, C> - for NewNamedHiddenStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a NamedParams, - ) -> IdQuery<'a, C, Id, 2> { - self.bind(client, ¶ms.price, ¶ms.name) - } - } - pub fn named() -> NamedStmt { - NamedStmt(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, Named, 0> { - NamedQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NamedBorrowed { - id: row.get(0), - name: row.get(1), - price: row.get(2), - show: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt(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, Named, 1> { - NamedQuery { - client, - params: [id], - stmt: &mut self.0, - extractor: |row| NamedBorrowed { - id: row.get(0), - name: row.get(1), - price: row.get(2), - show: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn new_named_complex() -> NewNamedComplexStmt { - NewNamedComplexStmt(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>( - &'a mut self, - client: &'a C, - named: &'a super::super::types::public::NamedCompositeBorrowed<'a>, - named_with_dot: &'a Option, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[named, named_with_dot]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - NamedComplexParams<'a>, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for NewNamedComplexStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a NamedComplexParams<'a>, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.named, ¶ms.named_with_dot)) - } - } - pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt(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, NamedComplex, 0> { - NamedComplexQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NamedComplexBorrowed { - named: row.get(0), - named_with_dot: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod nullity { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct NullityParams< - 'a, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::ArraySql>, - T3: cornucopia_async::StringSql, - > { - pub texts: T2, - pub name: T3, - pub composite: Option>, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Nullity { - pub texts: Vec>, - pub name: String, - pub composite: Option, - } - pub struct NullityBorrowed<'a> { - pub texts: cornucopia_async::ArrayIterator<'a, Option<&'a str>>, - pub name: &'a str, - pub composite: Option>, - } - impl<'a> From> for Nullity { - fn from( - NullityBorrowed { - texts, - name, - composite, - }: NullityBorrowed<'a>, - ) -> Self { - Self { - texts: texts.map(|v| v.map(|v| v.into())).collect(), - name: name.into(), - composite: composite.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> NullityBorrowed, - mapper: fn(NullityBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NullityQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(NullityBorrowed) -> R) -> NullityQuery<'a, C, R, N> { - NullityQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> NewNullityStmt { - NewNullityStmt(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 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>, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[texts, name, composite]).await - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::ArraySql>, - T3: cornucopia_async::StringSql, - > - cornucopia_async::Params< - 'a, - NullityParams<'a, T1, T2, T3>, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for NewNullityStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a NullityParams<'a, T1, T2, T3>, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite)) - } - } - pub fn nullity() -> NullityStmt { - NullityStmt(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, Nullity, 0> { - NullityQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NullityBorrowed { - texts: row.get(0), - name: row.get(1), - composite: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod params { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct InsertBookParams< - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - > { - pub author: Option, - pub name: T2, - } - #[derive(Clone, Copy, Debug)] - pub struct ParamsOrderParams { - pub c: i32, - pub a: i32, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectBook { - pub name: String, - pub author: Option, - } - pub struct SelectBookBorrowed<'a> { - pub name: &'a str, - pub author: Option<&'a str>, - } - impl<'a> From> for SelectBook { - fn from(SelectBookBorrowed { name, author }: SelectBookBorrowed<'a>) -> Self { - Self { - name: name.into(), - author: author.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> SelectBookBorrowed, - mapper: fn(SelectBookBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectBookQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectBookBorrowed) -> R, - ) -> SelectBookQuery<'a, C, R, N> { - SelectBookQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct FindBooks { - pub name: String, - pub author: Option, - } - pub struct FindBooksBorrowed<'a> { - pub name: &'a str, - pub author: Option<&'a str>, - } - impl<'a> From> for FindBooks { - fn from(FindBooksBorrowed { name, author }: FindBooksBorrowed<'a>) -> Self { - Self { - name: name.into(), - author: author.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> FindBooksBorrowed, - mapper: fn(FindBooksBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> FindBooksQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(FindBooksBorrowed) -> R) -> FindBooksQuery<'a, C, R, N> { - FindBooksQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> InsertBookStmt { - InsertBookStmt(cornucopia_async::private::Stmt::new( - "INSERT INTO book (author, name) VALUES ($1, $2)", - )) - } - pub struct InsertBookStmt(cornucopia_async::private::Stmt); - impl InsertBookStmt { - 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 - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - > - cornucopia_async::Params< - 'a, - InsertBookParams, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for InsertBookStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a InsertBookParams, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.author, ¶ms.name)) - } - } - pub fn select_book() -> SelectBookStmt { - SelectBookStmt(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, SelectBook, 0> { - SelectBookQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectBookBorrowed { - name: row.get(0), - author: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - pub fn find_books() -> FindBooksStmt { - FindBooksStmt(cornucopia_async::private::Stmt::new( - "SELECT * FROM book WHERE name = ANY ($1)", - )) - } - pub struct FindBooksStmt(cornucopia_async::private::Stmt); - impl FindBooksStmt { - 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, FindBooks, 1> { - FindBooksQuery { - client, - params: [title], - stmt: &mut self.0, - extractor: |row| FindBooksBorrowed { - name: row.get(0), - author: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - 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 struct ParamsUseTwiceStmt(cornucopia_async::private::Stmt); - impl ParamsUseTwiceStmt { - pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - name: &'a T1, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.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 struct ParamsOrderStmt(cornucopia_async::private::Stmt); - impl ParamsOrderStmt { - pub async fn bind<'a, C: GenericClient>( - &'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 - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - ParamsOrderParams, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for ParamsOrderStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a ParamsOrderParams, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.c, ¶ms.a)) - } - } - } - pub mod stress { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct EverythingParams< - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - T3: cornucopia_async::BytesSql, - T4: cornucopia_async::JsonSql, - T5: cornucopia_async::JsonSql, - > { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: T1, - pub varchar_: T2, - pub bytea_: T3, - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: T4, - pub jsonb_: T5, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - #[derive(Debug)] - pub struct EverythingArrayParams< - T1: cornucopia_async::ArraySql, - T2: cornucopia_async::ArraySql, - T3: cornucopia_async::ArraySql, - T4: cornucopia_async::ArraySql, - T5: cornucopia_async::ArraySql, - T6: cornucopia_async::ArraySql, - T7: cornucopia_async::ArraySql, - T8: cornucopia_async::ArraySql, - T9: cornucopia_async::ArraySql, - T10: cornucopia_async::ArraySql, - T11: cornucopia_async::ArraySql, - T12: cornucopia_async::ArraySql, - T13: cornucopia_async::ArraySql, - T14: cornucopia_async::StringSql, - T15: cornucopia_async::ArraySql, - T16: cornucopia_async::StringSql, - T17: cornucopia_async::ArraySql, - T18: cornucopia_async::BytesSql, - T19: cornucopia_async::ArraySql, - T20: cornucopia_async::ArraySql, - T21: cornucopia_async::ArraySql, - T22: cornucopia_async::ArraySql, - T23: cornucopia_async::ArraySql, - T24: cornucopia_async::ArraySql, - T25: cornucopia_async::ArraySql, - T26: cornucopia_async::JsonSql, - T27: cornucopia_async::ArraySql, - T28: cornucopia_async::JsonSql, - T29: cornucopia_async::ArraySql, - T30: cornucopia_async::ArraySql, - T31: cornucopia_async::ArraySql, - T32: cornucopia_async::ArraySql, - T33: cornucopia_async::ArraySql, - > { - pub bool_: T1, - pub boolean_: T2, - pub char_: T3, - pub smallint_: T4, - pub int2_: T5, - pub int_: T6, - pub int4_: T7, - pub bingint_: T8, - pub int8_: T9, - pub float4_: T10, - pub real_: T11, - pub float8_: T12, - pub double_precision_: T13, - pub text_: T15, - pub varchar_: T17, - pub bytea_: T19, - pub timestamp_: T20, - pub timestamp_without_time_zone_: T21, - pub timestamptz_: T22, - pub timestamp_with_time_zone_: T23, - pub date_: T24, - pub time_: T25, - pub json_: T27, - pub jsonb_: T29, - pub uuid_: T30, - pub inet_: T31, - pub macaddr_: T32, - pub numeric_: T33, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Everything { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: String, - pub varchar_: String, - pub bytea_: Vec, - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: serde_json::Value, - pub jsonb_: serde_json::Value, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - pub struct EverythingBorrowed<'a> { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: &'a str, - pub varchar_: &'a str, - pub bytea_: &'a [u8], - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: postgres_types::Json<&'a serde_json::value::RawValue>, - pub jsonb_: postgres_types::Json<&'a serde_json::value::RawValue>, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - impl<'a> From> for Everything { - fn from( - EverythingBorrowed { - 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_, - }: EverythingBorrowed<'a>, - ) -> Self { - Self { - bool_, - boolean_, - char_, - smallint_, - int2_, - smallserial_, - serial2_, - int_, - int4_, - serial_, - serial4_, - bingint_, - int8_, - bigserial_, - serial8_, - float4_, - real_, - float8_, - double_precision_, - text_: text_.into(), - varchar_: varchar_.into(), - bytea_: bytea_.into(), - timestamp_, - timestamp_without_time_zone_, - timestamptz_, - timestamp_with_time_zone_, - date_, - time_, - json_: serde_json::from_str(json_.0.get()).unwrap(), - jsonb_: serde_json::from_str(jsonb_.0.get()).unwrap(), - uuid_, - inet_, - macaddr_, - numeric_, - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> EverythingBorrowed, - mapper: fn(EverythingBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingBorrowed) -> R, - ) -> EverythingQuery<'a, C, R, N> { - EverythingQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingNull { - pub bool_: Option, - pub boolean_: Option, - pub char_: Option, - pub smallint_: Option, - pub int2_: Option, - pub smallserial_: Option, - pub serial2_: Option, - pub int_: Option, - pub int4_: Option, - pub serial_: Option, - pub serial4_: Option, - pub bingint_: Option, - pub int8_: Option, - pub bigserial_: Option, - pub serial8_: Option, - pub float4_: Option, - pub real_: Option, - pub float8_: Option, - pub double_precision_: Option, - pub text_: Option, - pub varchar_: Option, - pub bytea_: Option>, - pub timestamp_: Option, - pub timestamp_without_time_zone_: Option, - pub timestamptz_: Option, - pub timestamp_with_time_zone_: Option, - pub date_: Option, - pub time_: Option, - pub json_: Option, - pub jsonb_: Option, - pub uuid_: Option, - pub inet_: Option, - pub macaddr_: Option, - pub numeric_: Option, - } - pub struct EverythingNullBorrowed<'a> { - pub bool_: Option, - pub boolean_: Option, - pub char_: Option, - pub smallint_: Option, - pub int2_: Option, - pub smallserial_: Option, - pub serial2_: Option, - pub int_: Option, - pub int4_: Option, - pub serial_: Option, - pub serial4_: Option, - pub bingint_: Option, - pub int8_: Option, - pub bigserial_: Option, - pub serial8_: Option, - pub float4_: Option, - pub real_: Option, - pub float8_: Option, - pub double_precision_: Option, - pub text_: Option<&'a str>, - pub varchar_: Option<&'a str>, - pub bytea_: Option<&'a [u8]>, - pub timestamp_: Option, - pub timestamp_without_time_zone_: Option, - pub timestamptz_: Option, - pub timestamp_with_time_zone_: Option, - pub date_: Option, - pub time_: Option, - pub json_: Option>, - pub jsonb_: Option>, - pub uuid_: Option, - pub inet_: Option, - pub macaddr_: Option, - pub numeric_: Option, - } - impl<'a> From> for EverythingNull { - fn from( - EverythingNullBorrowed { - 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_, - }: EverythingNullBorrowed<'a>, - ) -> Self { - Self { - bool_, - boolean_, - char_, - smallint_, - int2_, - smallserial_, - serial2_, - int_, - int4_, - serial_, - serial4_, - bingint_, - int8_, - bigserial_, - serial8_, - float4_, - real_, - float8_, - double_precision_, - text_: text_.map(|v| v.into()), - varchar_: varchar_.map(|v| v.into()), - bytea_: bytea_.map(|v| v.into()), - timestamp_, - timestamp_without_time_zone_, - timestamptz_, - timestamp_with_time_zone_, - date_, - time_, - json_: json_.map(|v| serde_json::from_str(v.0.get()).unwrap()), - jsonb_: jsonb_.map(|v| serde_json::from_str(v.0.get()).unwrap()), - uuid_, - inet_, - macaddr_, - numeric_, - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> EverythingNullBorrowed, - mapper: fn(EverythingNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingNullBorrowed) -> R, - ) -> EverythingNullQuery<'a, C, R, N> { - EverythingNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingArray { - pub bool_: Vec, - pub boolean_: Vec, - pub char_: Vec, - pub smallint_: Vec, - pub int2_: Vec, - pub int_: Vec, - pub int4_: Vec, - pub bingint_: Vec, - pub int8_: Vec, - pub float4_: Vec, - pub real_: Vec, - pub float8_: Vec, - pub double_precision_: Vec, - pub text_: Vec, - pub varchar_: Vec, - pub bytea_: Vec>, - pub timestamp_: Vec, - pub timestamp_without_time_zone_: Vec, - pub timestamptz_: Vec, - pub timestamp_with_time_zone_: Vec, - pub date_: Vec, - pub time_: Vec, - pub json_: Vec, - pub jsonb_: Vec, - pub uuid_: Vec, - pub inet_: Vec, - pub macaddr_: Vec, - pub numeric_: Vec, - } - pub struct EverythingArrayBorrowed<'a> { - pub bool_: cornucopia_async::ArrayIterator<'a, bool>, - pub boolean_: cornucopia_async::ArrayIterator<'a, bool>, - pub char_: cornucopia_async::ArrayIterator<'a, i8>, - pub smallint_: cornucopia_async::ArrayIterator<'a, i16>, - pub int2_: cornucopia_async::ArrayIterator<'a, i16>, - pub int_: cornucopia_async::ArrayIterator<'a, i32>, - pub int4_: cornucopia_async::ArrayIterator<'a, i32>, - pub bingint_: cornucopia_async::ArrayIterator<'a, i64>, - pub int8_: cornucopia_async::ArrayIterator<'a, i64>, - pub float4_: cornucopia_async::ArrayIterator<'a, f32>, - pub real_: cornucopia_async::ArrayIterator<'a, f32>, - pub float8_: cornucopia_async::ArrayIterator<'a, f64>, - pub double_precision_: cornucopia_async::ArrayIterator<'a, f64>, - pub text_: cornucopia_async::ArrayIterator<'a, &'a str>, - pub varchar_: cornucopia_async::ArrayIterator<'a, &'a str>, - pub bytea_: cornucopia_async::ArrayIterator<'a, &'a [u8]>, - pub timestamp_: cornucopia_async::ArrayIterator<'a, time::PrimitiveDateTime>, - pub timestamp_without_time_zone_: - cornucopia_async::ArrayIterator<'a, time::PrimitiveDateTime>, - pub timestamptz_: cornucopia_async::ArrayIterator<'a, time::OffsetDateTime>, - pub timestamp_with_time_zone_: - cornucopia_async::ArrayIterator<'a, time::OffsetDateTime>, - pub date_: cornucopia_async::ArrayIterator<'a, time::Date>, - pub time_: cornucopia_async::ArrayIterator<'a, time::Time>, - pub json_: cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - pub jsonb_: cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - pub uuid_: cornucopia_async::ArrayIterator<'a, uuid::Uuid>, - pub inet_: cornucopia_async::ArrayIterator<'a, std::net::IpAddr>, - pub macaddr_: cornucopia_async::ArrayIterator<'a, eui48::MacAddress>, - pub numeric_: cornucopia_async::ArrayIterator<'a, rust_decimal::Decimal>, - } - impl<'a> From> for EverythingArray { - fn from( - EverythingArrayBorrowed { - 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_, - }: EverythingArrayBorrowed<'a>, - ) -> Self { - Self { - bool_: bool_.map(|v| v).collect(), - boolean_: boolean_.map(|v| v).collect(), - char_: char_.map(|v| v).collect(), - smallint_: smallint_.map(|v| v).collect(), - int2_: int2_.map(|v| v).collect(), - int_: int_.map(|v| v).collect(), - int4_: int4_.map(|v| v).collect(), - bingint_: bingint_.map(|v| v).collect(), - int8_: int8_.map(|v| v).collect(), - float4_: float4_.map(|v| v).collect(), - real_: real_.map(|v| v).collect(), - float8_: float8_.map(|v| v).collect(), - double_precision_: double_precision_.map(|v| v).collect(), - text_: text_.map(|v| v.into()).collect(), - varchar_: varchar_.map(|v| v.into()).collect(), - bytea_: bytea_.map(|v| v.into()).collect(), - timestamp_: timestamp_.map(|v| v).collect(), - timestamp_without_time_zone_: timestamp_without_time_zone_.map(|v| v).collect(), - timestamptz_: timestamptz_.map(|v| v).collect(), - timestamp_with_time_zone_: timestamp_with_time_zone_.map(|v| v).collect(), - date_: date_.map(|v| v).collect(), - time_: time_.map(|v| v).collect(), - json_: json_ - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - jsonb_: jsonb_ - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - uuid_: uuid_.map(|v| v).collect(), - inet_: inet_.map(|v| v).collect(), - macaddr_: macaddr_.map(|v| v).collect(), - numeric_: numeric_.map(|v| v).collect(), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> EverythingArrayBorrowed, - mapper: fn(EverythingArrayBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingArrayQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingArrayBorrowed) -> R, - ) -> EverythingArrayQuery<'a, C, R, N> { - EverythingArrayQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingArrayNull { - pub bool_: Option>, - pub boolean_: Option>, - pub char_: Option>, - pub smallint_: Option>, - pub int2_: Option>, - pub int_: Option>, - pub int4_: Option>, - pub bingint_: Option>, - pub int8_: Option>, - pub float4_: Option>, - pub real_: Option>, - pub float8_: Option>, - pub double_precision_: Option>, - pub text_: Option>, - pub varchar_: Option>, - pub bytea_: Option>>, - pub timestamp_: Option>, - pub timestamp_without_time_zone_: Option>, - pub timestamptz_: Option>, - pub timestamp_with_time_zone_: Option>, - pub date_: Option>, - pub time_: Option>, - pub json_: Option>, - pub jsonb_: Option>, - pub uuid_: Option>, - pub inet_: Option>, - pub macaddr_: Option>, - pub numeric_: Option>, - } - pub struct EverythingArrayNullBorrowed<'a> { - pub bool_: Option>, - pub boolean_: Option>, - pub char_: Option>, - pub smallint_: Option>, - pub int2_: Option>, - pub int_: Option>, - pub int4_: Option>, - pub bingint_: Option>, - pub int8_: Option>, - pub float4_: Option>, - pub real_: Option>, - pub float8_: Option>, - pub double_precision_: Option>, - pub text_: Option>, - pub varchar_: Option>, - pub bytea_: Option>, - pub timestamp_: Option>, - pub timestamp_without_time_zone_: - Option>, - pub timestamptz_: Option>, - pub timestamp_with_time_zone_: - Option>, - pub date_: Option>, - pub time_: Option>, - pub json_: Option< - cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - >, - pub jsonb_: Option< - cornucopia_async::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - >, - pub uuid_: Option>, - pub inet_: Option>, - pub macaddr_: Option>, - pub numeric_: Option>, - } - impl<'a> From> for EverythingArrayNull { - fn from( - EverythingArrayNullBorrowed { - 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_, - }: EverythingArrayNullBorrowed<'a>, - ) -> Self { - Self { - bool_: bool_.map(|v| v.map(|v| v).collect()), - boolean_: boolean_.map(|v| v.map(|v| v).collect()), - char_: char_.map(|v| v.map(|v| v).collect()), - smallint_: smallint_.map(|v| v.map(|v| v).collect()), - int2_: int2_.map(|v| v.map(|v| v).collect()), - int_: int_.map(|v| v.map(|v| v).collect()), - int4_: int4_.map(|v| v.map(|v| v).collect()), - bingint_: bingint_.map(|v| v.map(|v| v).collect()), - int8_: int8_.map(|v| v.map(|v| v).collect()), - float4_: float4_.map(|v| v.map(|v| v).collect()), - real_: real_.map(|v| v.map(|v| v).collect()), - float8_: float8_.map(|v| v.map(|v| v).collect()), - double_precision_: double_precision_.map(|v| v.map(|v| v).collect()), - text_: text_.map(|v| v.map(|v| v.into()).collect()), - varchar_: varchar_.map(|v| v.map(|v| v.into()).collect()), - bytea_: bytea_.map(|v| v.map(|v| v.into()).collect()), - timestamp_: timestamp_.map(|v| v.map(|v| v).collect()), - timestamp_without_time_zone_: timestamp_without_time_zone_ - .map(|v| v.map(|v| v).collect()), - timestamptz_: timestamptz_.map(|v| v.map(|v| v).collect()), - timestamp_with_time_zone_: timestamp_with_time_zone_ - .map(|v| v.map(|v| v).collect()), - date_: date_.map(|v| v.map(|v| v).collect()), - time_: time_.map(|v| v.map(|v| v).collect()), - json_: json_.map(|v| { - v.map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect() - }), - jsonb_: jsonb_.map(|v| { - v.map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect() - }), - uuid_: uuid_.map(|v| v.map(|v| v).collect()), - inet_: inet_.map(|v| v.map(|v| v).collect()), - macaddr_: macaddr_.map(|v| v.map(|v| v).collect()), - numeric_: numeric_.map(|v| v.map(|v| v).collect()), - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> EverythingArrayNullBorrowed, - mapper: fn(EverythingArrayNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingArrayNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingArrayNullBorrowed) -> R, - ) -> EverythingArrayNullQuery<'a, C, R, N> { - EverythingArrayNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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 struct SuperSuperTypesPublicNightmareCompositeQuery< - '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, - extractor: - fn(&tokio_postgres::Row) -> super::super::types::public::NightmareCompositeBorrowed, - mapper: fn(super::super::types::public::NightmareCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicNightmareCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::NightmareCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicNightmareCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicNightmareCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> SelectEverythingStmt { - SelectEverythingStmt(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, Everything, 0> { - EverythingQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - smallserial_: row.get(5), - serial2_: row.get(6), - int_: row.get(7), - int4_: row.get(8), - serial_: row.get(9), - serial4_: row.get(10), - bingint_: row.get(11), - int8_: row.get(12), - bigserial_: row.get(13), - serial8_: row.get(14), - float4_: row.get(15), - real_: row.get(16), - float8_: row.get(17), - double_precision_: row.get(18), - text_: row.get(19), - varchar_: row.get(20), - bytea_: row.get(21), - timestamp_: row.get(22), - timestamp_without_time_zone_: row.get(23), - timestamptz_: row.get(24), - timestamp_with_time_zone_: row.get(25), - date_: row.get(26), - time_: row.get(27), - json_: row.get(28), - jsonb_: row.get(29), - uuid_: row.get(30), - inet_: row.get(31), - macaddr_: row.get(32), - numeric_: row.get(33), - }, - mapper: |it| ::from(it), - } - } - } - pub fn select_everything_null() -> SelectEverythingNullStmt { - SelectEverythingNullStmt(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, EverythingNull, 0> { - EverythingNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingNullBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - smallserial_: row.get(5), - serial2_: row.get(6), - int_: row.get(7), - int4_: row.get(8), - serial_: row.get(9), - serial4_: row.get(10), - bingint_: row.get(11), - int8_: row.get(12), - bigserial_: row.get(13), - serial8_: row.get(14), - float4_: row.get(15), - real_: row.get(16), - float8_: row.get(17), - double_precision_: row.get(18), - text_: row.get(19), - varchar_: row.get(20), - bytea_: row.get(21), - timestamp_: row.get(22), - timestamp_without_time_zone_: row.get(23), - timestamptz_: row.get(24), - timestamp_with_time_zone_: row.get(25), - date_: row.get(26), - time_: row.get(27), - json_: row.get(28), - jsonb_: row.get(29), - uuid_: row.get(30), - inet_: row.get(31), - macaddr_: row.get(32), - numeric_: row.get(33), - }, - mapper: |it| ::from(it), - } - } - } - 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_) - 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 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, - client: &'a C, - bool_: &'a bool, - boolean_: &'a bool, - char_: &'a i8, - smallint_: &'a i16, - int2_: &'a i16, - smallserial_: &'a i16, - serial2_: &'a i16, - int_: &'a i32, - int4_: &'a i32, - serial_: &'a i32, - serial4_: &'a i32, - bingint_: &'a i64, - int8_: &'a i64, - bigserial_: &'a i64, - serial8_: &'a i64, - float4_: &'a f32, - real_: &'a f32, - float8_: &'a f64, - double_precision_: &'a f64, - text_: &'a T1, - varchar_: &'a T2, - bytea_: &'a T3, - timestamp_: &'a time::PrimitiveDateTime, - timestamp_without_time_zone_: &'a time::PrimitiveDateTime, - timestamptz_: &'a time::OffsetDateTime, - timestamp_with_time_zone_: &'a time::OffsetDateTime, - date_: &'a time::Date, - time_: &'a time::Time, - json_: &'a T4, - jsonb_: &'a T5, - uuid_: &'a uuid::Uuid, - inet_: &'a std::net::IpAddr, - macaddr_: &'a eui48::MacAddress, - numeric_: &'a rust_decimal::Decimal, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client - .execute( - stmt, - &[ - 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_, - ], - ) - .await - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::StringSql, - T2: cornucopia_async::StringSql, - T3: cornucopia_async::BytesSql, - T4: cornucopia_async::JsonSql, - T5: cornucopia_async::JsonSql, - > - cornucopia_async::Params< - 'a, - EverythingParams, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for InsertEverythingStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a EverythingParams, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind( - client, - ¶ms.bool_, - ¶ms.boolean_, - ¶ms.char_, - ¶ms.smallint_, - ¶ms.int2_, - ¶ms.smallserial_, - ¶ms.serial2_, - ¶ms.int_, - ¶ms.int4_, - ¶ms.serial_, - ¶ms.serial4_, - ¶ms.bingint_, - ¶ms.int8_, - ¶ms.bigserial_, - ¶ms.serial8_, - ¶ms.float4_, - ¶ms.real_, - ¶ms.float8_, - ¶ms.double_precision_, - ¶ms.text_, - ¶ms.varchar_, - ¶ms.bytea_, - ¶ms.timestamp_, - ¶ms.timestamp_without_time_zone_, - ¶ms.timestamptz_, - ¶ms.timestamp_with_time_zone_, - ¶ms.date_, - ¶ms.time_, - ¶ms.json_, - ¶ms.jsonb_, - ¶ms.uuid_, - ¶ms.inet_, - ¶ms.macaddr_, - ¶ms.numeric_, - )) - } - } - pub fn select_everything_array() -> SelectEverythingArrayStmt { - SelectEverythingArrayStmt(cornucopia_async::private::Stmt::new( - "SELECT - * -FROM - EverythingArray", - )) - } - pub struct SelectEverythingArrayStmt(cornucopia_async::private::Stmt); - impl SelectEverythingArrayStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> EverythingArrayQuery<'a, C, EverythingArray, 0> { - EverythingArrayQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingArrayBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - int_: row.get(5), - int4_: row.get(6), - bingint_: row.get(7), - int8_: row.get(8), - float4_: row.get(9), - real_: row.get(10), - float8_: row.get(11), - double_precision_: row.get(12), - text_: row.get(13), - varchar_: row.get(14), - bytea_: row.get(15), - timestamp_: row.get(16), - timestamp_without_time_zone_: row.get(17), - timestamptz_: row.get(18), - timestamp_with_time_zone_: row.get(19), - date_: row.get(20), - time_: row.get(21), - json_: row.get(22), - jsonb_: row.get(23), - uuid_: row.get(24), - inet_: row.get(25), - macaddr_: row.get(26), - numeric_: row.get(27), - }, - mapper: |it| ::from(it), - } - } - } - pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { - SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt::new( - "SELECT - * -FROM - EverythingArray", - )) - } - pub struct SelectEverythingArrayNullStmt(cornucopia_async::private::Stmt); - impl SelectEverythingArrayNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> EverythingArrayNullQuery<'a, C, EverythingArrayNull, 0> { - EverythingArrayNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingArrayNullBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - int_: row.get(5), - int4_: row.get(6), - bingint_: row.get(7), - int8_: row.get(8), - float4_: row.get(9), - real_: row.get(10), - float8_: row.get(11), - double_precision_: row.get(12), - text_: row.get(13), - varchar_: row.get(14), - bytea_: row.get(15), - timestamp_: row.get(16), - timestamp_without_time_zone_: row.get(17), - timestamptz_: row.get(18), - timestamp_with_time_zone_: row.get(19), - date_: row.get(20), - time_: row.get(21), - json_: row.get(22), - jsonb_: row.get(23), - uuid_: row.get(24), - inet_: row.get(25), - macaddr_: row.get(26), - numeric_: row.get(27), - }, - mapper: |it| ::from(it), - } - } - } - 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_) - 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 async fn bind< - 'a, - C: GenericClient, - T1: cornucopia_async::ArraySql, - T2: cornucopia_async::ArraySql, - T3: cornucopia_async::ArraySql, - T4: cornucopia_async::ArraySql, - T5: cornucopia_async::ArraySql, - T6: cornucopia_async::ArraySql, - T7: cornucopia_async::ArraySql, - T8: cornucopia_async::ArraySql, - T9: cornucopia_async::ArraySql, - T10: cornucopia_async::ArraySql, - T11: cornucopia_async::ArraySql, - T12: cornucopia_async::ArraySql, - T13: cornucopia_async::ArraySql, - T14: cornucopia_async::StringSql, - T15: cornucopia_async::ArraySql, - T16: cornucopia_async::StringSql, - T17: cornucopia_async::ArraySql, - T18: cornucopia_async::BytesSql, - T19: cornucopia_async::ArraySql, - T20: cornucopia_async::ArraySql, - T21: cornucopia_async::ArraySql, - T22: cornucopia_async::ArraySql, - T23: cornucopia_async::ArraySql, - T24: cornucopia_async::ArraySql, - T25: cornucopia_async::ArraySql, - T26: cornucopia_async::JsonSql, - T27: cornucopia_async::ArraySql, - T28: cornucopia_async::JsonSql, - T29: cornucopia_async::ArraySql, - T30: cornucopia_async::ArraySql, - T31: cornucopia_async::ArraySql, - T32: cornucopia_async::ArraySql, - T33: cornucopia_async::ArraySql, - >( - &'a mut self, - client: &'a C, - bool_: &'a T1, - boolean_: &'a T2, - char_: &'a T3, - smallint_: &'a T4, - int2_: &'a T5, - int_: &'a T6, - int4_: &'a T7, - bingint_: &'a T8, - int8_: &'a T9, - float4_: &'a T10, - real_: &'a T11, - float8_: &'a T12, - double_precision_: &'a T13, - text_: &'a T15, - varchar_: &'a T17, - bytea_: &'a T19, - timestamp_: &'a T20, - timestamp_without_time_zone_: &'a T21, - timestamptz_: &'a T22, - timestamp_with_time_zone_: &'a T23, - date_: &'a T24, - time_: &'a T25, - json_: &'a T27, - jsonb_: &'a T29, - uuid_: &'a T30, - inet_: &'a T31, - macaddr_: &'a T32, - numeric_: &'a T33, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client - .execute( - stmt, - &[ - 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_, - ], - ) - .await - } - } - impl< - 'a, - C: GenericClient + Send + Sync, - T1: cornucopia_async::ArraySql, - T2: cornucopia_async::ArraySql, - T3: cornucopia_async::ArraySql, - T4: cornucopia_async::ArraySql, - T5: cornucopia_async::ArraySql, - T6: cornucopia_async::ArraySql, - T7: cornucopia_async::ArraySql, - T8: cornucopia_async::ArraySql, - T9: cornucopia_async::ArraySql, - T10: cornucopia_async::ArraySql, - T11: cornucopia_async::ArraySql, - T12: cornucopia_async::ArraySql, - T13: cornucopia_async::ArraySql, - T14: cornucopia_async::StringSql, - T15: cornucopia_async::ArraySql, - T16: cornucopia_async::StringSql, - T17: cornucopia_async::ArraySql, - T18: cornucopia_async::BytesSql, - T19: cornucopia_async::ArraySql, - T20: cornucopia_async::ArraySql, - T21: cornucopia_async::ArraySql, - T22: cornucopia_async::ArraySql, - T23: cornucopia_async::ArraySql, - T24: cornucopia_async::ArraySql, - T25: cornucopia_async::ArraySql, - T26: cornucopia_async::JsonSql, - T27: cornucopia_async::ArraySql, - T28: cornucopia_async::JsonSql, - T29: cornucopia_async::ArraySql, - T30: cornucopia_async::ArraySql, - T31: cornucopia_async::ArraySql, - T32: cornucopia_async::ArraySql, - T33: cornucopia_async::ArraySql, - > - cornucopia_async::Params< - 'a, - EverythingArrayParams< - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31, - T32, - T33, - >, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for InsertEverythingArrayStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a EverythingArrayParams< - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31, - T32, - T33, - >, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind( - client, - ¶ms.bool_, - ¶ms.boolean_, - ¶ms.char_, - ¶ms.smallint_, - ¶ms.int2_, - ¶ms.int_, - ¶ms.int4_, - ¶ms.bingint_, - ¶ms.int8_, - ¶ms.float4_, - ¶ms.real_, - ¶ms.float8_, - ¶ms.double_precision_, - ¶ms.text_, - ¶ms.varchar_, - ¶ms.bytea_, - ¶ms.timestamp_, - ¶ms.timestamp_without_time_zone_, - ¶ms.timestamptz_, - ¶ms.timestamp_with_time_zone_, - ¶ms.date_, - ¶ms.time_, - ¶ms.json_, - ¶ms.jsonb_, - ¶ms.uuid_, - ¶ms.inet_, - ¶ms.macaddr_, - ¶ms.numeric_, - )) - } - } - pub fn select_nightmare() -> SelectNightmareStmt { - SelectNightmareStmt(cornucopia_async::private::Stmt::new( - "SELECT - * -FROM - nightmare", - )) - } - pub struct SelectNightmareStmt(cornucopia_async::private::Stmt); - impl SelectNightmareStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SuperSuperTypesPublicNightmareCompositeQuery< - 'a, - C, - super::super::types::public::NightmareComposite, - 0, - > { - SuperSuperTypesPublicNightmareCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it.into(), - } - } - } - pub fn insert_nightmare() -> InsertNightmareStmt { - InsertNightmareStmt(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>( - &'a mut self, - client: &'a C, - composite: &'a super::super::types::public::NightmareCompositeParams<'a>, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[composite]).await - } - } - } - pub mod syntax { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; - #[derive(Debug)] - pub struct ImplicitCompactParams { - pub name: Option, - pub price: Option, - } - #[derive(Debug)] - pub struct ImplicitSpacedParams { - pub name: Option, - pub price: Option, - } - #[derive(Debug)] - pub struct Params { - pub name: T1, - pub price: f64, - } - #[derive(Debug)] - pub struct ParamsSpace { - pub name: T1, - pub price: f64, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySqlParams { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql1Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql2Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql3Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql4Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql6Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql7Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql8Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql9Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql10Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - pub struct SuperSuperTypesPublicCloneCompositeQuery<'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, - extractor: - fn(&tokio_postgres::Row) -> super::super::types::public::CloneCompositeBorrowed, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCloneCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicCloneCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCloneCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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 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, - extractor: fn(&tokio_postgres::Row) -> Option, - mapper: fn(Option) -> T, - } - impl<'a, C, T: 'a, const N: usize> Optioni32Query<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Option) -> R) -> Optioni32Query<'a, C, R, N> { - Optioni32Query { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct Row { - pub id: i32, - } - 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, - extractor: fn(&tokio_postgres::Row) -> Row, - mapper: fn(Row) -> T, - } - impl<'a, C, T: 'a, const N: usize> RowQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Row) -> R) -> RowQuery<'a, C, R, N> { - RowQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct RowSpace { - pub id: i32, - } - 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, - extractor: fn(&tokio_postgres::Row) -> RowSpace, - mapper: fn(RowSpace) -> T, - } - impl<'a, C, T: 'a, const N: usize> RowSpaceQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(RowSpace) -> R) -> RowSpaceQuery<'a, C, R, N> { - RowSpaceQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Typeof { - pub trick_y: String, - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - pub struct TypeofBorrowed<'a> { - pub trick_y: &'a str, - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - impl<'a> From> for Typeof { - fn from( - TypeofBorrowed { - trick_y, - r#async, - r#enum, - }: TypeofBorrowed<'a>, - ) -> Self { - Self { - trick_y: trick_y.into(), - r#async, - r#enum, - } - } - } - 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, - extractor: fn(&tokio_postgres::Row) -> TypeofBorrowed, - mapper: fn(TypeofBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> TypeofQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(TypeofBorrowed) -> R) -> TypeofQuery<'a, C, R, N> { - TypeofQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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?; - 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?; - Ok(self - .client - .query_opt(stmt, &self.params) - .await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } - pub async fn iter( - self, - ) -> Result< - impl futures::Stream> + 'a, - tokio_postgres::Error, - > { - let stmt = self.stmt.prepare(self.client).await?; - let it = self - .client - .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() -> SelectCompactStmt { - SelectCompactStmt(cornucopia_async::private::Stmt::new("SELECT * FROM clone")) - } - pub struct SelectCompactStmt(cornucopia_async::private::Stmt); - impl SelectCompactStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it.into(), - } - } - } - pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(cornucopia_async::private::Stmt::new( - " SELECT * FROM clone ", - )) - } - pub struct SelectSpacedStmt(cornucopia_async::private::Stmt); - impl SelectSpacedStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - 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 struct ImplicitCompactStmt(cornucopia_async::private::Stmt); - impl ImplicitCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - name: &'a Option, - price: &'a Option, - ) -> Optioni32Query<'a, C, Option, 2> { - Optioni32Query { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params< - 'a, - ImplicitCompactParams, - Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitCompactStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a ImplicitCompactParams, - ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶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 struct ImplicitSpacedStmt(cornucopia_async::private::Stmt); - impl ImplicitSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - name: &'a Option, - price: &'a Option, - ) -> Optioni32Query<'a, C, Option, 2> { - Optioni32Query { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params< - 'a, - ImplicitSpacedParams, - Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitSpacedStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a ImplicitSpacedParams, - ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶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 struct NamedCompactStmt(cornucopia_async::private::Stmt); - impl NamedCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - name: &'a T1, - price: &'a f64, - ) -> RowQuery<'a, C, Row, 2> { - RowQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| Row { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, Params, RowQuery<'a, C, Row, 2>, C> - for NamedCompactStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a Params, - ) -> RowQuery<'a, C, Row, 2> { - self.bind(client, ¶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 struct NamedSpacedStmt(cornucopia_async::private::Stmt); - impl NamedSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( - &'a mut self, - client: &'a C, - name: &'a T1, - price: &'a f64, - ) -> RowSpaceQuery<'a, C, RowSpace, 2> { - RowSpaceQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| RowSpace { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_async::StringSql> - cornucopia_async::Params<'a, ParamsSpace, RowSpaceQuery<'a, C, RowSpace, 2>, C> - for NamedSpacedStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a ParamsSpace, - ) -> RowSpaceQuery<'a, C, RowSpace, 2> { - self.bind(client, ¶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 struct TrickySqlStmt(cornucopia_async::private::Stmt); - impl TrickySqlStmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySqlParams, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySqlStmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySqlParams, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql1Stmt(cornucopia_async::private::Stmt); - impl TrickySql1Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql1Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql1Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql1Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql2Stmt(cornucopia_async::private::Stmt); - impl TrickySql2Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql2Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql2Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql2Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql3Stmt(cornucopia_async::private::Stmt); - impl TrickySql3Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql3Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql3Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql3Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql4Stmt(cornucopia_async::private::Stmt); - impl TrickySql4Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql4Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql4Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql4Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql6Stmt(cornucopia_async::private::Stmt); - impl TrickySql6Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql6Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql6Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql6Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql7Stmt(cornucopia_async::private::Stmt); - impl TrickySql7Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql7Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql7Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql7Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql8Stmt(cornucopia_async::private::Stmt); - impl TrickySql8Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql8Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql8Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql8Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql9Stmt(cornucopia_async::private::Stmt); - impl TrickySql9Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql9Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql9Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql9Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶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 struct TrickySql10Stmt(cornucopia_async::private::Stmt); - impl TrickySql10Stmt { - pub async fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[r#async, r#enum]).await - } - } - impl<'a, C: GenericClient + Send + Sync> - cornucopia_async::Params< - 'a, - TrickySql10Params, - std::pin::Pin< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for TrickySql10Stmt - { - fn params( - &'a mut self, - client: &'a C, - params: &'a TrickySql10Params, - ) -> std::pin::Pin< - Box> + Send + 'a>, - > { - Box::pin(self.bind(client, ¶ms.r#async, ¶ms.r#enum)) - } - } - pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt(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, Typeof, 0> { - TypeofQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| TypeofBorrowed { - trick_y: row.get(0), - r#async: row.get(1), - r#enum: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - } -} diff --git a/codegen_test/src/cornucopia_sync.rs b/codegen_test/src/cornucopia_sync.rs deleted file mode 100644 index d6172b98..00000000 --- a/codegen_test/src/cornucopia_sync.rs +++ /dev/null @@ -1,5047 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types { - pub mod public { - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "clone_composite")] - pub struct CloneComposite { - #[postgres(name = "first")] - pub first: i32, - #[postgres(name = "second")] - pub second: String, - } - #[derive(Debug)] - pub struct CloneCompositeBorrowed<'a> { - pub first: i32, - pub second: &'a str, - } - impl<'a> From> for CloneComposite { - fn from(CloneCompositeBorrowed { first, second }: CloneCompositeBorrowed<'a>) -> Self { - Self { - first, - second: second.into(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for CloneCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let first = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let second = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(CloneCompositeBorrowed { first, second }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "clone_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for CloneCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CloneCompositeBorrowed { first, second } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), - "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "clone_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "first" => ::accepts(f.type_()), - "second" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "copy_composite")] - pub struct CopyComposite { - #[postgres(name = "first")] - pub first: i32, - #[postgres(name = "second")] - pub second: f64, - } - impl<'a> postgres_types::ToSql for CopyComposite { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CopyComposite { first, second } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "first" => postgres_types::ToSql::to_sql(first, field.type_(), out), - "second" => postgres_types::ToSql::to_sql(second, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "copy_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "first" => ::accepts(f.type_()), - "second" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "domain_composite")] - pub struct DomainComposite { - #[postgres(name = "txt")] - pub txt: String, - #[postgres(name = "json")] - pub json: serde_json::Value, - #[postgres(name = "nb")] - pub nb: i32, - #[postgres(name = "arr")] - pub arr: Vec, - } - #[derive(Debug)] - pub struct DomainCompositeBorrowed<'a> { - pub txt: &'a str, - pub json: postgres_types::Json<&'a serde_json::value::RawValue>, - pub nb: i32, - pub arr: cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - } - impl<'a> From> for DomainComposite { - fn from( - DomainCompositeBorrowed { txt, json, nb, arr }: DomainCompositeBorrowed<'a>, - ) -> Self { - Self { - txt: txt.into(), - json: serde_json::from_str(json.0.get()).unwrap(), - nb, - arr: arr - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for DomainCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let txt = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let json = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let nb = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let arr = postgres_types::private::read_value(fields[3].type_(), &mut out)?; - Ok(DomainCompositeBorrowed { txt, json, nb, arr }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "domain_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct DomainCompositeParams<'a> { - pub txt: &'a str, - pub json: &'a serde_json::value::Value, - pub nb: i32, - pub arr: &'a [&'a serde_json::value::Value], - } - impl<'a> postgres_types::ToSql for DomainCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let DomainCompositeParams { txt, json, nb, arr } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "txt" => postgres_types::ToSql::to_sql( - &cornucopia_sync::private::Domain(txt), - field.type_(), - out, - ), - "json" => postgres_types::ToSql::to_sql( - &cornucopia_sync::private::Domain(json), - field.type_(), - out, - ), - "nb" => postgres_types::ToSql::to_sql( - &cornucopia_sync::private::Domain(nb), - field.type_(), - out, - ), - "arr" => postgres_types::ToSql::to_sql( - &cornucopia_sync::private::Domain( - &cornucopia_sync::private::DomainArray(arr), - ), - field.type_(), - out, - ), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "domain_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 4 { - return false; - } - fields.iter().all(| f | match f.name() - { - "txt" => < cornucopia_sync::private::Domain::<&'a str> as postgres_types :: - ToSql > :: accepts(f.type_()),"json" => < cornucopia_sync::private::Domain::<&'a serde_json::value::Value> as postgres_types :: - ToSql > :: accepts(f.type_()),"nb" => < cornucopia_sync::private::Domain:: as postgres_types :: - ToSql > :: accepts(f.type_()),"arr" => < cornucopia_sync::private::Domain::> as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "named_composite")] - pub struct NamedComposite { - #[postgres(name = "wow")] - pub wow: Option, - #[postgres(name = "such_cool")] - pub such_cool: Option, - } - #[derive(Debug)] - pub struct NamedCompositeBorrowed<'a> { - pub wow: Option<&'a str>, - pub such_cool: Option, - } - impl<'a> From> for NamedComposite { - fn from(NamedCompositeBorrowed { wow, such_cool }: NamedCompositeBorrowed<'a>) -> Self { - Self { - wow: wow.map(|v| v.into()), - such_cool, - } - } - } - impl<'a> postgres_types::FromSql<'a> for NamedCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(NamedCompositeBorrowed { wow, such_cool }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "named_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for NamedCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NamedCompositeBorrowed { wow, such_cool } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), - "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "named_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| match f.name() { - "wow" => <&'a str as postgres_types::ToSql>::accepts(f.type_()), - "such_cool" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum EnumWithDot { - variant_with_dot, - } - impl<'a> postgres_types::ToSql for EnumWithDot { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - EnumWithDot::variant_with_dot => "variant.with_dot", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "enum.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 1 { - return false; - } - variants.iter().all(|v| match &**v { - "variant.with_dot" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for EnumWithDot { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "variant.with_dot" => Ok(EnumWithDot::variant_with_dot), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "enum.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 1 { - return false; - } - variants.iter().all(|v| match &**v { - "variant.with_dot" => true, - _ => false, - }) - } - _ => false, - } - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "named_composite.with_dot")] - pub struct NamedCompositeWithDot { - #[postgres(name = "this.is.inconceivable")] - pub this_is_inconceivable: Option, - } - impl<'a> postgres_types::ToSql for NamedCompositeWithDot { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NamedCompositeWithDot { - this_is_inconceivable, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "this.is.inconceivable" => { - postgres_types::ToSql::to_sql(this_is_inconceivable, field.type_(), out) - } - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "named_composite.with_dot" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 1 { - return false; - } - fields.iter().all(| f | match f.name() - { - "this.is.inconceivable" => < super::super::types::public::EnumWithDot as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "nullity_composite")] - pub struct NullityComposite { - #[postgres(name = "jsons")] - pub jsons: Option>>, - #[postgres(name = "id")] - pub id: i32, - } - #[derive(Debug)] - pub struct NullityCompositeBorrowed<'a> { - pub jsons: Option< - cornucopia_sync::ArrayIterator< - 'a, - Option>, - >, - >, - pub id: i32, - } - impl<'a> From> for NullityComposite { - fn from(NullityCompositeBorrowed { jsons, id }: NullityCompositeBorrowed<'a>) -> Self { - Self { - jsons: jsons.map(|v| { - v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) - .collect() - }), - id, - } - } - } - impl<'a> postgres_types::FromSql<'a> for NullityCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let jsons = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let id = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - Ok(NullityCompositeBorrowed { jsons, id }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "nullity_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct NullityCompositeParams<'a> { - pub jsons: Option<&'a [Option<&'a serde_json::value::Value>]>, - pub id: i32, - } - impl<'a> postgres_types::ToSql for NullityCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NullityCompositeParams { jsons, id } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "jsons" => postgres_types::ToSql::to_sql(jsons, field.type_(), out), - "id" => postgres_types::ToSql::to_sql(id, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "nullity_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 2 { - return false; - } - fields.iter().all(|f| { - match f.name() - { - "jsons" => < &'a [&'a serde_json::value::Value] as postgres_types :: - ToSql > :: accepts(f.type_()),"id" => < i32 as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - } - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum SpongebobCharacter { - Bob, - Patrick, - Squidward, - } - impl<'a> postgres_types::ToSql for SpongebobCharacter { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - SpongebobCharacter::Bob => "Bob", - SpongebobCharacter::Patrick => "Patrick", - SpongebobCharacter::Squidward => "Squidward", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "spongebob_character" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "Bob" => true, - "Patrick" => true, - "Squidward" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for SpongebobCharacter { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "Bob" => Ok(SpongebobCharacter::Bob), - "Patrick" => Ok(SpongebobCharacter::Patrick), - "Squidward" => Ok(SpongebobCharacter::Squidward), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "spongebob_character" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "Bob" => true, - "Patrick" => true, - "Squidward" => true, - _ => false, - }) - } - _ => false, - } - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "custom_composite")] - pub struct CustomComposite { - #[postgres(name = "wow")] - pub wow: String, - #[postgres(name = "such_cool")] - pub such_cool: i32, - #[postgres(name = "nice")] - pub nice: super::super::types::public::SpongebobCharacter, - } - #[derive(Debug)] - pub struct CustomCompositeBorrowed<'a> { - pub wow: &'a str, - pub such_cool: i32, - pub nice: super::super::types::public::SpongebobCharacter, - } - impl<'a> From> for CustomComposite { - fn from( - CustomCompositeBorrowed { - wow, - such_cool, - nice, - }: CustomCompositeBorrowed<'a>, - ) -> Self { - Self { - wow: wow.into(), - such_cool, - nice, - } - } - } - impl<'a> postgres_types::FromSql<'a> for CustomCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let wow = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let such_cool = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let nice = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - Ok(CustomCompositeBorrowed { - wow, - such_cool, - nice, - }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "custom_composite" && ty.schema() == "public" - } - } - impl<'a> postgres_types::ToSql for CustomCompositeBorrowed<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let CustomCompositeBorrowed { - wow, - such_cool, - nice, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "wow" => postgres_types::ToSql::to_sql(wow, field.type_(), out), - "such_cool" => postgres_types::ToSql::to_sql(such_cool, field.type_(), out), - "nice" => postgres_types::ToSql::to_sql(nice, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "custom_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 3 { - return false; - } - fields.iter().all(| f | match f.name() - { - "wow" => < &'a str as postgres_types :: - ToSql > :: accepts(f.type_()),"such_cool" => < i32 as postgres_types :: - ToSql > :: accepts(f.type_()),"nice" => < super::super::types::public::SpongebobCharacter as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Clone, PartialEq)] - #[postgres(name = "nightmare_composite")] - pub struct NightmareComposite { - #[postgres(name = "custom")] - pub custom: Vec, - #[postgres(name = "spongebob")] - pub spongebob: Vec, - #[postgres(name = "domain")] - pub domain: String, - } - #[derive(Debug)] - pub struct NightmareCompositeBorrowed<'a> { - pub custom: cornucopia_sync::ArrayIterator< - 'a, - super::super::types::public::CustomCompositeBorrowed<'a>, - >, - pub spongebob: - cornucopia_sync::ArrayIterator<'a, super::super::types::public::SpongebobCharacter>, - pub domain: &'a str, - } - impl<'a> From> for NightmareComposite { - fn from( - NightmareCompositeBorrowed { - custom, - spongebob, - domain, - }: NightmareCompositeBorrowed<'a>, - ) -> Self { - Self { - custom: custom.map(|v| v.into()).collect(), - spongebob: spongebob.map(|v| v).collect(), - domain: domain.into(), - } - } - } - impl<'a> postgres_types::FromSql<'a> for NightmareCompositeBorrowed<'a> { - fn from_sql( - ty: &postgres_types::Type, - out: &'a [u8], - ) -> Result, Box> - { - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - let mut out = out; - let num_fields = postgres_types::private::read_be_i32(&mut out)?; - if num_fields as usize != fields.len() { - return std::result::Result::Err(std::convert::Into::into(format!( - "invalid field count: {} vs {}", - num_fields, - fields.len() - ))); - } - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let custom = postgres_types::private::read_value(fields[0].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let spongebob = postgres_types::private::read_value(fields[1].type_(), &mut out)?; - let _oid = postgres_types::private::read_be_i32(&mut out)?; - let domain = postgres_types::private::read_value(fields[2].type_(), &mut out)?; - Ok(NightmareCompositeBorrowed { - custom, - spongebob, - domain, - }) - } - fn accepts(ty: &postgres_types::Type) -> bool { - ty.name() == "nightmare_composite" && ty.schema() == "public" - } - } - #[derive(Debug)] - pub struct NightmareCompositeParams<'a> { - pub custom: &'a [super::super::types::public::CustomCompositeBorrowed<'a>], - pub spongebob: &'a [super::super::types::public::SpongebobCharacter], - pub domain: &'a str, - } - impl<'a> postgres_types::ToSql for NightmareCompositeParams<'a> { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let NightmareCompositeParams { - custom, - spongebob, - domain, - } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "custom" => postgres_types::ToSql::to_sql(custom, field.type_(), out), - "spongebob" => postgres_types::ToSql::to_sql(spongebob, field.type_(), out), - "domain" => postgres_types::ToSql::to_sql( - &cornucopia_sync::private::Domain(domain), - field.type_(), - out, - ), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "nightmare_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 3 { - return false; - } - fields.iter().all(| f | match f.name() - { - "custom" => < &'a [super::super::types::public::CustomCompositeBorrowed<'a>] as postgres_types :: - ToSql > :: accepts(f.type_()),"spongebob" => < &'a [super::super::types::public::SpongebobCharacter] as postgres_types :: - ToSql > :: accepts(f.type_()),"domain" => < cornucopia_sync::private::Domain::<&'a str> as postgres_types :: - ToSql > :: accepts(f.type_()),_ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, postgres_types :: FromSql, Copy, Clone, PartialEq)] - #[postgres(name = "syntax_composite")] - pub struct SyntaxComposite { - #[postgres(name = "async")] - pub r#async: i32, - } - impl<'a> postgres_types::ToSql for SyntaxComposite { - fn to_sql( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let SyntaxComposite { r#async } = self; - let fields = match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => fields, - _ => unreachable!(), - }; - out.extend_from_slice(&(fields.len() as i32).to_be_bytes()); - for field in fields { - out.extend_from_slice(&field.type_().oid().to_be_bytes()); - let base = out.len(); - out.extend_from_slice(&[0; 4]); - let r = match field.name() { - "async" => postgres_types::ToSql::to_sql(r#async, field.type_(), out), - _ => unreachable!(), - }; - let count = match r? { - postgres_types::IsNull::Yes => -1, - postgres_types::IsNull::No => { - let len = out.len() - base - 4; - if len > i32::max_value() as usize { - return Err(Into::into("value too large to transmit")); - } - len as i32 - } - }; - out[base..base + 4].copy_from_slice(&count.to_be_bytes()); - } - Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_composite" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Composite(ref fields) => { - if fields.len() != 1 { - return false; - } - fields.iter().all(|f| match f.name() { - "async" => ::accepts(f.type_()), - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - #[derive(serde::Serialize, Debug, Clone, Copy, PartialEq, Eq)] - #[allow(non_camel_case_types)] - pub enum SyntaxEnum { - r#async, - r#box, - I_Love_Chocolate, - } - impl<'a> postgres_types::ToSql for SyntaxEnum { - fn to_sql( - &self, - ty: &postgres_types::Type, - buf: &mut postgres_types::private::BytesMut, - ) -> Result> - { - let s = match *self { - SyntaxEnum::r#async => "async", - SyntaxEnum::r#box => "box", - SyntaxEnum::I_Love_Chocolate => "I Love Chocolate", - }; - buf.extend_from_slice(s.as_bytes()); - std::result::Result::Ok(postgres_types::IsNull::No) - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_enum" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "async" => true, - "box" => true, - "I Love Chocolate" => true, - _ => false, - }) - } - _ => false, - } - } - fn to_sql_checked( - &self, - ty: &postgres_types::Type, - out: &mut postgres_types::private::BytesMut, - ) -> Result> - { - postgres_types::__to_sql_checked(self, ty, out) - } - } - impl<'a> postgres_types::FromSql<'a> for SyntaxEnum { - fn from_sql( - ty: &postgres_types::Type, - buf: &'a [u8], - ) -> Result> { - match std::str::from_utf8(buf)? { - "async" => Ok(SyntaxEnum::r#async), - "box" => Ok(SyntaxEnum::r#box), - "I Love Chocolate" => Ok(SyntaxEnum::I_Love_Chocolate), - s => Result::Err(Into::into(format!("invalid variant `{}`", s))), - } - } - fn accepts(ty: &postgres_types::Type) -> bool { - if ty.name() != "syntax_enum" { - return false; - } - match *ty.kind() { - postgres_types::Kind::Enum(ref variants) => { - if variants.len() != 3 { - return false; - } - variants.iter().all(|v| match &**v { - "async" => true, - "box" => true, - "I Love Chocolate" => true, - _ => false, - }) - } - _ => false, - } - } - } - } -} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod copy { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - pub struct SuperSuperTypesPublicCloneCompositeQuery<'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, - extractor: fn(&postgres::Row) -> super::super::types::public::CloneCompositeBorrowed, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCloneCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicCloneCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCloneCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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 struct SuperSuperTypesPublicCopyCompositeQuery<'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, - extractor: fn(&postgres::Row) -> super::super::types::public::CopyComposite, - mapper: fn(super::super::types::public::CopyComposite) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCopyCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CopyComposite) -> R, - ) -> SuperSuperTypesPublicCopyCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCopyCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> 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>( - &'a mut self, - client: &'a mut C, - composite: &'a super::super::types::public::CloneCompositeBorrowed<'a>, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) - } - } - pub fn select_clone() -> SelectCloneStmt { - SelectCloneStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) - } - pub struct SelectCloneStmt(cornucopia_sync::private::Stmt); - impl SelectCloneStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - 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 struct InsertCopyStmt(cornucopia_sync::private::Stmt); - impl InsertCopyStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - composite: &'a super::super::types::public::CopyComposite, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) - } - } - pub fn select_copy() -> SelectCopyStmt { - SelectCopyStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM copy")) - } - pub struct SelectCopyStmt(cornucopia_sync::private::Stmt); - impl SelectCopyStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SuperSuperTypesPublicCopyCompositeQuery< - 'a, - C, - super::super::types::public::CopyComposite, - 0, - > { - SuperSuperTypesPublicCopyCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - } - pub mod domain { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct InsertNightmareDomainParams< - 'a, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::JsonSql, - T3: cornucopia_sync::JsonSql, - T4: cornucopia_sync::ArraySql, - > { - pub txt: T1, - pub json: T2, - pub nb: i32, - pub arr: T4, - pub composite: Option>, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectNightmareDomain { - pub txt: String, - pub json: serde_json::Value, - pub nb: i32, - pub arr: Vec, - } - pub struct SelectNightmareDomainBorrowed<'a> { - pub txt: &'a str, - pub json: postgres_types::Json<&'a serde_json::value::RawValue>, - pub nb: i32, - pub arr: cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - } - impl<'a> From> for SelectNightmareDomain { - fn from( - SelectNightmareDomainBorrowed { txt, json, nb, arr }: SelectNightmareDomainBorrowed< - 'a, - >, - ) -> Self { - Self { - txt: txt.into(), - json: serde_json::from_str(json.0.get()).unwrap(), - nb, - arr: arr - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - } - } - } - 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, - extractor: fn(&postgres::Row) -> SelectNightmareDomainBorrowed, - mapper: fn(SelectNightmareDomainBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectNightmareDomainBorrowed) -> R, - ) -> SelectNightmareDomainQuery<'a, C, R, N> { - SelectNightmareDomainQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectNightmareDomainNull { - pub txt: Option, - pub json: Option, - pub nb: Option, - pub arr: Option>>, - pub composite: Option, - } - pub struct SelectNightmareDomainNullBorrowed<'a> { - pub txt: Option<&'a str>, - pub json: Option>, - pub nb: Option, - pub arr: Option< - cornucopia_sync::ArrayIterator< - 'a, - Option>, - >, - >, - pub composite: Option>, - } - impl<'a> From> for SelectNightmareDomainNull { - fn from( - SelectNightmareDomainNullBorrowed { - txt, - json, - nb, - arr, - composite, - }: SelectNightmareDomainNullBorrowed<'a>, - ) -> Self { - Self { - txt: txt.map(|v| v.into()), - json: json.map(|v| serde_json::from_str(v.0.get()).unwrap()), - nb, - arr: arr.map(|v| { - v.map(|v| v.map(|v| serde_json::from_str(v.0.get()).unwrap())) - .collect() - }), - composite: composite.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> SelectNightmareDomainNullBorrowed, - mapper: fn(SelectNightmareDomainNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectNightmareDomainNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectNightmareDomainNullBorrowed) -> R, - ) -> SelectNightmareDomainNullQuery<'a, C, R, N> { - SelectNightmareDomainNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> SelectNightmareDomainStmt { - SelectNightmareDomainStmt(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>( - &'a mut self, - client: &'a mut C, - ) -> SelectNightmareDomainQuery<'a, C, SelectNightmareDomain, 0> { - SelectNightmareDomainQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectNightmareDomainBorrowed { - txt: row.get(0), - json: row.get(1), - nb: row.get(2), - arr: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - 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 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, - arr: &'a T4, - composite: &'a Option>, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( - stmt, - &[ - &cornucopia_sync::private::Domain(txt), - &cornucopia_sync::private::Domain(json), - &cornucopia_sync::private::Domain(nb), - &cornucopia_sync::private::Domain(&cornucopia_sync::private::DomainArray( - arr, - )), - composite, - ], - ) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::JsonSql, - T3: cornucopia_sync::JsonSql, - T4: cornucopia_sync::ArraySql, - > - cornucopia_sync::Params< - 'a, - InsertNightmareDomainParams<'a, T1, T2, T3, T4>, - Result, - C, - > for InsertNightmareDomainStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a InsertNightmareDomainParams<'a, T1, T2, T3, T4>, - ) -> Result { - self.bind( - client, - ¶ms.txt, - ¶ms.json, - ¶ms.nb, - ¶ms.arr, - ¶ms.composite, - ) - } - } - pub fn select_nightmare_domain_null() -> SelectNightmareDomainNullStmt { - SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM nightmare_domain", - )) - } - pub struct SelectNightmareDomainNullStmt(cornucopia_sync::private::Stmt); - impl SelectNightmareDomainNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SelectNightmareDomainNullQuery<'a, C, SelectNightmareDomainNull, 0> { - SelectNightmareDomainNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectNightmareDomainNullBorrowed { - txt: row.get(0), - json: row.get(1), - nb: row.get(2), - arr: row.get(3), - composite: row.get(4), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod named { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct NamedParams { - pub name: T1, - pub price: Option, - } - #[derive(Debug)] - pub struct NamedComplexParams<'a> { - pub named: super::super::types::public::NamedCompositeBorrowed<'a>, - pub named_with_dot: Option, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct Id { - pub id: i32, - } - 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, - extractor: fn(&postgres::Row) -> Id, - mapper: fn(Id) -> T, - } - impl<'a, C, T: 'a, const N: usize> IdQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Id) -> R) -> IdQuery<'a, C, R, N> { - IdQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Named { - pub id: i32, - pub name: String, - pub price: Option, - pub show: bool, - } - pub struct NamedBorrowed<'a> { - pub id: i32, - pub name: &'a str, - pub price: Option, - pub show: bool, - } - impl<'a> From> for Named { - fn from( - NamedBorrowed { - id, - name, - price, - show, - }: NamedBorrowed<'a>, - ) -> Self { - Self { - id, - name: name.into(), - price, - show, - } - } - } - 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, - extractor: fn(&postgres::Row) -> NamedBorrowed, - mapper: fn(NamedBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NamedQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(NamedBorrowed) -> R) -> NamedQuery<'a, C, R, N> { - NamedQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct NamedComplex { - pub named: super::super::types::public::NamedComposite, - pub named_with_dot: Option, - } - pub struct NamedComplexBorrowed<'a> { - pub named: super::super::types::public::NamedCompositeBorrowed<'a>, - pub named_with_dot: Option, - } - impl<'a> From> for NamedComplex { - fn from( - NamedComplexBorrowed { - named, - named_with_dot, - }: NamedComplexBorrowed<'a>, - ) -> Self { - Self { - named: named.into(), - named_with_dot, - } - } - } - 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, - extractor: fn(&postgres::Row) -> NamedComplexBorrowed, - mapper: fn(NamedComplexBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NamedComplexQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(NamedComplexBorrowed) -> R, - ) -> NamedComplexQuery<'a, C, R, N> { - NamedComplexQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> NewNamedVisibleStmt { - NewNamedVisibleStmt(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>( - &'a mut self, - client: &'a mut C, - name: &'a T1, - price: &'a Option, - ) -> IdQuery<'a, C, Id, 2> { - IdQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| Id { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, NamedParams, IdQuery<'a, C, Id, 2>, C> - for NewNamedVisibleStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a NamedParams, - ) -> IdQuery<'a, C, Id, 2> { - self.bind(client, ¶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 struct NewNamedHiddenStmt(cornucopia_sync::private::Stmt); - impl NewNamedHiddenStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - price: &'a Option, - name: &'a T1, - ) -> IdQuery<'a, C, Id, 2> { - IdQuery { - client, - params: [price, name], - stmt: &mut self.0, - extractor: |row| Id { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, NamedParams, IdQuery<'a, C, Id, 2>, C> - for NewNamedHiddenStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a NamedParams, - ) -> IdQuery<'a, C, Id, 2> { - self.bind(client, ¶ms.price, ¶ms.name) - } - } - pub fn named() -> NamedStmt { - NamedStmt(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, Named, 0> { - NamedQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NamedBorrowed { - id: row.get(0), - name: row.get(1), - price: row.get(2), - show: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn named_by_id() -> NamedByIdStmt { - NamedByIdStmt(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, Named, 1> { - NamedQuery { - client, - params: [id], - stmt: &mut self.0, - extractor: |row| NamedBorrowed { - id: row.get(0), - name: row.get(1), - price: row.get(2), - show: row.get(3), - }, - mapper: |it| ::from(it), - } - } - } - pub fn new_named_complex() -> NewNamedComplexStmt { - NewNamedComplexStmt(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>( - &'a mut self, - client: &'a mut C, - named: &'a super::super::types::public::NamedCompositeBorrowed<'a>, - named_with_dot: &'a Option, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[named, named_with_dot]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, NamedComplexParams<'a>, Result, C> - for NewNamedComplexStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a NamedComplexParams<'a>, - ) -> Result { - self.bind(client, ¶ms.named, ¶ms.named_with_dot) - } - } - pub fn named_complex() -> NamedComplexStmt { - NamedComplexStmt(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, NamedComplex, 0> { - NamedComplexQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NamedComplexBorrowed { - named: row.get(0), - named_with_dot: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod nullity { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct NullityParams< - 'a, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::ArraySql>, - T3: cornucopia_sync::StringSql, - > { - pub texts: T2, - pub name: T3, - pub composite: Option>, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Nullity { - pub texts: Vec>, - pub name: String, - pub composite: Option, - } - pub struct NullityBorrowed<'a> { - pub texts: cornucopia_sync::ArrayIterator<'a, Option<&'a str>>, - pub name: &'a str, - pub composite: Option>, - } - impl<'a> From> for Nullity { - fn from( - NullityBorrowed { - texts, - name, - composite, - }: NullityBorrowed<'a>, - ) -> Self { - Self { - texts: texts.map(|v| v.map(|v| v.into())).collect(), - name: name.into(), - composite: composite.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> NullityBorrowed, - mapper: fn(NullityBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> NullityQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(NullityBorrowed) -> R) -> NullityQuery<'a, C, R, N> { - NullityQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> NewNullityStmt { - NewNullityStmt(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 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>, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[texts, name, composite]) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::ArraySql>, - T3: cornucopia_sync::StringSql, - > - cornucopia_sync::Params< - 'a, - NullityParams<'a, T1, T2, T3>, - Result, - C, - > for NewNullityStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a NullityParams<'a, T1, T2, T3>, - ) -> Result { - self.bind(client, ¶ms.texts, ¶ms.name, ¶ms.composite) - } - } - pub fn nullity() -> NullityStmt { - NullityStmt(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, Nullity, 0> { - NullityQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| NullityBorrowed { - texts: row.get(0), - name: row.get(1), - composite: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - } - pub mod params { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct InsertBookParams { - pub author: Option, - pub name: T2, - } - #[derive(Clone, Copy, Debug)] - pub struct ParamsOrderParams { - pub c: i32, - pub a: i32, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct SelectBook { - pub name: String, - pub author: Option, - } - pub struct SelectBookBorrowed<'a> { - pub name: &'a str, - pub author: Option<&'a str>, - } - impl<'a> From> for SelectBook { - fn from(SelectBookBorrowed { name, author }: SelectBookBorrowed<'a>) -> Self { - Self { - name: name.into(), - author: author.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> SelectBookBorrowed, - mapper: fn(SelectBookBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SelectBookQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(SelectBookBorrowed) -> R, - ) -> SelectBookQuery<'a, C, R, N> { - SelectBookQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct FindBooks { - pub name: String, - pub author: Option, - } - pub struct FindBooksBorrowed<'a> { - pub name: &'a str, - pub author: Option<&'a str>, - } - impl<'a> From> for FindBooks { - fn from(FindBooksBorrowed { name, author }: FindBooksBorrowed<'a>) -> Self { - Self { - name: name.into(), - author: author.map(|v| v.into()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> FindBooksBorrowed, - mapper: fn(FindBooksBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> FindBooksQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(FindBooksBorrowed) -> R) -> FindBooksQuery<'a, C, R, N> { - FindBooksQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> InsertBookStmt { - InsertBookStmt(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, - >( - &'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]) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - > - cornucopia_sync::Params<'a, InsertBookParams, Result, C> - for InsertBookStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a InsertBookParams, - ) -> Result { - self.bind(client, ¶ms.author, ¶ms.name) - } - } - pub fn select_book() -> SelectBookStmt { - SelectBookStmt(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, SelectBook, 0> { - SelectBookQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| SelectBookBorrowed { - name: row.get(0), - author: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - pub fn find_books() -> FindBooksStmt { - FindBooksStmt(cornucopia_sync::private::Stmt::new( - "SELECT * FROM book WHERE name = ANY ($1)", - )) - } - pub struct FindBooksStmt(cornucopia_sync::private::Stmt); - impl FindBooksStmt { - 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, FindBooks, 1> { - FindBooksQuery { - client, - params: [title], - stmt: &mut self.0, - extractor: |row| FindBooksBorrowed { - name: row.get(0), - author: row.get(1), - }, - mapper: |it| ::from(it), - } - } - } - 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 struct ParamsUseTwiceStmt(cornucopia_sync::private::Stmt); - impl ParamsUseTwiceStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - name: &'a T1, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.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 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]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, ParamsOrderParams, Result, C> - for ParamsOrderStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a ParamsOrderParams, - ) -> Result { - self.bind(client, ¶ms.c, ¶ms.a) - } - } - } - pub mod stress { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct EverythingParams< - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - T3: cornucopia_sync::BytesSql, - T4: cornucopia_sync::JsonSql, - T5: cornucopia_sync::JsonSql, - > { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: T1, - pub varchar_: T2, - pub bytea_: T3, - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: T4, - pub jsonb_: T5, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - #[derive(Debug)] - pub struct EverythingArrayParams< - T1: cornucopia_sync::ArraySql, - T2: cornucopia_sync::ArraySql, - T3: cornucopia_sync::ArraySql, - T4: cornucopia_sync::ArraySql, - T5: cornucopia_sync::ArraySql, - T6: cornucopia_sync::ArraySql, - T7: cornucopia_sync::ArraySql, - T8: cornucopia_sync::ArraySql, - T9: cornucopia_sync::ArraySql, - T10: cornucopia_sync::ArraySql, - T11: cornucopia_sync::ArraySql, - T12: cornucopia_sync::ArraySql, - T13: cornucopia_sync::ArraySql, - T14: cornucopia_sync::StringSql, - T15: cornucopia_sync::ArraySql, - T16: cornucopia_sync::StringSql, - T17: cornucopia_sync::ArraySql, - T18: cornucopia_sync::BytesSql, - T19: cornucopia_sync::ArraySql, - T20: cornucopia_sync::ArraySql, - T21: cornucopia_sync::ArraySql, - T22: cornucopia_sync::ArraySql, - T23: cornucopia_sync::ArraySql, - T24: cornucopia_sync::ArraySql, - T25: cornucopia_sync::ArraySql, - T26: cornucopia_sync::JsonSql, - T27: cornucopia_sync::ArraySql, - T28: cornucopia_sync::JsonSql, - T29: cornucopia_sync::ArraySql, - T30: cornucopia_sync::ArraySql, - T31: cornucopia_sync::ArraySql, - T32: cornucopia_sync::ArraySql, - T33: cornucopia_sync::ArraySql, - > { - pub bool_: T1, - pub boolean_: T2, - pub char_: T3, - pub smallint_: T4, - pub int2_: T5, - pub int_: T6, - pub int4_: T7, - pub bingint_: T8, - pub int8_: T9, - pub float4_: T10, - pub real_: T11, - pub float8_: T12, - pub double_precision_: T13, - pub text_: T15, - pub varchar_: T17, - pub bytea_: T19, - pub timestamp_: T20, - pub timestamp_without_time_zone_: T21, - pub timestamptz_: T22, - pub timestamp_with_time_zone_: T23, - pub date_: T24, - pub time_: T25, - pub json_: T27, - pub jsonb_: T29, - pub uuid_: T30, - pub inet_: T31, - pub macaddr_: T32, - pub numeric_: T33, - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Everything { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: String, - pub varchar_: String, - pub bytea_: Vec, - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: serde_json::Value, - pub jsonb_: serde_json::Value, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - pub struct EverythingBorrowed<'a> { - pub bool_: bool, - pub boolean_: bool, - pub char_: i8, - pub smallint_: i16, - pub int2_: i16, - pub smallserial_: i16, - pub serial2_: i16, - pub int_: i32, - pub int4_: i32, - pub serial_: i32, - pub serial4_: i32, - pub bingint_: i64, - pub int8_: i64, - pub bigserial_: i64, - pub serial8_: i64, - pub float4_: f32, - pub real_: f32, - pub float8_: f64, - pub double_precision_: f64, - pub text_: &'a str, - pub varchar_: &'a str, - pub bytea_: &'a [u8], - pub timestamp_: time::PrimitiveDateTime, - pub timestamp_without_time_zone_: time::PrimitiveDateTime, - pub timestamptz_: time::OffsetDateTime, - pub timestamp_with_time_zone_: time::OffsetDateTime, - pub date_: time::Date, - pub time_: time::Time, - pub json_: postgres_types::Json<&'a serde_json::value::RawValue>, - pub jsonb_: postgres_types::Json<&'a serde_json::value::RawValue>, - pub uuid_: uuid::Uuid, - pub inet_: std::net::IpAddr, - pub macaddr_: eui48::MacAddress, - pub numeric_: rust_decimal::Decimal, - } - impl<'a> From> for Everything { - fn from( - EverythingBorrowed { - 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_, - }: EverythingBorrowed<'a>, - ) -> Self { - Self { - bool_, - boolean_, - char_, - smallint_, - int2_, - smallserial_, - serial2_, - int_, - int4_, - serial_, - serial4_, - bingint_, - int8_, - bigserial_, - serial8_, - float4_, - real_, - float8_, - double_precision_, - text_: text_.into(), - varchar_: varchar_.into(), - bytea_: bytea_.into(), - timestamp_, - timestamp_without_time_zone_, - timestamptz_, - timestamp_with_time_zone_, - date_, - time_, - json_: serde_json::from_str(json_.0.get()).unwrap(), - jsonb_: serde_json::from_str(jsonb_.0.get()).unwrap(), - uuid_, - inet_, - macaddr_, - numeric_, - } - } - } - 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, - extractor: fn(&postgres::Row) -> EverythingBorrowed, - mapper: fn(EverythingBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingBorrowed) -> R, - ) -> EverythingQuery<'a, C, R, N> { - EverythingQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingNull { - pub bool_: Option, - pub boolean_: Option, - pub char_: Option, - pub smallint_: Option, - pub int2_: Option, - pub smallserial_: Option, - pub serial2_: Option, - pub int_: Option, - pub int4_: Option, - pub serial_: Option, - pub serial4_: Option, - pub bingint_: Option, - pub int8_: Option, - pub bigserial_: Option, - pub serial8_: Option, - pub float4_: Option, - pub real_: Option, - pub float8_: Option, - pub double_precision_: Option, - pub text_: Option, - pub varchar_: Option, - pub bytea_: Option>, - pub timestamp_: Option, - pub timestamp_without_time_zone_: Option, - pub timestamptz_: Option, - pub timestamp_with_time_zone_: Option, - pub date_: Option, - pub time_: Option, - pub json_: Option, - pub jsonb_: Option, - pub uuid_: Option, - pub inet_: Option, - pub macaddr_: Option, - pub numeric_: Option, - } - pub struct EverythingNullBorrowed<'a> { - pub bool_: Option, - pub boolean_: Option, - pub char_: Option, - pub smallint_: Option, - pub int2_: Option, - pub smallserial_: Option, - pub serial2_: Option, - pub int_: Option, - pub int4_: Option, - pub serial_: Option, - pub serial4_: Option, - pub bingint_: Option, - pub int8_: Option, - pub bigserial_: Option, - pub serial8_: Option, - pub float4_: Option, - pub real_: Option, - pub float8_: Option, - pub double_precision_: Option, - pub text_: Option<&'a str>, - pub varchar_: Option<&'a str>, - pub bytea_: Option<&'a [u8]>, - pub timestamp_: Option, - pub timestamp_without_time_zone_: Option, - pub timestamptz_: Option, - pub timestamp_with_time_zone_: Option, - pub date_: Option, - pub time_: Option, - pub json_: Option>, - pub jsonb_: Option>, - pub uuid_: Option, - pub inet_: Option, - pub macaddr_: Option, - pub numeric_: Option, - } - impl<'a> From> for EverythingNull { - fn from( - EverythingNullBorrowed { - 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_, - }: EverythingNullBorrowed<'a>, - ) -> Self { - Self { - bool_, - boolean_, - char_, - smallint_, - int2_, - smallserial_, - serial2_, - int_, - int4_, - serial_, - serial4_, - bingint_, - int8_, - bigserial_, - serial8_, - float4_, - real_, - float8_, - double_precision_, - text_: text_.map(|v| v.into()), - varchar_: varchar_.map(|v| v.into()), - bytea_: bytea_.map(|v| v.into()), - timestamp_, - timestamp_without_time_zone_, - timestamptz_, - timestamp_with_time_zone_, - date_, - time_, - json_: json_.map(|v| serde_json::from_str(v.0.get()).unwrap()), - jsonb_: jsonb_.map(|v| serde_json::from_str(v.0.get()).unwrap()), - uuid_, - inet_, - macaddr_, - numeric_, - } - } - } - 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, - extractor: fn(&postgres::Row) -> EverythingNullBorrowed, - mapper: fn(EverythingNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingNullBorrowed) -> R, - ) -> EverythingNullQuery<'a, C, R, N> { - EverythingNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingArray { - pub bool_: Vec, - pub boolean_: Vec, - pub char_: Vec, - pub smallint_: Vec, - pub int2_: Vec, - pub int_: Vec, - pub int4_: Vec, - pub bingint_: Vec, - pub int8_: Vec, - pub float4_: Vec, - pub real_: Vec, - pub float8_: Vec, - pub double_precision_: Vec, - pub text_: Vec, - pub varchar_: Vec, - pub bytea_: Vec>, - pub timestamp_: Vec, - pub timestamp_without_time_zone_: Vec, - pub timestamptz_: Vec, - pub timestamp_with_time_zone_: Vec, - pub date_: Vec, - pub time_: Vec, - pub json_: Vec, - pub jsonb_: Vec, - pub uuid_: Vec, - pub inet_: Vec, - pub macaddr_: Vec, - pub numeric_: Vec, - } - pub struct EverythingArrayBorrowed<'a> { - pub bool_: cornucopia_sync::ArrayIterator<'a, bool>, - pub boolean_: cornucopia_sync::ArrayIterator<'a, bool>, - pub char_: cornucopia_sync::ArrayIterator<'a, i8>, - pub smallint_: cornucopia_sync::ArrayIterator<'a, i16>, - pub int2_: cornucopia_sync::ArrayIterator<'a, i16>, - pub int_: cornucopia_sync::ArrayIterator<'a, i32>, - pub int4_: cornucopia_sync::ArrayIterator<'a, i32>, - pub bingint_: cornucopia_sync::ArrayIterator<'a, i64>, - pub int8_: cornucopia_sync::ArrayIterator<'a, i64>, - pub float4_: cornucopia_sync::ArrayIterator<'a, f32>, - pub real_: cornucopia_sync::ArrayIterator<'a, f32>, - pub float8_: cornucopia_sync::ArrayIterator<'a, f64>, - pub double_precision_: cornucopia_sync::ArrayIterator<'a, f64>, - pub text_: cornucopia_sync::ArrayIterator<'a, &'a str>, - pub varchar_: cornucopia_sync::ArrayIterator<'a, &'a str>, - pub bytea_: cornucopia_sync::ArrayIterator<'a, &'a [u8]>, - pub timestamp_: cornucopia_sync::ArrayIterator<'a, time::PrimitiveDateTime>, - pub timestamp_without_time_zone_: - cornucopia_sync::ArrayIterator<'a, time::PrimitiveDateTime>, - pub timestamptz_: cornucopia_sync::ArrayIterator<'a, time::OffsetDateTime>, - pub timestamp_with_time_zone_: cornucopia_sync::ArrayIterator<'a, time::OffsetDateTime>, - pub date_: cornucopia_sync::ArrayIterator<'a, time::Date>, - pub time_: cornucopia_sync::ArrayIterator<'a, time::Time>, - pub json_: cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - pub jsonb_: cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - pub uuid_: cornucopia_sync::ArrayIterator<'a, uuid::Uuid>, - pub inet_: cornucopia_sync::ArrayIterator<'a, std::net::IpAddr>, - pub macaddr_: cornucopia_sync::ArrayIterator<'a, eui48::MacAddress>, - pub numeric_: cornucopia_sync::ArrayIterator<'a, rust_decimal::Decimal>, - } - impl<'a> From> for EverythingArray { - fn from( - EverythingArrayBorrowed { - 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_, - }: EverythingArrayBorrowed<'a>, - ) -> Self { - Self { - bool_: bool_.map(|v| v).collect(), - boolean_: boolean_.map(|v| v).collect(), - char_: char_.map(|v| v).collect(), - smallint_: smallint_.map(|v| v).collect(), - int2_: int2_.map(|v| v).collect(), - int_: int_.map(|v| v).collect(), - int4_: int4_.map(|v| v).collect(), - bingint_: bingint_.map(|v| v).collect(), - int8_: int8_.map(|v| v).collect(), - float4_: float4_.map(|v| v).collect(), - real_: real_.map(|v| v).collect(), - float8_: float8_.map(|v| v).collect(), - double_precision_: double_precision_.map(|v| v).collect(), - text_: text_.map(|v| v.into()).collect(), - varchar_: varchar_.map(|v| v.into()).collect(), - bytea_: bytea_.map(|v| v.into()).collect(), - timestamp_: timestamp_.map(|v| v).collect(), - timestamp_without_time_zone_: timestamp_without_time_zone_.map(|v| v).collect(), - timestamptz_: timestamptz_.map(|v| v).collect(), - timestamp_with_time_zone_: timestamp_with_time_zone_.map(|v| v).collect(), - date_: date_.map(|v| v).collect(), - time_: time_.map(|v| v).collect(), - json_: json_ - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - jsonb_: jsonb_ - .map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect(), - uuid_: uuid_.map(|v| v).collect(), - inet_: inet_.map(|v| v).collect(), - macaddr_: macaddr_.map(|v| v).collect(), - numeric_: numeric_.map(|v| v).collect(), - } - } - } - 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, - extractor: fn(&postgres::Row) -> EverythingArrayBorrowed, - mapper: fn(EverythingArrayBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingArrayQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingArrayBorrowed) -> R, - ) -> EverythingArrayQuery<'a, C, R, N> { - EverythingArrayQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct EverythingArrayNull { - pub bool_: Option>, - pub boolean_: Option>, - pub char_: Option>, - pub smallint_: Option>, - pub int2_: Option>, - pub int_: Option>, - pub int4_: Option>, - pub bingint_: Option>, - pub int8_: Option>, - pub float4_: Option>, - pub real_: Option>, - pub float8_: Option>, - pub double_precision_: Option>, - pub text_: Option>, - pub varchar_: Option>, - pub bytea_: Option>>, - pub timestamp_: Option>, - pub timestamp_without_time_zone_: Option>, - pub timestamptz_: Option>, - pub timestamp_with_time_zone_: Option>, - pub date_: Option>, - pub time_: Option>, - pub json_: Option>, - pub jsonb_: Option>, - pub uuid_: Option>, - pub inet_: Option>, - pub macaddr_: Option>, - pub numeric_: Option>, - } - pub struct EverythingArrayNullBorrowed<'a> { - pub bool_: Option>, - pub boolean_: Option>, - pub char_: Option>, - pub smallint_: Option>, - pub int2_: Option>, - pub int_: Option>, - pub int4_: Option>, - pub bingint_: Option>, - pub int8_: Option>, - pub float4_: Option>, - pub real_: Option>, - pub float8_: Option>, - pub double_precision_: Option>, - pub text_: Option>, - pub varchar_: Option>, - pub bytea_: Option>, - pub timestamp_: Option>, - pub timestamp_without_time_zone_: - Option>, - pub timestamptz_: Option>, - pub timestamp_with_time_zone_: - Option>, - pub date_: Option>, - pub time_: Option>, - pub json_: Option< - cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - >, - pub jsonb_: Option< - cornucopia_sync::ArrayIterator< - 'a, - postgres_types::Json<&'a serde_json::value::RawValue>, - >, - >, - pub uuid_: Option>, - pub inet_: Option>, - pub macaddr_: Option>, - pub numeric_: Option>, - } - impl<'a> From> for EverythingArrayNull { - fn from( - EverythingArrayNullBorrowed { - 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_, - }: EverythingArrayNullBorrowed<'a>, - ) -> Self { - Self { - bool_: bool_.map(|v| v.map(|v| v).collect()), - boolean_: boolean_.map(|v| v.map(|v| v).collect()), - char_: char_.map(|v| v.map(|v| v).collect()), - smallint_: smallint_.map(|v| v.map(|v| v).collect()), - int2_: int2_.map(|v| v.map(|v| v).collect()), - int_: int_.map(|v| v.map(|v| v).collect()), - int4_: int4_.map(|v| v.map(|v| v).collect()), - bingint_: bingint_.map(|v| v.map(|v| v).collect()), - int8_: int8_.map(|v| v.map(|v| v).collect()), - float4_: float4_.map(|v| v.map(|v| v).collect()), - real_: real_.map(|v| v.map(|v| v).collect()), - float8_: float8_.map(|v| v.map(|v| v).collect()), - double_precision_: double_precision_.map(|v| v.map(|v| v).collect()), - text_: text_.map(|v| v.map(|v| v.into()).collect()), - varchar_: varchar_.map(|v| v.map(|v| v.into()).collect()), - bytea_: bytea_.map(|v| v.map(|v| v.into()).collect()), - timestamp_: timestamp_.map(|v| v.map(|v| v).collect()), - timestamp_without_time_zone_: timestamp_without_time_zone_ - .map(|v| v.map(|v| v).collect()), - timestamptz_: timestamptz_.map(|v| v.map(|v| v).collect()), - timestamp_with_time_zone_: timestamp_with_time_zone_ - .map(|v| v.map(|v| v).collect()), - date_: date_.map(|v| v.map(|v| v).collect()), - time_: time_.map(|v| v.map(|v| v).collect()), - json_: json_.map(|v| { - v.map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect() - }), - jsonb_: jsonb_.map(|v| { - v.map(|v| serde_json::from_str(v.0.get()).unwrap()) - .collect() - }), - uuid_: uuid_.map(|v| v.map(|v| v).collect()), - inet_: inet_.map(|v| v.map(|v| v).collect()), - macaddr_: macaddr_.map(|v| v.map(|v| v).collect()), - numeric_: numeric_.map(|v| v.map(|v| v).collect()), - } - } - } - 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, - extractor: fn(&postgres::Row) -> EverythingArrayNullBorrowed, - mapper: fn(EverythingArrayNullBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> EverythingArrayNullQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(EverythingArrayNullBorrowed) -> R, - ) -> EverythingArrayNullQuery<'a, C, R, N> { - EverythingArrayNullQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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 struct SuperSuperTypesPublicNightmareCompositeQuery< - '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, - extractor: - fn(&postgres::Row) -> super::super::types::public::NightmareCompositeBorrowed, - mapper: fn(super::super::types::public::NightmareCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicNightmareCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::NightmareCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicNightmareCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicNightmareCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> SelectEverythingStmt { - SelectEverythingStmt(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, Everything, 0> { - EverythingQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - smallserial_: row.get(5), - serial2_: row.get(6), - int_: row.get(7), - int4_: row.get(8), - serial_: row.get(9), - serial4_: row.get(10), - bingint_: row.get(11), - int8_: row.get(12), - bigserial_: row.get(13), - serial8_: row.get(14), - float4_: row.get(15), - real_: row.get(16), - float8_: row.get(17), - double_precision_: row.get(18), - text_: row.get(19), - varchar_: row.get(20), - bytea_: row.get(21), - timestamp_: row.get(22), - timestamp_without_time_zone_: row.get(23), - timestamptz_: row.get(24), - timestamp_with_time_zone_: row.get(25), - date_: row.get(26), - time_: row.get(27), - json_: row.get(28), - jsonb_: row.get(29), - uuid_: row.get(30), - inet_: row.get(31), - macaddr_: row.get(32), - numeric_: row.get(33), - }, - mapper: |it| ::from(it), - } - } - } - pub fn select_everything_null() -> SelectEverythingNullStmt { - SelectEverythingNullStmt(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, EverythingNull, 0> { - EverythingNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingNullBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - smallserial_: row.get(5), - serial2_: row.get(6), - int_: row.get(7), - int4_: row.get(8), - serial_: row.get(9), - serial4_: row.get(10), - bingint_: row.get(11), - int8_: row.get(12), - bigserial_: row.get(13), - serial8_: row.get(14), - float4_: row.get(15), - real_: row.get(16), - float8_: row.get(17), - double_precision_: row.get(18), - text_: row.get(19), - varchar_: row.get(20), - bytea_: row.get(21), - timestamp_: row.get(22), - timestamp_without_time_zone_: row.get(23), - timestamptz_: row.get(24), - timestamp_with_time_zone_: row.get(25), - date_: row.get(26), - time_: row.get(27), - json_: row.get(28), - jsonb_: row.get(29), - uuid_: row.get(30), - inet_: row.get(31), - macaddr_: row.get(32), - numeric_: row.get(33), - }, - mapper: |it| ::from(it), - } - } - } - 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_) - 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 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, - client: &'a mut C, - bool_: &'a bool, - boolean_: &'a bool, - char_: &'a i8, - smallint_: &'a i16, - int2_: &'a i16, - smallserial_: &'a i16, - serial2_: &'a i16, - int_: &'a i32, - int4_: &'a i32, - serial_: &'a i32, - serial4_: &'a i32, - bingint_: &'a i64, - int8_: &'a i64, - bigserial_: &'a i64, - serial8_: &'a i64, - float4_: &'a f32, - real_: &'a f32, - float8_: &'a f64, - double_precision_: &'a f64, - text_: &'a T1, - varchar_: &'a T2, - bytea_: &'a T3, - timestamp_: &'a time::PrimitiveDateTime, - timestamp_without_time_zone_: &'a time::PrimitiveDateTime, - timestamptz_: &'a time::OffsetDateTime, - timestamp_with_time_zone_: &'a time::OffsetDateTime, - date_: &'a time::Date, - time_: &'a time::Time, - json_: &'a T4, - jsonb_: &'a T5, - uuid_: &'a uuid::Uuid, - inet_: &'a std::net::IpAddr, - macaddr_: &'a eui48::MacAddress, - numeric_: &'a rust_decimal::Decimal, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( - stmt, - &[ - 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_, - ], - ) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::StringSql, - T2: cornucopia_sync::StringSql, - T3: cornucopia_sync::BytesSql, - T4: cornucopia_sync::JsonSql, - T5: cornucopia_sync::JsonSql, - > - cornucopia_sync::Params< - 'a, - EverythingParams, - Result, - C, - > for InsertEverythingStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a EverythingParams, - ) -> Result { - self.bind( - client, - ¶ms.bool_, - ¶ms.boolean_, - ¶ms.char_, - ¶ms.smallint_, - ¶ms.int2_, - ¶ms.smallserial_, - ¶ms.serial2_, - ¶ms.int_, - ¶ms.int4_, - ¶ms.serial_, - ¶ms.serial4_, - ¶ms.bingint_, - ¶ms.int8_, - ¶ms.bigserial_, - ¶ms.serial8_, - ¶ms.float4_, - ¶ms.real_, - ¶ms.float8_, - ¶ms.double_precision_, - ¶ms.text_, - ¶ms.varchar_, - ¶ms.bytea_, - ¶ms.timestamp_, - ¶ms.timestamp_without_time_zone_, - ¶ms.timestamptz_, - ¶ms.timestamp_with_time_zone_, - ¶ms.date_, - ¶ms.time_, - ¶ms.json_, - ¶ms.jsonb_, - ¶ms.uuid_, - ¶ms.inet_, - ¶ms.macaddr_, - ¶ms.numeric_, - ) - } - } - pub fn select_everything_array() -> SelectEverythingArrayStmt { - SelectEverythingArrayStmt(cornucopia_sync::private::Stmt::new( - "SELECT - * -FROM - EverythingArray", - )) - } - pub struct SelectEverythingArrayStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingArrayStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> EverythingArrayQuery<'a, C, EverythingArray, 0> { - EverythingArrayQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingArrayBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - int_: row.get(5), - int4_: row.get(6), - bingint_: row.get(7), - int8_: row.get(8), - float4_: row.get(9), - real_: row.get(10), - float8_: row.get(11), - double_precision_: row.get(12), - text_: row.get(13), - varchar_: row.get(14), - bytea_: row.get(15), - timestamp_: row.get(16), - timestamp_without_time_zone_: row.get(17), - timestamptz_: row.get(18), - timestamp_with_time_zone_: row.get(19), - date_: row.get(20), - time_: row.get(21), - json_: row.get(22), - jsonb_: row.get(23), - uuid_: row.get(24), - inet_: row.get(25), - macaddr_: row.get(26), - numeric_: row.get(27), - }, - mapper: |it| ::from(it), - } - } - } - pub fn select_everything_array_null() -> SelectEverythingArrayNullStmt { - SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt::new( - "SELECT - * -FROM - EverythingArray", - )) - } - pub struct SelectEverythingArrayNullStmt(cornucopia_sync::private::Stmt); - impl SelectEverythingArrayNullStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> EverythingArrayNullQuery<'a, C, EverythingArrayNull, 0> { - EverythingArrayNullQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| EverythingArrayNullBorrowed { - bool_: row.get(0), - boolean_: row.get(1), - char_: row.get(2), - smallint_: row.get(3), - int2_: row.get(4), - int_: row.get(5), - int4_: row.get(6), - bingint_: row.get(7), - int8_: row.get(8), - float4_: row.get(9), - real_: row.get(10), - float8_: row.get(11), - double_precision_: row.get(12), - text_: row.get(13), - varchar_: row.get(14), - bytea_: row.get(15), - timestamp_: row.get(16), - timestamp_without_time_zone_: row.get(17), - timestamptz_: row.get(18), - timestamp_with_time_zone_: row.get(19), - date_: row.get(20), - time_: row.get(21), - json_: row.get(22), - jsonb_: row.get(23), - uuid_: row.get(24), - inet_: row.get(25), - macaddr_: row.get(26), - numeric_: row.get(27), - }, - mapper: |it| ::from(it), - } - } - } - 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_) - 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 fn bind< - 'a, - C: GenericClient, - T1: cornucopia_sync::ArraySql, - T2: cornucopia_sync::ArraySql, - T3: cornucopia_sync::ArraySql, - T4: cornucopia_sync::ArraySql, - T5: cornucopia_sync::ArraySql, - T6: cornucopia_sync::ArraySql, - T7: cornucopia_sync::ArraySql, - T8: cornucopia_sync::ArraySql, - T9: cornucopia_sync::ArraySql, - T10: cornucopia_sync::ArraySql, - T11: cornucopia_sync::ArraySql, - T12: cornucopia_sync::ArraySql, - T13: cornucopia_sync::ArraySql, - T14: cornucopia_sync::StringSql, - T15: cornucopia_sync::ArraySql, - T16: cornucopia_sync::StringSql, - T17: cornucopia_sync::ArraySql, - T18: cornucopia_sync::BytesSql, - T19: cornucopia_sync::ArraySql, - T20: cornucopia_sync::ArraySql, - T21: cornucopia_sync::ArraySql, - T22: cornucopia_sync::ArraySql, - T23: cornucopia_sync::ArraySql, - T24: cornucopia_sync::ArraySql, - T25: cornucopia_sync::ArraySql, - T26: cornucopia_sync::JsonSql, - T27: cornucopia_sync::ArraySql, - T28: cornucopia_sync::JsonSql, - T29: cornucopia_sync::ArraySql, - T30: cornucopia_sync::ArraySql, - T31: cornucopia_sync::ArraySql, - T32: cornucopia_sync::ArraySql, - T33: cornucopia_sync::ArraySql, - >( - &'a mut self, - client: &'a mut C, - bool_: &'a T1, - boolean_: &'a T2, - char_: &'a T3, - smallint_: &'a T4, - int2_: &'a T5, - int_: &'a T6, - int4_: &'a T7, - bingint_: &'a T8, - int8_: &'a T9, - float4_: &'a T10, - real_: &'a T11, - float8_: &'a T12, - double_precision_: &'a T13, - text_: &'a T15, - varchar_: &'a T17, - bytea_: &'a T19, - timestamp_: &'a T20, - timestamp_without_time_zone_: &'a T21, - timestamptz_: &'a T22, - timestamp_with_time_zone_: &'a T23, - date_: &'a T24, - time_: &'a T25, - json_: &'a T27, - jsonb_: &'a T29, - uuid_: &'a T30, - inet_: &'a T31, - macaddr_: &'a T32, - numeric_: &'a T33, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute( - stmt, - &[ - 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_, - ], - ) - } - } - impl< - 'a, - C: GenericClient, - T1: cornucopia_sync::ArraySql, - T2: cornucopia_sync::ArraySql, - T3: cornucopia_sync::ArraySql, - T4: cornucopia_sync::ArraySql, - T5: cornucopia_sync::ArraySql, - T6: cornucopia_sync::ArraySql, - T7: cornucopia_sync::ArraySql, - T8: cornucopia_sync::ArraySql, - T9: cornucopia_sync::ArraySql, - T10: cornucopia_sync::ArraySql, - T11: cornucopia_sync::ArraySql, - T12: cornucopia_sync::ArraySql, - T13: cornucopia_sync::ArraySql, - T14: cornucopia_sync::StringSql, - T15: cornucopia_sync::ArraySql, - T16: cornucopia_sync::StringSql, - T17: cornucopia_sync::ArraySql, - T18: cornucopia_sync::BytesSql, - T19: cornucopia_sync::ArraySql, - T20: cornucopia_sync::ArraySql, - T21: cornucopia_sync::ArraySql, - T22: cornucopia_sync::ArraySql, - T23: cornucopia_sync::ArraySql, - T24: cornucopia_sync::ArraySql, - T25: cornucopia_sync::ArraySql, - T26: cornucopia_sync::JsonSql, - T27: cornucopia_sync::ArraySql, - T28: cornucopia_sync::JsonSql, - T29: cornucopia_sync::ArraySql, - T30: cornucopia_sync::ArraySql, - T31: cornucopia_sync::ArraySql, - T32: cornucopia_sync::ArraySql, - T33: cornucopia_sync::ArraySql, - > - cornucopia_sync::Params< - 'a, - EverythingArrayParams< - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31, - T32, - T33, - >, - Result, - C, - > for InsertEverythingArrayStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a EverythingArrayParams< - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31, - T32, - T33, - >, - ) -> Result { - self.bind( - client, - ¶ms.bool_, - ¶ms.boolean_, - ¶ms.char_, - ¶ms.smallint_, - ¶ms.int2_, - ¶ms.int_, - ¶ms.int4_, - ¶ms.bingint_, - ¶ms.int8_, - ¶ms.float4_, - ¶ms.real_, - ¶ms.float8_, - ¶ms.double_precision_, - ¶ms.text_, - ¶ms.varchar_, - ¶ms.bytea_, - ¶ms.timestamp_, - ¶ms.timestamp_without_time_zone_, - ¶ms.timestamptz_, - ¶ms.timestamp_with_time_zone_, - ¶ms.date_, - ¶ms.time_, - ¶ms.json_, - ¶ms.jsonb_, - ¶ms.uuid_, - ¶ms.inet_, - ¶ms.macaddr_, - ¶ms.numeric_, - ) - } - } - pub fn select_nightmare() -> SelectNightmareStmt { - SelectNightmareStmt(cornucopia_sync::private::Stmt::new( - "SELECT - * -FROM - nightmare", - )) - } - pub struct SelectNightmareStmt(cornucopia_sync::private::Stmt); - impl SelectNightmareStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SuperSuperTypesPublicNightmareCompositeQuery< - 'a, - C, - super::super::types::public::NightmareComposite, - 0, - > { - SuperSuperTypesPublicNightmareCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it.into(), - } - } - } - pub fn insert_nightmare() -> InsertNightmareStmt { - InsertNightmareStmt(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>( - &'a mut self, - client: &'a mut C, - composite: &'a super::super::types::public::NightmareCompositeParams<'a>, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[composite]) - } - } - } - pub mod syntax { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; - #[derive(Debug)] - pub struct ImplicitCompactParams { - pub name: Option, - pub price: Option, - } - #[derive(Debug)] - pub struct ImplicitSpacedParams { - pub name: Option, - pub price: Option, - } - #[derive(Debug)] - pub struct Params { - pub name: T1, - pub price: f64, - } - #[derive(Debug)] - pub struct ParamsSpace { - pub name: T1, - pub price: f64, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySqlParams { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql1Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql2Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql3Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql4Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql6Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql7Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql8Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql9Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - #[derive(Clone, Copy, Debug)] - pub struct TrickySql10Params { - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - pub struct SuperSuperTypesPublicCloneCompositeQuery<'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, - extractor: fn(&postgres::Row) -> super::super::types::public::CloneCompositeBorrowed, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicCloneCompositeQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map( - self, - mapper: fn(super::super::types::public::CloneCompositeBorrowed) -> R, - ) -> SuperSuperTypesPublicCloneCompositeQuery<'a, C, R, N> { - SuperSuperTypesPublicCloneCompositeQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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 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, - extractor: fn(&postgres::Row) -> Option, - mapper: fn(Option) -> T, - } - impl<'a, C, T: 'a, const N: usize> Optioni32Query<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Option) -> R) -> Optioni32Query<'a, C, R, N> { - Optioni32Query { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct Row { - pub id: i32, - } - 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, - extractor: fn(&postgres::Row) -> Row, - mapper: fn(Row) -> T, - } - impl<'a, C, T: 'a, const N: usize> RowQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(Row) -> R) -> RowQuery<'a, C, R, N> { - RowQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq, Copy)] - pub struct RowSpace { - pub id: i32, - } - 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, - extractor: fn(&postgres::Row) -> RowSpace, - mapper: fn(RowSpace) -> T, - } - impl<'a, C, T: 'a, const N: usize> RowSpaceQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(RowSpace) -> R) -> RowSpaceQuery<'a, C, R, N> { - RowSpaceQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .query_raw(stmt, cornucopia_sync::private::slice_iter(&self.params))? - .iterator() - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))); - Ok(it) - } - } - #[derive(serde::Serialize, Debug, Clone, PartialEq)] - pub struct Typeof { - pub trick_y: String, - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - pub struct TypeofBorrowed<'a> { - pub trick_y: &'a str, - pub r#async: super::super::types::public::SyntaxComposite, - pub r#enum: super::super::types::public::SyntaxEnum, - } - impl<'a> From> for Typeof { - fn from( - TypeofBorrowed { - trick_y, - r#async, - r#enum, - }: TypeofBorrowed<'a>, - ) -> Self { - Self { - trick_y: trick_y.into(), - r#async, - r#enum, - } - } - } - 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, - extractor: fn(&postgres::Row) -> TypeofBorrowed, - mapper: fn(TypeofBorrowed) -> T, - } - impl<'a, C, T: 'a, const N: usize> TypeofQuery<'a, C, T, N> - where - C: GenericClient, - { - pub fn map(self, mapper: fn(TypeofBorrowed) -> R) -> TypeofQuery<'a, C, R, N> { - TypeofQuery { - client: self.client, - params: self.params, - stmt: self.stmt, - 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)?; - 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)?; - Ok(self - .client - .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 it = self - .client - .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() -> SelectCompactStmt { - SelectCompactStmt(cornucopia_sync::private::Stmt::new("SELECT * FROM clone")) - } - pub struct SelectCompactStmt(cornucopia_sync::private::Stmt); - impl SelectCompactStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it.into(), - } - } - } - pub fn select_spaced() -> SelectSpacedStmt { - SelectSpacedStmt(cornucopia_sync::private::Stmt::new( - " SELECT * FROM clone ", - )) - } - pub struct SelectSpacedStmt(cornucopia_sync::private::Stmt); - impl SelectSpacedStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - ) -> SuperSuperTypesPublicCloneCompositeQuery< - 'a, - C, - super::super::types::public::CloneComposite, - 0, - > { - SuperSuperTypesPublicCloneCompositeQuery { - client, - params: [], - stmt: &mut self.0, - 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 struct ImplicitCompactStmt(cornucopia_sync::private::Stmt); - impl ImplicitCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - name: &'a Option, - price: &'a Option, - ) -> Optioni32Query<'a, C, Option, 2> { - Optioni32Query { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params< - 'a, - ImplicitCompactParams, - Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitCompactStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a ImplicitCompactParams, - ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶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 struct ImplicitSpacedStmt(cornucopia_sync::private::Stmt); - impl ImplicitSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - name: &'a Option, - price: &'a Option, - ) -> Optioni32Query<'a, C, Option, 2> { - Optioni32Query { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| row.get(0), - mapper: |it| it, - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params< - 'a, - ImplicitSpacedParams, - Optioni32Query<'a, C, Option, 2>, - C, - > for ImplicitSpacedStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a ImplicitSpacedParams, - ) -> Optioni32Query<'a, C, Option, 2> { - self.bind(client, ¶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 struct NamedCompactStmt(cornucopia_sync::private::Stmt); - impl NamedCompactStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - name: &'a T1, - price: &'a f64, - ) -> RowQuery<'a, C, Row, 2> { - RowQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| Row { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, Params, RowQuery<'a, C, Row, 2>, C> - for NamedCompactStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a Params, - ) -> RowQuery<'a, C, Row, 2> { - self.bind(client, ¶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 struct NamedSpacedStmt(cornucopia_sync::private::Stmt); - impl NamedSpacedStmt { - pub fn bind<'a, C: GenericClient, T1: cornucopia_sync::StringSql>( - &'a mut self, - client: &'a mut C, - name: &'a T1, - price: &'a f64, - ) -> RowSpaceQuery<'a, C, RowSpace, 2> { - RowSpaceQuery { - client, - params: [name, price], - stmt: &mut self.0, - extractor: |row| RowSpace { id: row.get(0) }, - mapper: |it| ::from(it), - } - } - } - impl<'a, C: GenericClient, T1: cornucopia_sync::StringSql> - cornucopia_sync::Params<'a, ParamsSpace, RowSpaceQuery<'a, C, RowSpace, 2>, C> - for NamedSpacedStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a ParamsSpace, - ) -> RowSpaceQuery<'a, C, RowSpace, 2> { - self.bind(client, ¶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 struct TrickySqlStmt(cornucopia_sync::private::Stmt); - impl TrickySqlStmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySqlParams, Result, C> - for TrickySqlStmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySqlParams, - ) -> Result { - self.bind(client, ¶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 struct TrickySql1Stmt(cornucopia_sync::private::Stmt); - impl TrickySql1Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql1Params, Result, C> - for TrickySql1Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql1Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql2Stmt(cornucopia_sync::private::Stmt); - impl TrickySql2Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql2Params, Result, C> - for TrickySql2Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql2Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql3Stmt(cornucopia_sync::private::Stmt); - impl TrickySql3Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql3Params, Result, C> - for TrickySql3Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql3Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql4Stmt(cornucopia_sync::private::Stmt); - impl TrickySql4Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql4Params, Result, C> - for TrickySql4Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql4Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql6Stmt(cornucopia_sync::private::Stmt); - impl TrickySql6Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql6Params, Result, C> - for TrickySql6Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql6Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql7Stmt(cornucopia_sync::private::Stmt); - impl TrickySql7Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql7Params, Result, C> - for TrickySql7Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql7Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql8Stmt(cornucopia_sync::private::Stmt); - impl TrickySql8Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql8Params, Result, C> - for TrickySql8Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql8Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql9Stmt(cornucopia_sync::private::Stmt); - impl TrickySql9Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql9Params, Result, C> - for TrickySql9Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql9Params, - ) -> Result { - self.bind(client, ¶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 struct TrickySql10Stmt(cornucopia_sync::private::Stmt); - impl TrickySql10Stmt { - pub fn bind<'a, C: GenericClient>( - &'a mut self, - client: &'a mut C, - r#async: &'a super::super::types::public::SyntaxComposite, - r#enum: &'a super::super::types::public::SyntaxEnum, - ) -> Result { - let stmt = self.0.prepare(client)?; - client.execute(stmt, &[r#async, r#enum]) - } - } - impl<'a, C: GenericClient> - cornucopia_sync::Params<'a, TrickySql10Params, Result, C> - for TrickySql10Stmt - { - fn params( - &'a mut self, - client: &'a mut C, - params: &'a TrickySql10Params, - ) -> Result { - self.bind(client, ¶ms.r#async, ¶ms.r#enum) - } - } - pub fn r#typeof() -> RTypeofStmt { - RTypeofStmt(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, Typeof, 0> { - TypeofQuery { - client, - params: [], - stmt: &mut self.0, - extractor: |row| TypeofBorrowed { - trick_y: row.get(0), - r#async: row.get(1), - r#enum: row.get(2), - }, - mapper: |it| ::from(it), - } - } - } - } -} diff --git a/codegen_test/src/main.rs b/codegen_test/src/main.rs index a9c98534..8e5d3e5f 100644 --- a/codegen_test/src/main.rs +++ b/codegen_test/src/main.rs @@ -1,5 +1,4 @@ -mod cornucopia_async; -mod cornucopia_sync; +mod cornucopia; use ::cornucopia_async::IterSql; use eui48::MacAddress; @@ -14,27 +13,38 @@ use std::{ use time::{OffsetDateTime, PrimitiveDateTime}; use uuid::Uuid; -use crate::cornucopia_sync::{ +use crate::cornucopia::{ queries::{ - copy::{insert_clone, insert_copy, select_copy}, + copy::sync::{insert_clone, insert_copy, select_copy}, domain::{ - insert_nightmare_domain, select_nightmare_domain, select_nightmare_domain_null, + sync::{ + insert_nightmare_domain, select_nightmare_domain, select_nightmare_domain_null, + }, InsertNightmareDomainParams, SelectNightmareDomain, SelectNightmareDomainNull, }, - named::{ + named::sync::{ named, named_by_id, named_complex, new_named_complex, new_named_hidden, - new_named_visible, Named, NamedComplex, NamedComplexParams, NamedParams, + new_named_visible, }, - nullity::{new_nullity, nullity}, + named::{Named, NamedComplex, NamedComplexParams, NamedParams}, + nullity::sync::{new_nullity, nullity}, nullity::{Nullity, NullityParams}, - params::insert_book, - params::{find_books, params_use_twice, select_book, SelectBook}, + params::sync::insert_book, + params::{ + sync::{find_books, params_use_twice, select_book}, + SelectBook, + }, stress::{ - insert_everything, insert_everything_array, insert_nightmare, select_everything, - select_everything_array, select_nightmare, Everything, EverythingArray, - EverythingArrayParams, EverythingParams, + sync::{ + insert_everything, insert_everything_array, insert_nightmare, select_everything, + select_everything_array, select_nightmare, + }, + Everything, EverythingArray, EverythingArrayParams, EverythingParams, + }, + syntax::{ + sync::{r#typeof, tricky_sql10}, + TrickySql10Params, }, - syntax::{r#typeof, tricky_sql10, TrickySql10Params}, }, types::public::{ CloneCompositeBorrowed, CopyComposite, CustomComposite, CustomCompositeBorrowed, @@ -44,7 +54,7 @@ use crate::cornucopia_sync::{ SyntaxComposite, SyntaxEnum, }, }; -use ::cornucopia_sync::Params; +use cornucopia_sync::Params; pub fn main() { let client = &mut Config::new() diff --git a/cornucopia/src/cli.rs b/cornucopia/src/cli.rs index 66c5c193..73692260 100644 --- a/cornucopia/src/cli.rs +++ b/cornucopia/src/cli.rs @@ -19,9 +19,12 @@ struct Args { destination: PathBuf, #[clap(subcommand)] action: Action, - /// Generate synchronous rust code. Async otherwise. + /// Generate synchronous rust code #[clap(long)] sync: bool, + /// Generate asynchronous rust code + #[clap(long)] + r#async: bool, /// Derive serde's `Serialize` trait for generated types. #[clap(long)] serialize: bool, @@ -49,21 +52,20 @@ pub fn run() -> Result<(), Error> { destination, action, sync, + r#async, serialize, } = Args::parse(); + let settings = CodegenSettings { + gen_async: r#async || !sync, + gen_sync: sync, + derive_ser: serialize, + }; + match action { Action::Live { url } => { let mut client = conn::from_url(&url)?; - generate_live( - &mut client, - &queries_path, - Some(&destination), - CodegenSettings { - is_async: !sync, - derive_ser: serialize, - }, - )?; + generate_live(&mut client, &queries_path, Some(&destination), settings)?; } Action::Schema { schema_files } => { // Run the generate command. If the command is unsuccessful, cleanup Cornucopia's container @@ -72,10 +74,7 @@ pub fn run() -> Result<(), Error> { &schema_files, Some(destination), podman, - CodegenSettings { - is_async: !sync, - derive_ser: serialize, - }, + settings, ) { container::cleanup(podman).ok(); return Err(e); diff --git a/cornucopia/src/codegen.rs b/cornucopia/src/codegen.rs index c0c88329..af6c4b8a 100644 --- a/cornucopia/src/codegen.rs +++ b/cornucopia/src/codegen.rs @@ -1,5 +1,5 @@ use core::str; -use std::fmt::Write; +use std::fmt::{Display, Write}; use codegen_template::code; use indexmap::IndexMap; @@ -12,9 +12,41 @@ use crate::{ CodegenSettings, }; +pub struct GenCtx { + // Current module depth + pub depth: u8, + // Should use async client and generate async code + pub is_async: bool, + // Should serializable struct + pub gen_derive: bool, +} + +impl GenCtx { + pub fn new(depth: u8, is_async: bool, gen_derive: bool) -> Self { + Self { + depth, + is_async, + gen_derive, + } + } + + pub fn path(&self, depth: u8, name: impl Display) -> String { + let depth = std::iter::repeat("super::").take(depth as usize); + code!($($depth)$name) + } + + pub fn client_name(&self) -> &'static str { + if self.is_async { + "cornucopia_async" + } else { + "cornucopia_sync" + } + } +} + impl PreparedField { - pub fn own_struct(&self) -> String { - let it = self.ty.own_ty(self.is_inner_nullable); + pub fn own_struct(&self, ctx: &GenCtx) -> String { + let it = self.ty.own_ty(self.is_inner_nullable, ctx); if self.is_nullable { format!("Option<{it}>") } else { @@ -22,10 +54,8 @@ impl PreparedField { } } - pub fn param_ergo_ty(&self, is_async: bool, traits: &mut Vec) -> String { - let it = self - .ty - .param_ergo_ty(self.is_inner_nullable, is_async, traits); + pub fn param_ergo_ty(&self, traits: &mut Vec, ctx: &GenCtx) -> String { + let it = self.ty.param_ergo_ty(self.is_inner_nullable, traits, ctx); if self.is_nullable { format!("Option<{it}>") } else { @@ -33,8 +63,8 @@ impl PreparedField { } } - pub fn param_ty(&self, is_async: bool) -> String { - let it = self.ty.param_ty(self.is_inner_nullable, is_async); + pub fn param_ty(&self, ctx: &GenCtx) -> String { + let it = self.ty.param_ty(self.is_inner_nullable, ctx); if self.is_nullable { format!("Option<{it}>") } else { @@ -42,10 +72,8 @@ impl PreparedField { } } - pub fn brw_ty(&self, has_lifetime: bool, is_async: bool) -> String { - let it = self - .ty - .brw_ty(self.is_inner_nullable, has_lifetime, is_async); + pub fn brw_ty(&self, has_lifetime: bool, ctx: &GenCtx) -> String { + let it = self.ty.brw_ty(self.is_inner_nullable, has_lifetime, ctx); if self.is_nullable { format!("Option<{it}>") } else { @@ -66,7 +94,7 @@ impl PreparedField { if call == self.ident.rs { call } else { - format!("{}: {}", self.ident.rs, call) + format!("{}: {call}", self.ident.rs) } } } @@ -156,7 +184,7 @@ fn struct_tosql( name: &str, is_borrow: bool, is_params: bool, - is_async: bool, + ctx: &GenCtx, ) { let (post, lifetime) = if is_borrow { if is_params { @@ -169,10 +197,8 @@ fn struct_tosql( }; let db_fields_ident = fields.iter().map(|p| &p.ident.db); let rs_fields_ident = fields.iter().map(|p| &p.ident.rs); - let write_ty = fields - .iter() - .map(|p| p.ty.sql_wrapped(&p.ident.rs, is_async)); - let accept_ty = fields.iter().map(|p| p.ty.accept_to_sql(is_async)); + let write_ty = fields.iter().map(|p| p.ty.sql_wrapped(&p.ident.rs, ctx)); + let accept_ty = fields.iter().map(|p| p.ty.accept_to_sql(ctx)); let nb_fields = fields.len(); code!(w => @@ -278,15 +304,15 @@ fn composite_fromsql( ); } -fn gen_params_struct(w: &mut impl Write, params: &PreparedItem, settings: CodegenSettings) { +fn gen_params_struct(w: &mut impl Write, params: &PreparedItem, ctx: &GenCtx) { let PreparedItem { name, fields, is_copy, is_named, is_ref, + .. } = params; - let is_async = settings.is_async; if *is_named { let traits = &mut Vec::new(); @@ -294,7 +320,7 @@ fn gen_params_struct(w: &mut impl Write, params: &PreparedItem, settings: Codege let lifetime = if *is_ref { "'a," } else { "" }; let fields_ty = fields .iter() - .map(|p| p.param_ergo_ty(is_async, traits)) + .map(|p| p.param_ergo_ty(traits, ctx)) .collect::>(); let fields_name = fields.iter().map(|p| &p.ident.rs); let traits_idx = (1..=traits.len()).into_iter().map(idx_char); @@ -307,14 +333,7 @@ fn gen_params_struct(w: &mut impl Write, params: &PreparedItem, settings: Codege } } -fn gen_row_structs( - w: &mut impl Write, - row: &PreparedItem, - CodegenSettings { - is_async, - derive_ser, - }: CodegenSettings, -) { +fn gen_row_structs(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { let PreparedItem { name, fields, @@ -325,9 +344,13 @@ fn gen_row_structs( if *is_named { // Generate row struct let fields_name = fields.iter().map(|p| &p.ident.rs); - let fields_ty = fields.iter().map(|p| p.own_struct()); + let fields_ty = fields.iter().map(|p| p.own_struct(ctx)); let copy = if *is_copy { "Copy" } else { "" }; - let ser_str = if derive_ser { "serde::Serialize," } else { "" }; + let ser_str = if ctx.gen_derive { + "serde::Serialize," + } else { + "" + }; code!(w => #[derive($ser_str Debug, Clone, PartialEq,$copy)] pub struct $name { @@ -337,7 +360,7 @@ fn gen_row_structs( if !is_copy { let fields_name = fields.iter().map(|p| &p.ident.rs); - let fields_ty = fields.iter().map(|p| p.brw_ty(true, is_async)); + let fields_ty = fields.iter().map(|p| p.brw_ty(true, ctx)); let from_own_assign = fields.iter().map(|f| f.owning_assign()); code!(w => pub struct ${name}Borrowed<'a> { @@ -353,107 +376,110 @@ fn gen_row_structs( ); }; } - { - // Generate query struct - let borrowed_str = if *is_copy { "" } else { "Borrowed" }; - let (client_mut, fn_async, fn_await, backend, collect, raw_type, raw_pre, raw_post, client) = - if is_async { - ( - "", - "async", - ".await", - "tokio_postgres", - "try_collect().await", - "futures::Stream", - "", - ".into_stream()", - "cornucopia_async", - ) - } else { - ( - "mut", - "", - "", - "postgres", - "collect()", - "Iterator", - ".iterator()", - "", - "cornucopia_sync", - ) - }; +} - let row_struct = if *is_named { - format!("{name}{borrowed_str}") +fn gen_row_query(w: &mut impl Write, row: &PreparedItem, ctx: &GenCtx) { + let PreparedItem { + name, + fields, + is_copy, + is_named, + .. + } = row; + // Generate query struct + let borrowed_str = if *is_copy { "" } else { "Borrowed" }; + let (client_mut, fn_async, fn_await, backend, collect, raw_type, raw_pre, raw_post, client) = + if ctx.is_async { + ( + "", + "async", + ".await", + "tokio_postgres", + "try_collect().await", + "futures::Stream", + "", + ".into_stream()", + "cornucopia_async", + ) } else { - fields[0].brw_ty(false, is_async) + ( + "mut", + "", + "", + "postgres", + "collect()", + "Iterator", + ".iterator()", + "", + "cornucopia_sync", + ) }; - code!(w => - 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, - extractor: fn(&$backend::Row) -> $row_struct, - mapper: fn($row_struct) -> T, - } - impl<'a, C, T:'a, const N: usize> ${name}Query<'a, C, T, N> where C: GenericClient { - pub fn map(self, mapper: fn($row_struct) -> R) -> ${name}Query<'a,C,R,N> { - ${name}Query { - client: self.client, - params: self.params, - stmt: self.stmt, - extractor: self.extractor, - mapper, - } - } + let row_struct = if *is_named { + format!("{}{borrowed_str}", row.path(ctx)) + } else { + fields[0].brw_ty(false, ctx) + }; - 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?; - Ok((self.mapper)((self.extractor)(&row))) + code!(w => + 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, + extractor: fn(&$backend::Row) -> $row_struct, + mapper: fn($row_struct) -> T, + } + impl<'a, C, T:'a, const N: usize> ${name}Query<'a, C, T, N> where C: GenericClient { + pub fn map(self, mapper: fn($row_struct) -> R) -> ${name}Query<'a,C,R,N> { + ${name}Query { + client: self.client, + params: self.params, + stmt: self.stmt, + extractor: self.extractor, + mapper, } + } - pub $fn_async fn all(self) -> Result, $backend::Error> { - self.iter()$fn_await?.$collect - } + 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?; + Ok((self.mapper)((self.extractor)(&row))) + } - pub $fn_async fn opt(self) -> Result, $backend::Error> { - let stmt = self.stmt.prepare(self.client)$fn_await?; - Ok(self - .client - .query_opt(stmt, &self.params) - $fn_await? - .map(|row| (self.mapper)((self.extractor)(&row)))) - } + pub $fn_async fn all(self) -> Result, $backend::Error> { + self.iter()$fn_await?.$collect + } - pub $fn_async fn iter( - self, - ) -> Result> + 'a, $backend::Error> { - let stmt = self.stmt.prepare(self.client)$fn_await?; - let it = self - .client - .query_raw(stmt, $client::private::slice_iter(&self.params)) - $fn_await? - $raw_pre - .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) - $raw_post; - Ok(it) - } - }); - } + pub $fn_async fn opt(self) -> Result, $backend::Error> { + let stmt = self.stmt.prepare(self.client)$fn_await?; + Ok(self + .client + .query_opt(stmt, &self.params) + $fn_await? + .map(|row| (self.mapper)((self.extractor)(&row)))) + } + + pub $fn_async fn iter( + self, + ) -> Result> + 'a, $backend::Error> { + let stmt = self.stmt.prepare(self.client)$fn_await?; + let it = self + .client + .query_raw(stmt, $client::private::slice_iter(&self.params)) + $fn_await? + $raw_pre + .map(move |res| res.map(|row| (self.mapper)((self.extractor)(&row)))) + $raw_post; + Ok(it) + } + }); } pub fn idx_char(idx: usize) -> String { format!("T{idx}") } -fn gen_query_fn( - w: &mut W, - module: &PreparedModule, - query: &PreparedQuery, - CodegenSettings { is_async, .. }: CodegenSettings, -) { +fn gen_query_fn(w: &mut W, module: &PreparedModule, query: &PreparedQuery, ctx: &GenCtx) { let PreparedQuery { ident, row, @@ -461,7 +487,7 @@ fn gen_query_fn( param, } = query; - let (client_mut, fn_async, fn_await, backend, client) = if is_async { + let (client_mut, fn_async, fn_await, backend, client) = if ctx.is_async { ("", "async", ".await", "tokio_postgres", "cornucopia_async") } else { ("mut", "", "", "postgres", "cornucopia_sync") @@ -478,41 +504,44 @@ fn gen_query_fn( let traits = &mut Vec::new(); let params_ty: Vec<_> = order .iter() - .map(|idx| param_field[*idx].param_ergo_ty(is_async, traits)) + .map(|idx| param_field[*idx].param_ergo_ty(traits, ctx)) .collect(); let params_name = order.iter().map(|idx| ¶m_field[*idx].ident.rs); let traits_idx = (1..=traits.len()).into_iter().map(idx_char); let lazy_impl = |w: &mut W| { if let Some((idx, index)) = row { + let item = module.rows.get_index(*idx).unwrap().1; let PreparedItem { name: row_name, fields, is_copy, is_named, .. - } = &module.rows.get_index(*idx).unwrap().1; + } = &item; // Query fn let nb_params = param_field.len(); // TODO find a way to clean this mess #[allow(clippy::type_complexity)] let (row_struct_name, extractor, mapper): (_, Box, _) = if *is_named { + let path = item.path(ctx); ( - row_name.value.clone(), + path.clone(), Box::new(|w: _| { + let path = item.path(ctx); let post = if *is_copy { "" } else { "Borrowed" }; let fields_name = fields.iter().map(|p| &p.ident.rs); let fields_idx = (0..fields.len()).map(|i| index[i]); - code!(w => $row_name$post { + code!(w => $path$post { $($fields_name: row.get($fields_idx),) }) }), - format!("<{row_name}>::from(it)"), + code!(<$path>::from(it)), ) } else { let field = &fields[0]; ( - field.own_struct(), + field.own_struct(ctx), Box::new(|w: _| code!(w => row.get(0))), field.owning_call(Some("it")), ) @@ -532,7 +561,7 @@ fn gen_query_fn( // Execute fn let params_wrap = order.iter().map(|idx| { let p = ¶m_field[*idx]; - p.ty.sql_wrapped(&p.ident.rs, is_async) + 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 { @@ -560,7 +589,7 @@ fn gen_query_fn( // Param impl if let Some(param) = param { if param.is_named { - let param_name = ¶m.name; + let param_path = ¶m.path(ctx); let lifetime = if param.is_copy || !param.is_ref { "" } else { @@ -568,23 +597,22 @@ fn gen_query_fn( }; if let Some((idx, _)) = row { let prepared_row = &module.rows.get_index(*idx).unwrap().1; - let name = prepared_row.name.value.clone(); let query_row_struct = if prepared_row.is_named { - name + prepared_row.path(ctx) } else { - prepared_row.fields[0].own_struct() + prepared_row.fields[0].own_struct(ctx) }; 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_name<$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_name<$lifetime $($traits_idx,)>) -> ${name}Query<'a, C, $query_row_struct, $nb_params> { + 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,)) } } ); } else { - let (send_sync, pre_ty, post_ty_lf, pre, post) = if is_async { + let (send_sync, pre_ty, post_ty_lf, pre, post) = if ctx.is_async { ( "+ Send + Sync", "std::pin::Pin( ("", "Result", "", "self", "") }; code!(w => - impl <'a, C: GenericClient $send_sync, $($traits_idx: $traits,)> $client::Params<'a, $param_name<$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_name<$lifetime $($traits_idx,)>) -> $pre_ty$post_ty_lf { + 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 } } @@ -609,15 +637,7 @@ fn gen_query_fn( /// Generates type definitions for custom user types. This includes domains, composites and enums. /// If the type is not `Copy`, then a Borrowed version will be generated. -fn gen_custom_type( - w: &mut impl Write, - schema: &str, - prepared: &PreparedType, - CodegenSettings { - derive_ser, - is_async, - }: CodegenSettings, -) { +fn gen_custom_type(w: &mut impl Write, schema: &str, prepared: &PreparedType, ctx: &GenCtx) { let PreparedType { struct_name, content, @@ -626,7 +646,11 @@ fn gen_custom_type( name, } = prepared; let copy = if *is_copy { "Copy," } else { "" }; - let ser_str = if derive_ser { "serde::Serialize," } else { "" }; + let ser_str = if ctx.gen_derive { + "serde::Serialize," + } else { + "" + }; match content { PreparedContent::Enum(variants) => { let variants_ident = variants.iter().map(|v| &v.rs); @@ -643,7 +667,7 @@ fn gen_custom_type( let fields_original_name = fields.iter().map(|p| &p.ident.db); let fields_name = fields.iter().map(|p| &p.ident.rs); { - let fields_ty = fields.iter().map(|p| p.own_struct()); + let fields_ty = fields.iter().map(|p| p.own_struct(ctx)); code!(w => #[derive($ser_str Debug,postgres_types::FromSql,$copy Clone, PartialEq)] #[postgres(name = "$name")] @@ -656,10 +680,10 @@ fn gen_custom_type( ); } if *is_copy { - struct_tosql(w, struct_name, fields, name, false, *is_params, is_async); + struct_tosql(w, struct_name, fields, name, false, *is_params, ctx); } else { let fields_owning = fields.iter().map(|p| p.owning_assign()); - let fields_brw = fields.iter().map(|p| p.brw_ty(true, is_async)); + let fields_brw = fields.iter().map(|p| p.brw_ty(true, ctx)); code!(w => #[derive(Debug)] pub struct ${struct_name}Borrowed<'a> { @@ -679,7 +703,7 @@ fn gen_custom_type( ); composite_fromsql(w, struct_name, fields, name, schema); if !is_params { - let fields_ty = fields.iter().map(|p| p.param_ty(is_async)); + let fields_ty = fields.iter().map(|p| p.param_ty(ctx)); let derive = if *is_copy { ",Copy,Clone" } else { "" }; code!(w => #[derive(Debug $derive)] @@ -688,7 +712,7 @@ fn gen_custom_type( } ); } - struct_tosql(w, struct_name, fields, name, true, *is_params, is_async); + struct_tosql(w, struct_name, fields, name, true, *is_params, ctx); } } } @@ -697,13 +721,13 @@ fn gen_custom_type( fn gen_type_modules( w: &mut W, prepared: &IndexMap>, - settings: CodegenSettings, + ctx: &GenCtx, ) { let modules = prepared.iter().map(|(schema, types)| { move |w: &mut W| { let lazy = |w: &mut W| { for ty in types { - gen_custom_type(w, schema, ty, settings) + gen_custom_type(w, schema, ty, ctx) } }; @@ -725,38 +749,80 @@ fn gen_type_modules( } pub(crate) fn generate(preparation: Preparation, settings: CodegenSettings) -> String { - let import = if settings.is_async { - "use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;" - } else { - "use postgres::{{fallible_iterator::FallibleIterator,GenericClient}};" - }; let mut buff = "// This file was generated with `cornucopia`. Do not modify.\n\n".to_string(); let w = &mut buff; // Generate database type - gen_type_modules(w, &preparation.types, settings); + gen_type_modules( + w, + &preparation.types, + &GenCtx::new(1, settings.gen_async, settings.derive_ser), + ); // Generate queries let query_modules = preparation.modules.iter().map(|module| { move |w: &mut String| { let name = &module.info.name; + let ctx = GenCtx::new(2, settings.gen_async, settings.derive_ser); let params_string = module .params .values() - .map(|params| |w: &mut String| gen_params_struct(w, params, settings)); - let rows_string = module + .map(|params| |w: &mut String| gen_params_struct(w, params, &ctx)); + let rows_struct_string = module .rows .values() - .map(|row| |w: &mut String| gen_row_structs(w, row, settings)); - let queries_string = module - .queries - .values() - .map(|query| |w: &mut String| gen_query_fn(w, module, query, settings)); + .map(|row| |w: &mut String| gen_row_structs(w, row, &ctx)); + + let sync_specific = |w: &mut String| { + let gen_specific = |depth: u8, is_async: bool| { + move |w: &mut String| { + let ctx = GenCtx::new(depth, is_async, settings.derive_ser); + let import = if is_async { + "use futures::{StreamExt, TryStreamExt};use futures; use cornucopia_async::GenericClient;" + } else { + "use postgres::{fallible_iterator::FallibleIterator,GenericClient};" + }; + let rows_query_string = module + .rows + .values() + .map(|row| |w: &mut String| gen_row_query(w, row, &ctx)); + let queries_string = module.queries.values().map(|query| { + |w: &mut String| gen_query_fn(w, module, query, &ctx) + }); + code!(w => + $import + $($!rows_query_string) + $($!queries_string) + ) + } + }; + + if settings.gen_async != settings.gen_sync { + if settings.gen_async { + let gen = gen_specific(2, true); + code!(w => $!gen) + } else { + let gen = gen_specific(2, false); + code!(w => $!gen) + } + } else { + let sync = gen_specific(3, false); + let async_ = gen_specific(3, true); + code!(w => + pub mod sync { + $!sync + } + pub mod async_ { + $!async_ + } + ) + + } + }; code!(w => pub mod $name { - $import $($!params_string) - $($!rows_string) - $($!queries_string) + $($!rows_struct_string) + $!sync_specific } ); } diff --git a/cornucopia/src/lib.rs b/cornucopia/src/lib.rs index 1fafda66..b879ee28 100644 --- a/cornucopia/src/lib.rs +++ b/cornucopia/src/lib.rs @@ -33,7 +33,8 @@ pub use load_schema::load_schema; /// Struct containing the settings for code generation. #[derive(Clone, Copy)] pub struct CodegenSettings { - pub is_async: bool, + pub gen_async: bool, + pub gen_sync: bool, pub derive_ser: bool, } diff --git a/cornucopia/src/prepare_queries.rs b/cornucopia/src/prepare_queries.rs index 1717c3fa..9edf6eee 100644 --- a/cornucopia/src/prepare_queries.rs +++ b/cornucopia/src/prepare_queries.rs @@ -6,6 +6,7 @@ use postgres::Client; use postgres_types::{Kind, Type}; use crate::{ + codegen::GenCtx, parser::{Module, NullableIdent, Query, Span, TypeAnnotation}, read_queries::ModuleInfo, type_registrar::CornucopiaType, @@ -87,7 +88,7 @@ impl PreparedField { impl PreparedField { pub fn unwrapped_name(&self) -> String { - self.own_struct() + self.own_struct(&GenCtx::new(0, false, false)) .replace(['<', '>', '_'], "") .to_upper_camel_case() } @@ -112,6 +113,10 @@ impl PreparedItem { fields, } } + + pub fn path(&self, ctx: &GenCtx) -> String { + ctx.path(ctx.depth - 2, &self.name) + } } #[derive(PartialEq, Eq, Debug, Clone)] diff --git a/cornucopia/src/type_registrar.rs b/cornucopia/src/type_registrar.rs index d67e007f..c26b538a 100644 --- a/cornucopia/src/type_registrar.rs +++ b/cornucopia/src/type_registrar.rs @@ -4,7 +4,12 @@ use heck::ToUpperCamelCase; use indexmap::{map::Entry, IndexMap}; use postgres_types::{Kind, Type}; -use crate::{codegen::idx_char, parser::Span, read_queries::ModuleInfo, utils::SchemaKey}; +use crate::{ + codegen::{idx_char, GenCtx}, + parser::Span, + read_queries::ModuleInfo, + utils::SchemaKey, +}; use self::error::Error; @@ -26,7 +31,6 @@ pub(crate) enum CornucopiaType { Custom { pg_ty: Type, struct_name: String, - struct_path: String, is_copy: bool, is_params: bool, }, @@ -69,20 +73,20 @@ impl CornucopiaType { } /// Wrap type to escape domains in parameters - pub(crate) fn sql_wrapped(&self, name: &str, is_async: bool) -> String { - let client_name = if is_async { "async" } else { "sync" }; + pub(crate) fn sql_wrapped(&self, name: &str, ctx: &GenCtx) -> String { + let client_name = ctx.client_name(); match self { CornucopiaType::Domain { inner, .. } => { format!( - "&cornucopia_{client_name}::private::Domain({})", - inner.sql_wrapped(name, is_async) + "&{client_name}::private::Domain({})", + inner.sql_wrapped(name, ctx) ) } CornucopiaType::Array { inner } => match inner.as_ref() { CornucopiaType::Domain { inner, .. } => { format!( - "&cornucopia_{client_name}::private::DomainArray({})", - inner.sql_wrapped(name, is_async) + "&{client_name}::private::DomainArray({})", + inner.sql_wrapped(name, ctx) ) } _ => name.to_string(), @@ -92,21 +96,21 @@ impl CornucopiaType { } /// Wrap type to escape domains when writing to sql - pub(crate) fn accept_to_sql(&self, is_async: bool) -> String { - let client_name = if is_async { "async" } else { "sync" }; + pub(crate) fn accept_to_sql(&self, ctx: &GenCtx) -> String { + let client_name = ctx.client_name(); match self { CornucopiaType::Domain { inner, .. } => format!( - "cornucopia_{client_name}::private::Domain::<{}>", - inner.accept_to_sql(is_async) + "{client_name}::private::Domain::<{}>", + inner.accept_to_sql(ctx) ), CornucopiaType::Array { inner } => match inner.as_ref() { CornucopiaType::Domain { inner, .. } => { - let ty = inner.accept_to_sql(is_async); - format!("cornucopia_{client_name}::private::DomainArray::<{ty}, &[{ty}]>") + let ty = inner.accept_to_sql(ctx); + format!("{client_name}::private::DomainArray::<{ty}, &[{ty}]>") } - _ => self.param_ty(false, is_async), + _ => self.param_ty(false, ctx), }, - _ => self.param_ty(false, is_async), + _ => self.param_ty(false, ctx), } } @@ -152,19 +156,21 @@ impl CornucopiaType { } /// Corresponding owned type - pub(crate) fn own_ty(&self, is_inner_nullable: bool) -> String { + pub(crate) fn own_ty(&self, is_inner_nullable: bool, ctx: &GenCtx) -> String { match self { CornucopiaType::Simple { rust_name, .. } => (*rust_name).to_string(), CornucopiaType::Array { inner, .. } => { - let own_inner = inner.own_ty(false); + let own_inner = inner.own_ty(false, ctx); if is_inner_nullable { format!("Vec>") } else { format!("Vec<{own_inner}>") } } - CornucopiaType::Domain { inner, .. } => inner.own_ty(false), - CornucopiaType::Custom { struct_path, .. } => struct_path.to_string(), + CornucopiaType::Domain { inner, .. } => inner.own_ty(false, ctx), + CornucopiaType::Custom { + struct_name, pg_ty, .. + } => custom_ty_path(pg_ty.schema(), struct_name, ctx), } } @@ -172,54 +178,52 @@ impl CornucopiaType { pub(crate) fn param_ergo_ty( &self, is_inner_nullable: bool, - is_async: bool, traits: &mut Vec, + ctx: &GenCtx, ) -> String { - let client_name = if is_async { "async" } else { "sync" }; + let client_name = ctx.client_name(); match self { CornucopiaType::Simple { pg_ty, .. } => match *pg_ty { Type::BYTEA => { - traits.push(format!("cornucopia_{client_name}::BytesSql")); + traits.push(format!("{client_name}::BytesSql")); idx_char(traits.len()) } Type::TEXT | Type::VARCHAR => { - traits.push(format!("cornucopia_{client_name}::StringSql")); + traits.push(format!("{client_name}::StringSql")); idx_char(traits.len()) } Type::JSON | Type::JSONB => { - traits.push(format!("cornucopia_{client_name}::JsonSql")); + traits.push(format!("{client_name}::JsonSql")); idx_char(traits.len()) } - _ => self.param_ty(is_inner_nullable, is_async), + _ => self.param_ty(is_inner_nullable, ctx), }, CornucopiaType::Array { inner, .. } => { - let inner = inner.param_ergo_ty(is_inner_nullable, is_async, traits); + let inner = inner.param_ergo_ty(is_inner_nullable, traits, ctx); let inner = if is_inner_nullable { format!("Option<{inner}>") } else { inner }; - traits.push(format!( - "cornucopia_{client_name}::ArraySql" - )); + traits.push(format!("{client_name}::ArraySql")); idx_char(traits.len()) } CornucopiaType::Domain { inner, .. } => { - inner.param_ergo_ty(is_inner_nullable, is_async, traits) + inner.param_ergo_ty(is_inner_nullable, traits, ctx) } - CornucopiaType::Custom { .. } => self.param_ty(is_inner_nullable, is_async), + CornucopiaType::Custom { .. } => self.param_ty(is_inner_nullable, ctx), } } /// Corresponding borrowed parameter type - pub(crate) fn param_ty(&self, is_inner_nullable: bool, is_async: bool) -> String { + pub(crate) fn param_ty(&self, is_inner_nullable: bool, ctx: &GenCtx) -> String { match self { CornucopiaType::Simple { pg_ty, .. } => match *pg_ty { Type::JSON | Type::JSONB => "&'a serde_json::value::Value".to_string(), - _ => self.brw_ty(is_inner_nullable, true, is_async), + _ => self.brw_ty(is_inner_nullable, true, ctx), }, CornucopiaType::Array { inner, .. } => { - let inner = inner.param_ty(is_inner_nullable, is_async); + let inner = inner.param_ty(is_inner_nullable, ctx); let inner = if is_inner_nullable { format!("Option<{inner}>") } else { @@ -228,17 +232,19 @@ impl CornucopiaType { // Its more practical for users to use a slice format!("&'a [{inner}]") } - CornucopiaType::Domain { inner, .. } => inner.param_ty(false, is_async), + CornucopiaType::Domain { inner, .. } => inner.param_ty(false, ctx), CornucopiaType::Custom { - struct_path, is_params, is_copy, + pg_ty, + struct_name, .. } => { if !is_copy && !is_params { - format!("{struct_path}Params<'a>") + let path = custom_ty_path(pg_ty.schema(), struct_name, ctx); + format!("{}Params<'a>", path) } else { - self.brw_ty(is_inner_nullable, true, is_async) + self.brw_ty(is_inner_nullable, true, ctx) } } } @@ -250,9 +256,8 @@ impl CornucopiaType { &self, is_inner_nullable: bool, has_lifetime: bool, - is_async: bool, + ctx: &GenCtx, ) -> String { - let client_name = if is_async { "async" } else { "sync" }; let lifetime = if has_lifetime { "'a" } else { "" }; match self { CornucopiaType::Simple { @@ -266,7 +271,7 @@ impl CornucopiaType { _ => (*rust_name).to_string(), }, CornucopiaType::Array { inner, .. } => { - let inner = inner.brw_ty(is_inner_nullable, has_lifetime, is_async); + let inner = inner.brw_ty(is_inner_nullable, has_lifetime, ctx); let inner = if is_inner_nullable { format!("Option<{inner}>") } else { @@ -274,24 +279,40 @@ impl CornucopiaType { }; // Its more practical for users to use a slice let lifetime = if has_lifetime { lifetime } else { "'_" }; - format!("cornucopia_{client_name}::ArrayIterator<{lifetime}, {inner}>") + let client_name = ctx.client_name(); + format!("{client_name}::ArrayIterator<{lifetime}, {inner}>") } - CornucopiaType::Domain { inner, .. } => inner.brw_ty(false, has_lifetime, is_async), + CornucopiaType::Domain { inner, .. } => inner.brw_ty(false, has_lifetime, ctx), CornucopiaType::Custom { - struct_path, is_copy, + pg_ty, + struct_name, .. } => { + let path = custom_ty_path(pg_ty.schema(), struct_name, ctx); if *is_copy { - struct_path.to_string() + path } else { - format!("{struct_path}Borrowed<{lifetime}>") + format!("{}Borrowed<{lifetime}>", path) } } } } } +pub fn custom_ty_path(schema: &str, struct_name: &str, ctx: &GenCtx) -> String { + if ctx.depth == 0 { + format!("{}::{}", schema, struct_name) + } else if ctx.depth == 1 { + format!("super::{}::{}", schema, struct_name) + } else { + ctx.path( + ctx.depth, + format_args!("types::{}::{}", schema, struct_name), + ) + } +} + /// Data structure holding all types known to this particular run of Cornucopia. #[derive(Debug, Clone, Default)] pub(crate) struct TypeRegistrar { @@ -310,7 +331,6 @@ impl TypeRegistrar { let rust_ty_name = ty.name().to_upper_camel_case(); CornucopiaType::Custom { pg_ty: ty.clone(), - struct_path: format!("super::super::types::{}::{}", ty.schema(), rust_ty_name), struct_name: rust_ty_name, is_copy, is_params, diff --git a/examples/basic_async/src/cornucopia.rs b/examples/basic_async/src/cornucopia.rs index b5076ccf..36941dc5 100644 --- a/examples/basic_async/src/cornucopia.rs +++ b/examples/basic_async/src/cornucopia.rs @@ -231,9 +231,6 @@ pub mod queries { } } pub mod module_2 { - use cornucopia_async::GenericClient; - use futures; - use futures::{StreamExt, TryStreamExt}; #[derive(Debug)] pub struct AuthorNameStartingWithParams { pub start_str: T1, @@ -258,6 +255,61 @@ pub mod queries { } } } + #[derive(Debug, Clone, PartialEq)] + pub struct AuthorNameStartingWith { + pub authorid: i32, + pub name: String, + pub bookid: i32, + pub title: String, + } + pub struct AuthorNameStartingWithBorrowed<'a> { + pub authorid: i32, + pub name: &'a str, + pub bookid: i32, + pub title: &'a str, + } + impl<'a> From> for AuthorNameStartingWith { + fn from( + AuthorNameStartingWithBorrowed { + authorid, + name, + bookid, + title, + }: AuthorNameStartingWithBorrowed<'a>, + ) -> Self { + Self { + authorid, + name: name.into(), + bookid, + title: title.into(), + } + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct SelectTranslations { + pub title: String, + pub translations: Vec, + } + pub struct SelectTranslationsBorrowed<'a> { + pub title: &'a str, + pub translations: cornucopia_async::ArrayIterator<'a, &'a str>, + } + impl<'a> From> for SelectTranslations { + fn from( + SelectTranslationsBorrowed { + title, + translations, + }: SelectTranslationsBorrowed<'a>, + ) -> Self { + Self { + title: title.into(), + translations: translations.map(|v| v.into()).collect(), + } + } + } + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; pub struct AuthorsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -362,36 +414,6 @@ pub mod queries { Ok(it) } } - #[derive(Debug, Clone, PartialEq)] - pub struct AuthorNameStartingWith { - pub authorid: i32, - pub name: String, - pub bookid: i32, - pub title: String, - } - pub struct AuthorNameStartingWithBorrowed<'a> { - pub authorid: i32, - pub name: &'a str, - pub bookid: i32, - pub title: &'a str, - } - impl<'a> From> for AuthorNameStartingWith { - fn from( - AuthorNameStartingWithBorrowed { - authorid, - name, - bookid, - title, - }: AuthorNameStartingWithBorrowed<'a>, - ) -> Self { - Self { - authorid, - name: name.into(), - bookid, - title: title.into(), - } - } - } pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -447,22 +469,22 @@ pub mod queries { Ok(it) } } - pub struct SuperSuperTypesPublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { + 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, extractor: fn(&tokio_postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicVoiceactorQuery<'a, C, T, N> + impl<'a, C, T: 'a, const N: usize> PublicVoiceactorQuery<'a, C, T, N> where C: GenericClient, { pub fn map( self, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> R, - ) -> SuperSuperTypesPublicVoiceactorQuery<'a, C, R, N> { - SuperSuperTypesPublicVoiceactorQuery { + ) -> PublicVoiceactorQuery<'a, C, R, N> { + PublicVoiceactorQuery { client: self.client, params: self.params, stmt: self.stmt, @@ -502,28 +524,6 @@ pub mod queries { Ok(it) } } - #[derive(Debug, Clone, PartialEq)] - pub struct SelectTranslations { - pub title: String, - pub translations: Vec, - } - pub struct SelectTranslationsBorrowed<'a> { - pub title: &'a str, - pub translations: cornucopia_async::ArrayIterator<'a, &'a str>, - } - impl<'a> From> for SelectTranslations { - fn from( - SelectTranslationsBorrowed { - title, - translations, - }: SelectTranslationsBorrowed<'a>, - ) -> Self { - Self { - title: title.into(), - translations: translations.map(|v| v.into()).collect(), - } - } - } pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -723,13 +723,9 @@ WHERE &'a mut self, client: &'a C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, - ) -> SuperSuperTypesPublicVoiceactorQuery< - 'a, - C, - super::super::types::public::Voiceactor, - 1, - > { - SuperSuperTypesPublicVoiceactorQuery { + ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> + { + PublicVoiceactorQuery { client, params: [spongebob_character], stmt: &mut self.0, diff --git a/examples/basic_sync/src/cornucopia.rs b/examples/basic_sync/src/cornucopia.rs index 7771ae58..55e9cea0 100644 --- a/examples/basic_sync/src/cornucopia.rs +++ b/examples/basic_sync/src/cornucopia.rs @@ -229,7 +229,6 @@ pub mod queries { } } pub mod module_2 { - use postgres::{fallible_iterator::FallibleIterator, GenericClient}; #[derive(Debug)] pub struct AuthorNameStartingWithParams { pub start_str: T1, @@ -254,6 +253,59 @@ pub mod queries { } } } + #[derive(Debug, Clone, PartialEq)] + pub struct AuthorNameStartingWith { + pub authorid: i32, + pub name: String, + pub bookid: i32, + pub title: String, + } + pub struct AuthorNameStartingWithBorrowed<'a> { + pub authorid: i32, + pub name: &'a str, + pub bookid: i32, + pub title: &'a str, + } + impl<'a> From> for AuthorNameStartingWith { + fn from( + AuthorNameStartingWithBorrowed { + authorid, + name, + bookid, + title, + }: AuthorNameStartingWithBorrowed<'a>, + ) -> Self { + Self { + authorid, + name: name.into(), + bookid, + title: title.into(), + } + } + } + #[derive(Debug, Clone, PartialEq)] + pub struct SelectTranslations { + pub title: String, + pub translations: Vec, + } + pub struct SelectTranslationsBorrowed<'a> { + pub title: &'a str, + pub translations: cornucopia_sync::ArrayIterator<'a, &'a str>, + } + impl<'a> From> for SelectTranslations { + fn from( + SelectTranslationsBorrowed { + title, + translations, + }: SelectTranslationsBorrowed<'a>, + ) -> Self { + Self { + title: title.into(), + translations: translations.map(|v| v.into()).collect(), + } + } + } + use postgres::{fallible_iterator::FallibleIterator, GenericClient}; pub struct AuthorsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -350,36 +402,6 @@ pub mod queries { Ok(it) } } - #[derive(Debug, Clone, PartialEq)] - pub struct AuthorNameStartingWith { - pub authorid: i32, - pub name: String, - pub bookid: i32, - pub title: String, - } - pub struct AuthorNameStartingWithBorrowed<'a> { - pub authorid: i32, - pub name: &'a str, - pub bookid: i32, - pub title: &'a str, - } - impl<'a> From> for AuthorNameStartingWith { - fn from( - AuthorNameStartingWithBorrowed { - authorid, - name, - bookid, - title, - }: AuthorNameStartingWithBorrowed<'a>, - ) -> Self { - Self { - authorid, - name: name.into(), - bookid, - title: title.into(), - } - } - } pub struct AuthorNameStartingWithQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -431,22 +453,22 @@ pub mod queries { Ok(it) } } - pub struct SuperSuperTypesPublicVoiceactorQuery<'a, C: GenericClient, T, const N: usize> { + 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, extractor: fn(&postgres::Row) -> super::super::types::public::VoiceactorBorrowed, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> T, } - impl<'a, C, T: 'a, const N: usize> SuperSuperTypesPublicVoiceactorQuery<'a, C, T, N> + impl<'a, C, T: 'a, const N: usize> PublicVoiceactorQuery<'a, C, T, N> where C: GenericClient, { pub fn map( self, mapper: fn(super::super::types::public::VoiceactorBorrowed) -> R, - ) -> SuperSuperTypesPublicVoiceactorQuery<'a, C, R, N> { - SuperSuperTypesPublicVoiceactorQuery { + ) -> PublicVoiceactorQuery<'a, C, R, N> { + PublicVoiceactorQuery { client: self.client, params: self.params, stmt: self.stmt, @@ -482,28 +504,6 @@ pub mod queries { Ok(it) } } - #[derive(Debug, Clone, PartialEq)] - pub struct SelectTranslations { - pub title: String, - pub translations: Vec, - } - pub struct SelectTranslationsBorrowed<'a> { - pub title: &'a str, - pub translations: cornucopia_sync::ArrayIterator<'a, &'a str>, - } - impl<'a> From> for SelectTranslations { - fn from( - SelectTranslationsBorrowed { - title, - translations, - }: SelectTranslationsBorrowed<'a>, - ) -> Self { - Self { - title: title.into(), - translations: translations.map(|v| v.into()).collect(), - } - } - } pub struct SelectTranslationsQuery<'a, C: GenericClient, T, const N: usize> { client: &'a mut C, params: [&'a (dyn postgres_types::ToSql + Sync); N], @@ -699,13 +699,9 @@ WHERE &'a mut self, client: &'a mut C, spongebob_character: &'a super::super::types::public::SpongeBobCharacter, - ) -> SuperSuperTypesPublicVoiceactorQuery< - 'a, - C, - super::super::types::public::Voiceactor, - 1, - > { - SuperSuperTypesPublicVoiceactorQuery { + ) -> PublicVoiceactorQuery<'a, C, super::super::types::public::Voiceactor, 1> + { + PublicVoiceactorQuery { client, params: [spongebob_character], stmt: &mut self.0, diff --git a/integration/fixtures/codegen/benchmarks.toml b/integration/fixtures/codegen/benchmarks.toml index 36153a21..681476ae 100644 --- a/integration/fixtures/codegen/benchmarks.toml +++ b/integration/fixtures/codegen/benchmarks.toml @@ -1,10 +1,6 @@ [[codegen]] -name = "Sync" +name = "Bench" base_path = "bench/usage/cornucopia_benches" -destination = "generated_sync.rs" +destination = "generated.rs" sync = true - -[[codegen]] -name = "Async" -base_path = "bench/usage/cornucopia_benches" -destination = "generated_async.rs" +async = true \ No newline at end of file diff --git a/integration/fixtures/codegen/codegen_test.toml b/integration/fixtures/codegen/codegen_test.toml index 3867a0e2..88b1c532 100644 --- a/integration/fixtures/codegen/codegen_test.toml +++ b/integration/fixtures/codegen/codegen_test.toml @@ -1,14 +1,8 @@ [[codegen]] -name = "Sync" +name = "Codegen" base_path = "codegen_test" -destination = "src/cornucopia_sync.rs" +destination = "src/cornucopia.rs" derive_ser = true sync = true +async = true run = "codegen_test" - -[[codegen]] -name = "Async" -base_path = "codegen_test" -destination = "src/cornucopia_async.rs" -run = "codegen_test" -derive_ser = true diff --git a/integration/fixtures/codegen/examples.toml b/integration/fixtures/codegen/examples.toml index 1f1d538d..26b8c286 100644 --- a/integration/fixtures/codegen/examples.toml +++ b/integration/fixtures/codegen/examples.toml @@ -2,6 +2,7 @@ name = "Auto build" base_path = "examples/auto_build" run = true +async = true [[codegen]] name = "Basic sync" @@ -13,3 +14,4 @@ run = true name = "Basic async" base_path = "examples/basic_async" run = true +async = true diff --git a/integration/src/main.rs b/integration/src/main.rs index a22bb474..29e19f8b 100644 --- a/integration/src/main.rs +++ b/integration/src/main.rs @@ -49,6 +49,7 @@ struct CodegenTest<'a> { queries: Option<&'a str>, destination: Option<&'a str>, sync: Option, + r#async: Option, derive_ser: Option, run: Option, } @@ -159,7 +160,8 @@ fn run_errors_test( "queries", None, CodegenSettings { - is_async: false, + gen_sync: true, + gen_async: false, derive_ser: false, }, )?; @@ -217,8 +219,14 @@ fn run_codegen_test( let queries_path = codegen_test.queries.unwrap_or("queries"); let schema_path = "schema.sql"; let destination = codegen_test.destination.unwrap_or("src/cornucopia.rs"); - let is_async = !codegen_test.sync.unwrap_or(false); + let gen_sync = codegen_test.sync.unwrap_or(false); + let gen_async = codegen_test.r#async.unwrap_or(false); let derive_ser = codegen_test.derive_ser.unwrap_or(false); + let settings = CodegenSettings { + gen_async, + gen_sync, + derive_ser, + }; // Load schema reset_db(client)?; @@ -228,16 +236,8 @@ fn run_codegen_test( // Otherwise, it is only checked. if apply { // Generate - cornucopia::generate_live( - client, - queries_path, - Some(destination), - CodegenSettings { - is_async, - derive_ser, - }, - ) - .map_err(Error::report)?; + cornucopia::generate_live(client, queries_path, Some(destination), settings) + .map_err(Error::report)?; // Format the generated file Command::new("rustfmt") .args(["--edition", "2021"]) @@ -247,16 +247,8 @@ fn run_codegen_test( // Get currently checked-in generate file let old_codegen = std::fs::read_to_string(destination).unwrap_or_default(); // Generate new file - let new_codegen = cornucopia::generate_live( - client, - queries_path, - None, - CodegenSettings { - is_async, - derive_ser, - }, - ) - .map_err(Error::report)?; + let new_codegen = cornucopia::generate_live(client, queries_path, None, settings) + .map_err(Error::report)?; // Format the generated code string by piping to rustfmt let mut rustfmt = Command::new("rustfmt") .args(["--edition", "2021"])