From c882d1b0fff9f8ab72266e026c0836cbbc3592f3 Mon Sep 17 00:00:00 2001 From: HTGAzureX1212 <39023054+HTGAzureX1212@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:08:04 +0800 Subject: [PATCH 1/3] get creates from schema sql --- database/hartex-database-migrate/src/main.rs | 22 +- database/hartex-database-queries/build.rs | 6 +- .../generated/api_backend.rs | 251 +- .../generated/configuration.rs | 179 +- .../generated/discord_frontend.rs | 2245 ++++++++++++----- database/hartex-database-typedsql/src/lib.rs | 8 +- .../hartex-database-typedsql/src/schema.rs | 21 +- 7 files changed, 1949 insertions(+), 783 deletions(-) diff --git a/database/hartex-database-migrate/src/main.rs b/database/hartex-database-migrate/src/main.rs index 73859ef48..4f2ffaf03 100644 --- a/database/hartex-database-migrate/src/main.rs +++ b/database/hartex-database-migrate/src/main.rs @@ -31,8 +31,8 @@ use std::env; -use miette::IntoDiagnostic; use hartex_log::log; +use miette::IntoDiagnostic; use tokio_postgres::NoTls; mod api_backend { @@ -53,8 +53,9 @@ pub async fn main() -> miette::Result<()> { log::trace!("establishing database connection: Discord Frontend Migrations"); let url = env::var("HARTEX_NIGHTLY_PGSQL_URL").unwrap(); - let (mut client, connection) = - tokio_postgres::connect(&url, NoTls).await.into_diagnostic()?; + let (mut client, connection) = tokio_postgres::connect(&url, NoTls) + .await + .into_diagnostic()?; tokio::spawn(async move { if let Err(error) = connection.await { @@ -63,12 +64,16 @@ pub async fn main() -> miette::Result<()> { }); log::trace!("running migrations: Discord Frontend Migrations"); - discord_frontend::migrations::runner().run_async(&mut client).await.into_diagnostic()?; + discord_frontend::migrations::runner() + .run_async(&mut client) + .await + .into_diagnostic()?; log::trace!("establishing database connection: API Backend Migrations"); let url2 = env::var("API_PGSQL_URL").unwrap(); - let (mut client2, connection2) = - tokio_postgres::connect(&url2, NoTls).await.into_diagnostic()?; + let (mut client2, connection2) = tokio_postgres::connect(&url2, NoTls) + .await + .into_diagnostic()?; tokio::spawn(async move { if let Err(error) = connection2.await { @@ -77,7 +82,10 @@ pub async fn main() -> miette::Result<()> { }); log::trace!("establishing database connection: API Backend Migrations"); - api_backend::migrations::runner().run_async(&mut client2).await.into_diagnostic()?; + api_backend::migrations::runner() + .run_async(&mut client2) + .await + .into_diagnostic()?; Ok(()) } diff --git a/database/hartex-database-queries/build.rs b/database/hartex-database-queries/build.rs index 73c01c6ef..614d8c539 100644 --- a/database/hartex-database-queries/build.rs +++ b/database/hartex-database-queries/build.rs @@ -76,9 +76,5 @@ pub fn main() { ) .unwrap(); - hartex_database_typedsql::generate_queries_with_schemas( - "schemas", - "", - "" - ).unwrap(); + hartex_database_typedsql::generate_queries_with_schemas("schemas", "", "").unwrap(); } diff --git a/database/hartex-database-queries/generated/api_backend.rs b/database/hartex-database-queries/generated/api_backend.rs index a9106ec16..7f1fe9659 100644 --- a/database/hartex-database-queries/generated/api_backend.rs +++ b/database/hartex-database-queries/generated/api_backend.rs @@ -1,96 +1,181 @@ // 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 start_timestamp_select_by_component -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct SelectStartTimestampByComponent -{ pub component : String,pub timestamp : time::OffsetDateTime,}pub struct SelectStartTimestampByComponentBorrowed<'a> { pub component : &'a str,pub timestamp : time::OffsetDateTime,} -impl<'a> From> for SelectStartTimestampByComponent -{ - fn from(SelectStartTimestampByComponentBorrowed { component,timestamp,}: SelectStartTimestampByComponentBorrowed<'a>) -> - Self { Self { component: component.into(),timestamp,} } -}pub struct SelectStartTimestampByComponentQuery<'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) -> SelectStartTimestampByComponentBorrowed, - mapper: fn(SelectStartTimestampByComponentBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(SelectStartTimestampByComponentBorrowed) -> R) -> - SelectStartTimestampByComponentQuery<'a,C,R,N> - { - SelectStartTimestampByComponentQuery +#[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 start_timestamp_select_by_component { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct SelectStartTimestampByComponent { + pub component: String, + pub timestamp: time::OffsetDateTime, + } + pub struct SelectStartTimestampByComponentBorrowed<'a> { + pub component: &'a str, + pub timestamp: time::OffsetDateTime, + } + impl<'a> From> for SelectStartTimestampByComponent { + fn from( + SelectStartTimestampByComponentBorrowed { + component, + timestamp, + }: SelectStartTimestampByComponentBorrowed<'a>, + ) -> Self { + Self { + component: component.into(), + timestamp, + } + } + } + pub struct SelectStartTimestampByComponentQuery<'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) -> SelectStartTimestampByComponentBorrowed, + mapper: fn(SelectStartTimestampByComponentBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> SelectStartTimestampByComponentQuery<'a, C, T, N> + where + C: GenericClient, { - client: self.client, params: self.params, stmt: self.stmt, - extractor: self.extractor, mapper, + pub fn map( + self, + mapper: fn(SelectStartTimestampByComponentBorrowed) -> R, + ) -> SelectStartTimestampByComponentQuery<'a, C, R, N> { + SelectStartTimestampByComponentQuery { + 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 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> + '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_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt -{ SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new("SELECT + pub fn select_start_timestamp_by_component() -> SelectStartTimestampByComponentStmt { + SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"APIBackend\".public.\"StartTimestamps\" WHERE - \"component\" = $1")) } pub struct -SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt); impl SelectStartTimestampByComponentStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -component: &'a T1,) -> SelectStartTimestampByComponentQuery<'a,C, -SelectStartTimestampByComponent, 1> -{ - SelectStartTimestampByComponentQuery - { - client, params: [component,], stmt: &mut self.0, extractor: - |row| { SelectStartTimestampByComponentBorrowed { component: row.get(0),timestamp: row.get(1),} }, mapper: |it| { ::from(it) }, + \"component\" = $1", + )) + } + pub struct SelectStartTimestampByComponentStmt(cornucopia_async::private::Stmt); + impl SelectStartTimestampByComponentStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + component: &'a T1, + ) -> SelectStartTimestampByComponentQuery<'a, C, SelectStartTimestampByComponent, 1> + { + SelectStartTimestampByComponentQuery { + client, + params: [component], + stmt: &mut self.0, + extractor: |row| SelectStartTimestampByComponentBorrowed { + component: row.get(0), + timestamp: row.get(1), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod start_timestamp_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct StartTimestampUpsertParams { pub component: T1,pub timestamp: time::OffsetDateTime,}pub fn start_timestamp_upsert() -> StartTimestampUpsertStmt -{ StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO + pub mod start_timestamp_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct StartTimestampUpsertParams { + pub component: T1, + pub timestamp: time::OffsetDateTime, + } + pub fn start_timestamp_upsert() -> StartTimestampUpsertStmt { + StartTimestampUpsertStmt(cornucopia_async::private::Stmt::new( + "INSERT INTO \"APIBackend\".public.\"StartTimestamps\" (\"component\", \"timestamp\") VALUES ($1, $2) ON CONFLICT (\"component\") DO UPDATE SET - \"timestamp\" = $2")) } pub struct -StartTimestampUpsertStmt(cornucopia_async::private::Stmt); impl StartTimestampUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -component: &'a T1,timestamp: &'a time::OffsetDateTime,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[component,timestamp,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,> -cornucopia_async::Params<'a, StartTimestampUpsertParams, std::pin::Pin> + Send + 'a>>, C> for StartTimestampUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - StartTimestampUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.component,¶ms.timestamp,)) } -}}} \ No newline at end of file + \"timestamp\" = $2", + )) + } + pub struct StartTimestampUpsertStmt(cornucopia_async::private::Stmt); + impl StartTimestampUpsertStmt { + pub async fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + component: &'a T1, + timestamp: &'a time::OffsetDateTime, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client.execute(stmt, &[component, timestamp]).await + } + } + impl<'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + StartTimestampUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for StartTimestampUpsertStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a StartTimestampUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind(client, ¶ms.component, ¶ms.timestamp)) + } + } + } +} diff --git a/database/hartex-database-queries/generated/configuration.rs b/database/hartex-database-queries/generated/configuration.rs index a1b18e3a7..9becf3764 100644 --- a/database/hartex-database-queries/generated/configuration.rs +++ b/database/hartex-database-queries/generated/configuration.rs @@ -1,50 +1,82 @@ // 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 plugin_enabled -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct PluginEnabledParams { pub plugin: T1,pub guild_id: T2,}pub struct BoolQuery<'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) -> bool, - mapper: fn(bool) -> T, -} impl<'a, C, T:'a, const N: usize> BoolQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(bool) -> R) -> - BoolQuery<'a,C,R,N> - { - BoolQuery +#[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 plugin_enabled { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct PluginEnabledParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > { + pub plugin: T1, + pub guild_id: T2, + } + pub struct BoolQuery<'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) -> bool, + mapper: fn(bool) -> T, + } + impl<'a, C, T: 'a, const N: usize> BoolQuery<'a, C, T, N> + where + C: GenericClient, { - client: self.client, params: self.params, stmt: self.stmt, - extractor: self.extractor, mapper, + pub fn map(self, mapper: fn(bool) -> R) -> BoolQuery<'a, C, R, N> { + BoolQuery { + 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 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> + '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 plugin_enabled() -> PluginEnabledStmt -{ PluginEnabledStmt(cornucopia_async::private::Stmt::new("SELECT EXISTS( + pub fn plugin_enabled() -> PluginEnabledStmt { + PluginEnabledStmt(cornucopia_async::private::Stmt::new( + "SELECT EXISTS( SELECT TRUE FROM @@ -52,27 +84,42 @@ GenericClient WHERE \"enabled_plugins\" @> array[ $1 ] AND \"guild_id\" = $2 -)")) } pub struct -PluginEnabledStmt(cornucopia_async::private::Stmt); impl PluginEnabledStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -plugin: &'a T1,guild_id: &'a T2,) -> BoolQuery<'a,C, -bool, 2> -{ - BoolQuery - { - client, params: [plugin,guild_id,], stmt: &mut self.0, extractor: - |row| { row.get(0) }, mapper: |it| { it }, +)", + )) + } + pub struct PluginEnabledStmt(cornucopia_async::private::Stmt); + impl PluginEnabledStmt { + pub fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + plugin: &'a T1, + guild_id: &'a T2, + ) -> BoolQuery<'a, C, bool, 2> { + BoolQuery { + client, + params: [plugin, guild_id], + stmt: &mut self.0, + extractor: |row| row.get(0), + mapper: |it| it, + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql> + cornucopia_async::Params<'a, PluginEnabledParams, BoolQuery<'a, C, bool, 2>, C> + for PluginEnabledStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a PluginEnabledParams, + ) -> BoolQuery<'a, C, bool, 2> { + self.bind(client, ¶ms.plugin, ¶ms.guild_id) + } + } } -} }impl <'a, C: GenericClient,T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,> cornucopia_async::Params<'a, -PluginEnabledParams, BoolQuery<'a, C, -bool, 2>, C> for PluginEnabledStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - PluginEnabledParams) -> BoolQuery<'a, C, - bool, 2> - { self.bind(client, ¶ms.plugin,¶ms.guild_id,) } -}}} \ No newline at end of file +} diff --git a/database/hartex-database-queries/generated/discord_frontend.rs b/database/hartex-database-queries/generated/discord_frontend.rs index a675a22b3..ed4386790 100644 --- a/database/hartex-database-queries/generated/discord_frontend.rs +++ b/database/hartex-database-queries/generated/discord_frontend.rs @@ -1,235 +1,543 @@ // 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 cached_emoji_select_by_guild_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedEmojiSelectByGuildId -{ pub id : String,pub guild_id : String,pub animated : bool,pub name : String,pub managed : bool,}pub struct CachedEmojiSelectByGuildIdBorrowed<'a> { pub id : &'a str,pub guild_id : &'a str,pub animated : bool,pub name : &'a str,pub managed : bool,} -impl<'a> From> for CachedEmojiSelectByGuildId -{ - fn from(CachedEmojiSelectByGuildIdBorrowed { id,guild_id,animated,name,managed,}: CachedEmojiSelectByGuildIdBorrowed<'a>) -> - Self { Self { id: id.into(),guild_id: guild_id.into(),animated,name: name.into(),managed,} } -}pub struct CachedEmojiSelectByGuildIdQuery<'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) -> CachedEmojiSelectByGuildIdBorrowed, - mapper: fn(CachedEmojiSelectByGuildIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedEmojiSelectByGuildIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedEmojiSelectByGuildIdBorrowed) -> R) -> - CachedEmojiSelectByGuildIdQuery<'a,C,R,N> - { - CachedEmojiSelectByGuildIdQuery +#[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 cached_emoji_select_by_guild_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedEmojiSelectByGuildId { + pub id: String, + pub guild_id: String, + pub animated: bool, + pub name: String, + pub managed: bool, + } + pub struct CachedEmojiSelectByGuildIdBorrowed<'a> { + pub id: &'a str, + pub guild_id: &'a str, + pub animated: bool, + pub name: &'a str, + pub managed: bool, + } + impl<'a> From> for CachedEmojiSelectByGuildId { + fn from( + CachedEmojiSelectByGuildIdBorrowed { + id, + guild_id, + animated, + name, + managed, + }: CachedEmojiSelectByGuildIdBorrowed<'a>, + ) -> Self { + Self { + id: id.into(), + guild_id: guild_id.into(), + animated, + name: name.into(), + managed, + } + } + } + pub struct CachedEmojiSelectByGuildIdQuery<'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) -> CachedEmojiSelectByGuildIdBorrowed, + mapper: fn(CachedEmojiSelectByGuildIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedEmojiSelectByGuildIdQuery<'a, C, T, N> + where + C: GenericClient, { - 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> + '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 cached_emoji_select_by_guild_id() -> CachedEmojiSelectByGuildIdStmt -{ CachedEmojiSelectByGuildIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub fn map( + self, + mapper: fn(CachedEmojiSelectByGuildIdBorrowed) -> R, + ) -> CachedEmojiSelectByGuildIdQuery<'a, C, R, N> { + CachedEmojiSelectByGuildIdQuery { + 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 cached_emoji_select_by_guild_id() -> CachedEmojiSelectByGuildIdStmt { + CachedEmojiSelectByGuildIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedEmojis\" WHERE - \"guild_id\" = $1")) } pub struct -CachedEmojiSelectByGuildIdStmt(cornucopia_async::private::Stmt); impl CachedEmojiSelectByGuildIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -guild_id: &'a T1,) -> CachedEmojiSelectByGuildIdQuery<'a,C, -CachedEmojiSelectByGuildId, 1> -{ - CachedEmojiSelectByGuildIdQuery - { - client, params: [guild_id,], stmt: &mut self.0, extractor: - |row| { CachedEmojiSelectByGuildIdBorrowed { id: row.get(0),guild_id: row.get(1),animated: row.get(2),name: row.get(3),managed: row.get(4),} }, mapper: |it| { ::from(it) }, + \"guild_id\" = $1", + )) + } + pub struct CachedEmojiSelectByGuildIdStmt(cornucopia_async::private::Stmt); + impl CachedEmojiSelectByGuildIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + guild_id: &'a T1, + ) -> CachedEmojiSelectByGuildIdQuery<'a, C, CachedEmojiSelectByGuildId, 1> { + CachedEmojiSelectByGuildIdQuery { + client, + params: [guild_id], + stmt: &mut self.0, + extractor: |row| CachedEmojiSelectByGuildIdBorrowed { + id: row.get(0), + guild_id: row.get(1), + animated: row.get(2), + name: row.get(3), + managed: row.get(4), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_emoji_select_by_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedEmojiSelectById -{ pub id : String,pub guild_id : String,pub animated : bool,pub name : String,pub managed : bool,}pub struct CachedEmojiSelectByIdBorrowed<'a> { pub id : &'a str,pub guild_id : &'a str,pub animated : bool,pub name : &'a str,pub managed : bool,} -impl<'a> From> for CachedEmojiSelectById -{ - fn from(CachedEmojiSelectByIdBorrowed { id,guild_id,animated,name,managed,}: CachedEmojiSelectByIdBorrowed<'a>) -> - Self { Self { id: id.into(),guild_id: guild_id.into(),animated,name: name.into(),managed,} } -}pub struct CachedEmojiSelectByIdQuery<'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) -> CachedEmojiSelectByIdBorrowed, - mapper: fn(CachedEmojiSelectByIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedEmojiSelectByIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedEmojiSelectByIdBorrowed) -> R) -> - CachedEmojiSelectByIdQuery<'a,C,R,N> - { - CachedEmojiSelectByIdQuery + pub mod cached_emoji_select_by_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedEmojiSelectById { + pub id: String, + pub guild_id: String, + pub animated: bool, + pub name: String, + pub managed: bool, + } + pub struct CachedEmojiSelectByIdBorrowed<'a> { + pub id: &'a str, + pub guild_id: &'a str, + pub animated: bool, + pub name: &'a str, + pub managed: bool, + } + impl<'a> From> for CachedEmojiSelectById { + fn from( + CachedEmojiSelectByIdBorrowed { + id, + guild_id, + animated, + name, + managed, + }: CachedEmojiSelectByIdBorrowed<'a>, + ) -> Self { + Self { + id: id.into(), + guild_id: guild_id.into(), + animated, + name: name.into(), + managed, + } + } + } + pub struct CachedEmojiSelectByIdQuery<'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) -> CachedEmojiSelectByIdBorrowed, + mapper: fn(CachedEmojiSelectByIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedEmojiSelectByIdQuery<'a, C, T, N> + where + C: GenericClient, { - 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> + '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 cached_emoji_select_by_id() -> CachedEmojiSelectByIdStmt -{ CachedEmojiSelectByIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub fn map( + self, + mapper: fn(CachedEmojiSelectByIdBorrowed) -> R, + ) -> CachedEmojiSelectByIdQuery<'a, C, R, N> { + CachedEmojiSelectByIdQuery { + 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 cached_emoji_select_by_id() -> CachedEmojiSelectByIdStmt { + CachedEmojiSelectByIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedEmojis\" WHERE - \"id\" = $1")) } pub struct -CachedEmojiSelectByIdStmt(cornucopia_async::private::Stmt); impl CachedEmojiSelectByIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -id: &'a T1,) -> CachedEmojiSelectByIdQuery<'a,C, -CachedEmojiSelectById, 1> -{ - CachedEmojiSelectByIdQuery - { - client, params: [id,], stmt: &mut self.0, extractor: - |row| { CachedEmojiSelectByIdBorrowed { id: row.get(0),guild_id: row.get(1),animated: row.get(2),name: row.get(3),managed: row.get(4),} }, mapper: |it| { ::from(it) }, + \"id\" = $1", + )) + } + pub struct CachedEmojiSelectByIdStmt(cornucopia_async::private::Stmt); + impl CachedEmojiSelectByIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + id: &'a T1, + ) -> CachedEmojiSelectByIdQuery<'a, C, CachedEmojiSelectById, 1> { + CachedEmojiSelectByIdQuery { + client, + params: [id], + stmt: &mut self.0, + extractor: |row| CachedEmojiSelectByIdBorrowed { + id: row.get(0), + guild_id: row.get(1), + animated: row.get(2), + name: row.get(3), + managed: row.get(4), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_emoji_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedEmojiUpsertParams { pub animated: bool,pub name: T1,pub id: T2,pub guild_id: T3,pub managed: bool,}pub fn cached_emoji_upsert() -> CachedEmojiUpsertStmt -{ CachedEmojiUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedEmojis\" (\"animated\", \"name\", \"id\", \"guild_id\", \"managed\") + pub mod cached_emoji_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedEmojiUpsertParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + > { + pub animated: bool, + pub name: T1, + pub id: T2, + pub guild_id: T3, + pub managed: bool, + } + pub fn cached_emoji_upsert() -> CachedEmojiUpsertStmt { + CachedEmojiUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedEmojis\" (\"animated\", \"name\", \"id\", \"guild_id\", \"managed\") VALUES ($1, $2, $3, $4, $5) ON CONFLICT (\"id\") DO UPDATE SET \"guild_id\" = $4, \"animated\" = $1, \"name\" = $2, - \"managed\" = $5")) } pub struct -CachedEmojiUpsertStmt(cornucopia_async::private::Stmt); impl CachedEmojiUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,T3: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -animated: &'a bool,name: &'a T1,id: &'a T2,guild_id: &'a T3,managed: &'a bool,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[animated,name,id,guild_id,managed,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,T3: cornucopia_async::StringSql,> -cornucopia_async::Params<'a, CachedEmojiUpsertParams, std::pin::Pin> + Send + 'a>>, C> for CachedEmojiUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedEmojiUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.animated,¶ms.name,¶ms.id,¶ms.guild_id,¶ms.managed,)) } -}}pub mod cached_guild_select_by_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedGuildSelectById -{ pub default_message_notifications : i16,pub explicit_content_filter : i16,pub features : Vec,pub icon : Option,pub id : String,pub large : bool,pub mfa_level : i16,pub name : String,pub owner_id : String,pub premium_subscription_count : Option,pub premium_tier : i16,pub verification_level : i16,}pub struct CachedGuildSelectByIdBorrowed<'a> { pub default_message_notifications : i16,pub explicit_content_filter : i16,pub features : cornucopia_async::ArrayIterator<'a, &'a str>,pub icon : Option<&'a str>,pub id : &'a str,pub large : bool,pub mfa_level : i16,pub name : &'a str,pub owner_id : &'a str,pub premium_subscription_count : Option,pub premium_tier : i16,pub verification_level : i16,} -impl<'a> From> for CachedGuildSelectById -{ - fn from(CachedGuildSelectByIdBorrowed { default_message_notifications,explicit_content_filter,features,icon,id,large,mfa_level,name,owner_id,premium_subscription_count,premium_tier,verification_level,}: CachedGuildSelectByIdBorrowed<'a>) -> - Self { Self { default_message_notifications,explicit_content_filter,features: features.map(|v| v.into()).collect(),icon: icon.map(|v| v.into()),id: id.into(),large,mfa_level,name: name.into(),owner_id: owner_id.into(),premium_subscription_count,premium_tier,verification_level,} } -}pub struct CachedGuildSelectByIdQuery<'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) -> CachedGuildSelectByIdBorrowed, - mapper: fn(CachedGuildSelectByIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedGuildSelectByIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedGuildSelectByIdBorrowed) -> R) -> - CachedGuildSelectByIdQuery<'a,C,R,N> - { - CachedGuildSelectByIdQuery + \"managed\" = $5")) + } + pub struct CachedEmojiUpsertStmt(cornucopia_async::private::Stmt); + impl CachedEmojiUpsertStmt { + pub async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + animated: &'a bool, + name: &'a T1, + id: &'a T2, + guild_id: &'a T3, + managed: &'a bool, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute(stmt, &[animated, name, id, guild_id, managed]) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + CachedEmojiUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for CachedEmojiUpsertStmt { - 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> + '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) + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedEmojiUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind( + client, + ¶ms.animated, + ¶ms.name, + ¶ms.id, + ¶ms.guild_id, + ¶ms.managed, + )) + } + } } -}pub fn cached_guild_select_by_id() -> CachedGuildSelectByIdStmt -{ CachedGuildSelectByIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub mod cached_guild_select_by_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedGuildSelectById { + pub default_message_notifications: i16, + pub explicit_content_filter: i16, + pub features: Vec, + pub icon: Option, + pub id: String, + pub large: bool, + pub mfa_level: i16, + pub name: String, + pub owner_id: String, + pub premium_subscription_count: Option, + pub premium_tier: i16, + pub verification_level: i16, + } + pub struct CachedGuildSelectByIdBorrowed<'a> { + pub default_message_notifications: i16, + pub explicit_content_filter: i16, + pub features: cornucopia_async::ArrayIterator<'a, &'a str>, + pub icon: Option<&'a str>, + pub id: &'a str, + pub large: bool, + pub mfa_level: i16, + pub name: &'a str, + pub owner_id: &'a str, + pub premium_subscription_count: Option, + pub premium_tier: i16, + pub verification_level: i16, + } + impl<'a> From> for CachedGuildSelectById { + fn from( + CachedGuildSelectByIdBorrowed { + default_message_notifications, + explicit_content_filter, + features, + icon, + id, + large, + mfa_level, + name, + owner_id, + premium_subscription_count, + premium_tier, + verification_level, + }: CachedGuildSelectByIdBorrowed<'a>, + ) -> Self { + Self { + default_message_notifications, + explicit_content_filter, + features: features.map(|v| v.into()).collect(), + icon: icon.map(|v| v.into()), + id: id.into(), + large, + mfa_level, + name: name.into(), + owner_id: owner_id.into(), + premium_subscription_count, + premium_tier, + verification_level, + } + } + } + pub struct CachedGuildSelectByIdQuery<'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) -> CachedGuildSelectByIdBorrowed, + mapper: fn(CachedGuildSelectByIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedGuildSelectByIdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(CachedGuildSelectByIdBorrowed) -> R, + ) -> CachedGuildSelectByIdQuery<'a, C, R, N> { + CachedGuildSelectByIdQuery { + 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 cached_guild_select_by_id() -> CachedGuildSelectByIdStmt { + CachedGuildSelectByIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedGuilds\" WHERE - \"id\" = $1")) } pub struct -CachedGuildSelectByIdStmt(cornucopia_async::private::Stmt); impl CachedGuildSelectByIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -id: &'a T1,) -> CachedGuildSelectByIdQuery<'a,C, -CachedGuildSelectById, 1> -{ - CachedGuildSelectByIdQuery - { - client, params: [id,], stmt: &mut self.0, extractor: - |row| { CachedGuildSelectByIdBorrowed { default_message_notifications: row.get(0),explicit_content_filter: row.get(1),features: row.get(2),icon: row.get(3),id: row.get(4),large: row.get(5),mfa_level: row.get(6),name: row.get(7),owner_id: row.get(8),premium_subscription_count: row.get(9),premium_tier: row.get(10),verification_level: row.get(11),} }, mapper: |it| { ::from(it) }, + \"id\" = $1", + )) + } + pub struct CachedGuildSelectByIdStmt(cornucopia_async::private::Stmt); + impl CachedGuildSelectByIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + id: &'a T1, + ) -> CachedGuildSelectByIdQuery<'a, C, CachedGuildSelectById, 1> { + CachedGuildSelectByIdQuery { + client, + params: [id], + stmt: &mut self.0, + extractor: |row| CachedGuildSelectByIdBorrowed { + default_message_notifications: row.get(0), + explicit_content_filter: row.get(1), + features: row.get(2), + icon: row.get(3), + id: row.get(4), + large: row.get(5), + mfa_level: row.get(6), + name: row.get(7), + owner_id: row.get(8), + premium_subscription_count: row.get(9), + premium_tier: row.get(10), + verification_level: row.get(11), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_guild_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedGuildUpsertParams,T3: cornucopia_async::StringSql,T4: cornucopia_async::StringSql,T5: cornucopia_async::StringSql,T6: cornucopia_async::StringSql,> { pub default_message_notifications: i16,pub explicit_content_filter: i16,pub features: T2,pub icon: Option,pub large: bool,pub name: T4,pub owner_id: T5,pub id: T6,pub mfa_level: i16,pub premium_subscription_count: Option,pub premium_tier: i16,pub verification_level: i16,}pub fn cached_guild_upsert() -> CachedGuildUpsertStmt -{ CachedGuildUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO + pub mod cached_guild_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedGuildUpsertParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + T6: cornucopia_async::StringSql, + > { + pub default_message_notifications: i16, + pub explicit_content_filter: i16, + pub features: T2, + pub icon: Option, + pub large: bool, + pub name: T4, + pub owner_id: T5, + pub id: T6, + pub mfa_level: i16, + pub premium_subscription_count: Option, + pub premium_tier: i16, + pub verification_level: i16, + } + pub fn cached_guild_upsert() -> CachedGuildUpsertStmt { + CachedGuildUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedGuilds\" (\"default_message_notifications\", \"explicit_content_filter\", \"features\", \"icon\", \"large\", \"name\", \"owner_id\", \"id\", \"mfa_level\", \"premium_subscription_count\", \"premium_tier\", \"verification_level\") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) ON CONFLICT (\"id\") DO UPDATE @@ -244,345 +552,862 @@ ON CONFLICT (\"id\") DO UPDATE \"owner_id\" = $7, \"premium_subscription_count\" = $10, \"premium_tier\" = $11, - \"verification_level\" = $12")) } pub struct -CachedGuildUpsertStmt(cornucopia_async::private::Stmt); impl CachedGuildUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::ArraySql,T3: -cornucopia_async::StringSql,T4: -cornucopia_async::StringSql,T5: -cornucopia_async::StringSql,T6: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -default_message_notifications: &'a i16,explicit_content_filter: &'a i16,features: &'a T2,icon: &'a Option,large: &'a bool,name: &'a T4,owner_id: &'a T5,id: &'a T6,mfa_level: &'a i16,premium_subscription_count: &'a Option,premium_tier: &'a i16,verification_level: &'a i16,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[default_message_notifications,explicit_content_filter,features,icon,large,name,owner_id,id,mfa_level,premium_subscription_count,premium_tier,verification_level,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,T2: cornucopia_async::ArraySql,T3: cornucopia_async::StringSql,T4: cornucopia_async::StringSql,T5: cornucopia_async::StringSql,T6: cornucopia_async::StringSql,> -cornucopia_async::Params<'a, CachedGuildUpsertParams, std::pin::Pin> + Send + 'a>>, C> for CachedGuildUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedGuildUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.default_message_notifications,¶ms.explicit_content_filter,¶ms.features,¶ms.icon,¶ms.large,¶ms.name,¶ms.owner_id,¶ms.id,¶ms.mfa_level,¶ms.premium_subscription_count,¶ms.premium_tier,¶ms.verification_level,)) } -}}pub mod cached_member_select_by_guild_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedMemberSelectByGuildId -{ pub flags : i64,pub joined_at : Option,pub nick : Option,pub roles : Vec,pub guild_id : String,pub user_id : String,}pub struct CachedMemberSelectByGuildIdBorrowed<'a> { pub flags : i64,pub joined_at : Option,pub nick : Option<&'a str>,pub roles : cornucopia_async::ArrayIterator<'a, &'a str>,pub guild_id : &'a str,pub user_id : &'a str,} -impl<'a> From> for CachedMemberSelectByGuildId -{ - fn from(CachedMemberSelectByGuildIdBorrowed { flags,joined_at,nick,roles,guild_id,user_id,}: CachedMemberSelectByGuildIdBorrowed<'a>) -> - Self { Self { flags,joined_at,nick: nick.map(|v| v.into()),roles: roles.map(|v| v.into()).collect(),guild_id: guild_id.into(),user_id: user_id.into(),} } -}pub struct CachedMemberSelectByGuildIdQuery<'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) -> CachedMemberSelectByGuildIdBorrowed, - mapper: fn(CachedMemberSelectByGuildIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedMemberSelectByGuildIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedMemberSelectByGuildIdBorrowed) -> R) -> - CachedMemberSelectByGuildIdQuery<'a,C,R,N> - { - CachedMemberSelectByGuildIdQuery + \"verification_level\" = $12")) + } + pub struct CachedGuildUpsertStmt(cornucopia_async::private::Stmt); + impl CachedGuildUpsertStmt { + pub async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + T6: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + default_message_notifications: &'a i16, + explicit_content_filter: &'a i16, + features: &'a T2, + icon: &'a Option, + large: &'a bool, + name: &'a T4, + owner_id: &'a T5, + id: &'a T6, + mfa_level: &'a i16, + premium_subscription_count: &'a Option, + premium_tier: &'a i16, + verification_level: &'a i16, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute(stmt, &[ + default_message_notifications, + explicit_content_filter, + features, + icon, + large, + name, + owner_id, + id, + mfa_level, + premium_subscription_count, + premium_tier, + verification_level, + ]) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::ArraySql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + T6: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + CachedGuildUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for CachedGuildUpsertStmt { - 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> + '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) + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedGuildUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind( + client, + ¶ms.default_message_notifications, + ¶ms.explicit_content_filter, + ¶ms.features, + ¶ms.icon, + ¶ms.large, + ¶ms.name, + ¶ms.owner_id, + ¶ms.id, + ¶ms.mfa_level, + ¶ms.premium_subscription_count, + ¶ms.premium_tier, + ¶ms.verification_level, + )) + } + } } -}pub fn cached_member_select_by_guild_id() -> CachedMemberSelectByGuildIdStmt -{ CachedMemberSelectByGuildIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub mod cached_member_select_by_guild_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedMemberSelectByGuildId { + pub flags: i64, + pub joined_at: Option, + pub nick: Option, + pub roles: Vec, + pub guild_id: String, + pub user_id: String, + } + pub struct CachedMemberSelectByGuildIdBorrowed<'a> { + pub flags: i64, + pub joined_at: Option, + pub nick: Option<&'a str>, + pub roles: cornucopia_async::ArrayIterator<'a, &'a str>, + pub guild_id: &'a str, + pub user_id: &'a str, + } + impl<'a> From> for CachedMemberSelectByGuildId { + fn from( + CachedMemberSelectByGuildIdBorrowed { + flags, + joined_at, + nick, + roles, + guild_id, + user_id, + }: CachedMemberSelectByGuildIdBorrowed<'a>, + ) -> Self { + Self { + flags, + joined_at, + nick: nick.map(|v| v.into()), + roles: roles.map(|v| v.into()).collect(), + guild_id: guild_id.into(), + user_id: user_id.into(), + } + } + } + pub struct CachedMemberSelectByGuildIdQuery<'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) -> CachedMemberSelectByGuildIdBorrowed, + mapper: fn(CachedMemberSelectByGuildIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedMemberSelectByGuildIdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(CachedMemberSelectByGuildIdBorrowed) -> R, + ) -> CachedMemberSelectByGuildIdQuery<'a, C, R, N> { + CachedMemberSelectByGuildIdQuery { + 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 cached_member_select_by_guild_id() -> CachedMemberSelectByGuildIdStmt { + CachedMemberSelectByGuildIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedMembers\" WHERE - \"guild_id\" = $1")) } pub struct -CachedMemberSelectByGuildIdStmt(cornucopia_async::private::Stmt); impl CachedMemberSelectByGuildIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -guild_id: &'a T1,) -> CachedMemberSelectByGuildIdQuery<'a,C, -CachedMemberSelectByGuildId, 1> -{ - CachedMemberSelectByGuildIdQuery - { - client, params: [guild_id,], stmt: &mut self.0, extractor: - |row| { CachedMemberSelectByGuildIdBorrowed { flags: row.get(0),joined_at: row.get(1),nick: row.get(2),roles: row.get(3),guild_id: row.get(4),user_id: row.get(5),} }, mapper: |it| { ::from(it) }, + \"guild_id\" = $1", + )) + } + pub struct CachedMemberSelectByGuildIdStmt(cornucopia_async::private::Stmt); + impl CachedMemberSelectByGuildIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + guild_id: &'a T1, + ) -> CachedMemberSelectByGuildIdQuery<'a, C, CachedMemberSelectByGuildId, 1> + { + CachedMemberSelectByGuildIdQuery { + client, + params: [guild_id], + stmt: &mut self.0, + extractor: |row| CachedMemberSelectByGuildIdBorrowed { + flags: row.get(0), + joined_at: row.get(1), + nick: row.get(2), + roles: row.get(3), + guild_id: row.get(4), + user_id: row.get(5), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_member_select_by_user_id_and_guild_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedMemberSelectByUserIdAndGuildIdParams { pub user_id: T1,pub guild_id: T2,}#[derive( Debug, Clone, PartialEq,)] pub struct CachedMemberSelectByUserIdAndGuildId -{ pub flags : i64,pub joined_at : Option,pub nick : Option,pub roles : Vec,pub guild_id : String,pub user_id : String,}pub struct CachedMemberSelectByUserIdAndGuildIdBorrowed<'a> { pub flags : i64,pub joined_at : Option,pub nick : Option<&'a str>,pub roles : cornucopia_async::ArrayIterator<'a, &'a str>,pub guild_id : &'a str,pub user_id : &'a str,} -impl<'a> From> for CachedMemberSelectByUserIdAndGuildId -{ - fn from(CachedMemberSelectByUserIdAndGuildIdBorrowed { flags,joined_at,nick,roles,guild_id,user_id,}: CachedMemberSelectByUserIdAndGuildIdBorrowed<'a>) -> - Self { Self { flags,joined_at,nick: nick.map(|v| v.into()),roles: roles.map(|v| v.into()).collect(),guild_id: guild_id.into(),user_id: user_id.into(),} } -}pub struct CachedMemberSelectByUserIdAndGuildIdQuery<'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) -> CachedMemberSelectByUserIdAndGuildIdBorrowed, - mapper: fn(CachedMemberSelectByUserIdAndGuildIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedMemberSelectByUserIdAndGuildIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedMemberSelectByUserIdAndGuildIdBorrowed) -> R) -> - CachedMemberSelectByUserIdAndGuildIdQuery<'a,C,R,N> - { - CachedMemberSelectByUserIdAndGuildIdQuery + pub mod cached_member_select_by_user_id_and_guild_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedMemberSelectByUserIdAndGuildIdParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > { + pub user_id: T1, + pub guild_id: T2, + } + #[derive(Debug, Clone, PartialEq)] + pub struct CachedMemberSelectByUserIdAndGuildId { + pub flags: i64, + pub joined_at: Option, + pub nick: Option, + pub roles: Vec, + pub guild_id: String, + pub user_id: String, + } + pub struct CachedMemberSelectByUserIdAndGuildIdBorrowed<'a> { + pub flags: i64, + pub joined_at: Option, + pub nick: Option<&'a str>, + pub roles: cornucopia_async::ArrayIterator<'a, &'a str>, + pub guild_id: &'a str, + pub user_id: &'a str, + } + impl<'a> From> + for CachedMemberSelectByUserIdAndGuildId { - 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> + '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 cached_member_select_by_user_id_and_guild_id() -> CachedMemberSelectByUserIdAndGuildIdStmt -{ CachedMemberSelectByUserIdAndGuildIdStmt(cornucopia_async::private::Stmt::new("SELECT + fn from( + CachedMemberSelectByUserIdAndGuildIdBorrowed { + flags, + joined_at, + nick, + roles, + guild_id, + user_id, + }: CachedMemberSelectByUserIdAndGuildIdBorrowed<'a>, + ) -> Self { + Self { + flags, + joined_at, + nick: nick.map(|v| v.into()), + roles: roles.map(|v| v.into()).collect(), + guild_id: guild_id.into(), + user_id: user_id.into(), + } + } + } + pub struct CachedMemberSelectByUserIdAndGuildIdQuery< + '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) -> CachedMemberSelectByUserIdAndGuildIdBorrowed, + mapper: fn(CachedMemberSelectByUserIdAndGuildIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedMemberSelectByUserIdAndGuildIdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(CachedMemberSelectByUserIdAndGuildIdBorrowed) -> R, + ) -> CachedMemberSelectByUserIdAndGuildIdQuery<'a, C, R, N> { + CachedMemberSelectByUserIdAndGuildIdQuery { + 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 cached_member_select_by_user_id_and_guild_id() + -> CachedMemberSelectByUserIdAndGuildIdStmt { + CachedMemberSelectByUserIdAndGuildIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedMembers\" WHERE user_id = $1 AND - guild_id = $2")) } pub struct -CachedMemberSelectByUserIdAndGuildIdStmt(cornucopia_async::private::Stmt); impl CachedMemberSelectByUserIdAndGuildIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -user_id: &'a T1,guild_id: &'a T2,) -> CachedMemberSelectByUserIdAndGuildIdQuery<'a,C, -CachedMemberSelectByUserIdAndGuildId, 2> -{ - CachedMemberSelectByUserIdAndGuildIdQuery - { - client, params: [user_id,guild_id,], stmt: &mut self.0, extractor: - |row| { CachedMemberSelectByUserIdAndGuildIdBorrowed { flags: row.get(0),joined_at: row.get(1),nick: row.get(2),roles: row.get(3),guild_id: row.get(4),user_id: row.get(5),} }, mapper: |it| { ::from(it) }, + guild_id = $2", + )) + } + pub struct CachedMemberSelectByUserIdAndGuildIdStmt(cornucopia_async::private::Stmt); + impl CachedMemberSelectByUserIdAndGuildIdStmt { + pub fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + user_id: &'a T1, + guild_id: &'a T2, + ) -> CachedMemberSelectByUserIdAndGuildIdQuery< + 'a, + C, + CachedMemberSelectByUserIdAndGuildId, + 2, + > { + CachedMemberSelectByUserIdAndGuildIdQuery { + client, + params: [user_id, guild_id], + stmt: &mut self.0, + extractor: |row| CachedMemberSelectByUserIdAndGuildIdBorrowed { + flags: row.get(0), + joined_at: row.get(1), + nick: row.get(2), + roles: row.get(3), + guild_id: row.get(4), + user_id: row.get(5), + }, + mapper: |it| ::from(it), + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + CachedMemberSelectByUserIdAndGuildIdParams, + CachedMemberSelectByUserIdAndGuildIdQuery< + 'a, + C, + CachedMemberSelectByUserIdAndGuildId, + 2, + >, + C, + > for CachedMemberSelectByUserIdAndGuildIdStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedMemberSelectByUserIdAndGuildIdParams, + ) -> CachedMemberSelectByUserIdAndGuildIdQuery< + 'a, + C, + CachedMemberSelectByUserIdAndGuildId, + 2, + > { + self.bind(client, ¶ms.user_id, ¶ms.guild_id) + } + } } -} }impl <'a, C: GenericClient,T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,> cornucopia_async::Params<'a, -CachedMemberSelectByUserIdAndGuildIdParams, CachedMemberSelectByUserIdAndGuildIdQuery<'a, C, -CachedMemberSelectByUserIdAndGuildId, 2>, C> for CachedMemberSelectByUserIdAndGuildIdStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedMemberSelectByUserIdAndGuildIdParams) -> CachedMemberSelectByUserIdAndGuildIdQuery<'a, C, - CachedMemberSelectByUserIdAndGuildId, 2> - { self.bind(client, ¶ms.user_id,¶ms.guild_id,) } -}}pub mod cached_member_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedMemberUpsertParams,> { pub flags: i64,pub joined_at: Option,pub nick: Option,pub user_id: T2,pub guild_id: T3,pub roles: T5,}pub fn cached_member_upsert() -> CachedMemberUpsertStmt -{ CachedMemberUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedMembers\" (\"flags\", \"joined_at\", \"nick\", \"user_id\", \"guild_id\", \"roles\") + pub mod cached_member_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedMemberUpsertParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::ArraySql, + > { + pub flags: i64, + pub joined_at: Option, + pub nick: Option, + pub user_id: T2, + pub guild_id: T3, + pub roles: T5, + } + pub fn cached_member_upsert() -> CachedMemberUpsertStmt { + CachedMemberUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedMembers\" (\"flags\", \"joined_at\", \"nick\", \"user_id\", \"guild_id\", \"roles\") VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (\"user_id\", \"guild_id\") DO UPDATE SET \"flags\" = $1, \"joined_at\" = $2, \"nick\" = $3, - \"roles\" = $6")) } pub struct -CachedMemberUpsertStmt(cornucopia_async::private::Stmt); impl CachedMemberUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,T3: -cornucopia_async::StringSql,T4: -cornucopia_async::StringSql,T5: -cornucopia_async::ArraySql,>(&'a mut self, client: &'a C, -flags: &'a i64,joined_at: &'a Option,nick: &'a Option,user_id: &'a T2,guild_id: &'a T3,roles: &'a T5,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[flags,joined_at,nick,user_id,guild_id,roles,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,T3: cornucopia_async::StringSql,T4: cornucopia_async::StringSql,T5: cornucopia_async::ArraySql,> -cornucopia_async::Params<'a, CachedMemberUpsertParams, std::pin::Pin> + Send + 'a>>, C> for CachedMemberUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedMemberUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.flags,¶ms.joined_at,¶ms.nick,¶ms.user_id,¶ms.guild_id,¶ms.roles,)) } -}}pub mod cached_role_select_by_guild_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedRoleSelectByGuildId -{ pub color : i64,pub flags : i32,pub guild_id : String,pub hoist : bool,pub icon : Option,pub id : String,pub managed : bool,pub mentionable : bool,pub position : i32,}pub struct CachedRoleSelectByGuildIdBorrowed<'a> { pub color : i64,pub flags : i32,pub guild_id : &'a str,pub hoist : bool,pub icon : Option<&'a str>,pub id : &'a str,pub managed : bool,pub mentionable : bool,pub position : i32,} -impl<'a> From> for CachedRoleSelectByGuildId -{ - fn from(CachedRoleSelectByGuildIdBorrowed { color,flags,guild_id,hoist,icon,id,managed,mentionable,position,}: CachedRoleSelectByGuildIdBorrowed<'a>) -> - Self { Self { color,flags,guild_id: guild_id.into(),hoist,icon: icon.map(|v| v.into()),id: id.into(),managed,mentionable,position,} } -}pub struct CachedRoleSelectByGuildIdQuery<'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) -> CachedRoleSelectByGuildIdBorrowed, - mapper: fn(CachedRoleSelectByGuildIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedRoleSelectByGuildIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedRoleSelectByGuildIdBorrowed) -> R) -> - CachedRoleSelectByGuildIdQuery<'a,C,R,N> - { - CachedRoleSelectByGuildIdQuery + \"roles\" = $6")) + } + pub struct CachedMemberUpsertStmt(cornucopia_async::private::Stmt); + impl CachedMemberUpsertStmt { + pub async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::ArraySql, + >( + &'a mut self, + client: &'a C, + flags: &'a i64, + joined_at: &'a Option, + nick: &'a Option, + user_id: &'a T2, + guild_id: &'a T3, + roles: &'a T5, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute(stmt, &[flags, joined_at, nick, user_id, guild_id, roles]) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::ArraySql, + > + cornucopia_async::Params< + 'a, + CachedMemberUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for CachedMemberUpsertStmt { - 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> + '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) + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedMemberUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind( + client, + ¶ms.flags, + ¶ms.joined_at, + ¶ms.nick, + ¶ms.user_id, + ¶ms.guild_id, + ¶ms.roles, + )) + } + } } -}pub fn cached_role_select_by_guild_id() -> CachedRoleSelectByGuildIdStmt -{ CachedRoleSelectByGuildIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub mod cached_role_select_by_guild_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedRoleSelectByGuildId { + pub color: i64, + pub flags: i32, + pub guild_id: String, + pub hoist: bool, + pub icon: Option, + pub id: String, + pub managed: bool, + pub mentionable: bool, + pub position: i32, + } + pub struct CachedRoleSelectByGuildIdBorrowed<'a> { + pub color: i64, + pub flags: i32, + pub guild_id: &'a str, + pub hoist: bool, + pub icon: Option<&'a str>, + pub id: &'a str, + pub managed: bool, + pub mentionable: bool, + pub position: i32, + } + impl<'a> From> for CachedRoleSelectByGuildId { + fn from( + CachedRoleSelectByGuildIdBorrowed { + color, + flags, + guild_id, + hoist, + icon, + id, + managed, + mentionable, + position, + }: CachedRoleSelectByGuildIdBorrowed<'a>, + ) -> Self { + Self { + color, + flags, + guild_id: guild_id.into(), + hoist, + icon: icon.map(|v| v.into()), + id: id.into(), + managed, + mentionable, + position, + } + } + } + pub struct CachedRoleSelectByGuildIdQuery<'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) -> CachedRoleSelectByGuildIdBorrowed, + mapper: fn(CachedRoleSelectByGuildIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedRoleSelectByGuildIdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(CachedRoleSelectByGuildIdBorrowed) -> R, + ) -> CachedRoleSelectByGuildIdQuery<'a, C, R, N> { + CachedRoleSelectByGuildIdQuery { + 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 cached_role_select_by_guild_id() -> CachedRoleSelectByGuildIdStmt { + CachedRoleSelectByGuildIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedRoles\" WHERE - \"guild_id\" = $1")) } pub struct -CachedRoleSelectByGuildIdStmt(cornucopia_async::private::Stmt); impl CachedRoleSelectByGuildIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -guild_id: &'a T1,) -> CachedRoleSelectByGuildIdQuery<'a,C, -CachedRoleSelectByGuildId, 1> -{ - CachedRoleSelectByGuildIdQuery - { - client, params: [guild_id,], stmt: &mut self.0, extractor: - |row| { CachedRoleSelectByGuildIdBorrowed { color: row.get(0),flags: row.get(1),guild_id: row.get(2),hoist: row.get(3),icon: row.get(4),id: row.get(5),managed: row.get(6),mentionable: row.get(7),position: row.get(8),} }, mapper: |it| { ::from(it) }, + \"guild_id\" = $1", + )) + } + pub struct CachedRoleSelectByGuildIdStmt(cornucopia_async::private::Stmt); + impl CachedRoleSelectByGuildIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + guild_id: &'a T1, + ) -> CachedRoleSelectByGuildIdQuery<'a, C, CachedRoleSelectByGuildId, 1> { + CachedRoleSelectByGuildIdQuery { + client, + params: [guild_id], + stmt: &mut self.0, + extractor: |row| CachedRoleSelectByGuildIdBorrowed { + color: row.get(0), + flags: row.get(1), + guild_id: row.get(2), + hoist: row.get(3), + icon: row.get(4), + id: row.get(5), + managed: row.get(6), + mentionable: row.get(7), + position: row.get(8), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_role_select_by_id_and_guild_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedRoleSelectByIdAndGuildIdParams { pub id: T1,pub guild_id: T2,}#[derive( Debug, Clone, PartialEq,)] pub struct CachedRoleSelectByIdAndGuildId -{ pub color : i64,pub flags : i32,pub guild_id : String,pub hoist : bool,pub icon : Option,pub id : String,pub managed : bool,pub mentionable : bool,pub position : i32,}pub struct CachedRoleSelectByIdAndGuildIdBorrowed<'a> { pub color : i64,pub flags : i32,pub guild_id : &'a str,pub hoist : bool,pub icon : Option<&'a str>,pub id : &'a str,pub managed : bool,pub mentionable : bool,pub position : i32,} -impl<'a> From> for CachedRoleSelectByIdAndGuildId -{ - fn from(CachedRoleSelectByIdAndGuildIdBorrowed { color,flags,guild_id,hoist,icon,id,managed,mentionable,position,}: CachedRoleSelectByIdAndGuildIdBorrowed<'a>) -> - Self { Self { color,flags,guild_id: guild_id.into(),hoist,icon: icon.map(|v| v.into()),id: id.into(),managed,mentionable,position,} } -}pub struct CachedRoleSelectByIdAndGuildIdQuery<'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) -> CachedRoleSelectByIdAndGuildIdBorrowed, - mapper: fn(CachedRoleSelectByIdAndGuildIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedRoleSelectByIdAndGuildIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedRoleSelectByIdAndGuildIdBorrowed) -> R) -> - CachedRoleSelectByIdAndGuildIdQuery<'a,C,R,N> - { - CachedRoleSelectByIdAndGuildIdQuery + pub mod cached_role_select_by_id_and_guild_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedRoleSelectByIdAndGuildIdParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + > { + pub id: T1, + pub guild_id: T2, + } + #[derive(Debug, Clone, PartialEq)] + pub struct CachedRoleSelectByIdAndGuildId { + pub color: i64, + pub flags: i32, + pub guild_id: String, + pub hoist: bool, + pub icon: Option, + pub id: String, + pub managed: bool, + pub mentionable: bool, + pub position: i32, + } + pub struct CachedRoleSelectByIdAndGuildIdBorrowed<'a> { + pub color: i64, + pub flags: i32, + pub guild_id: &'a str, + pub hoist: bool, + pub icon: Option<&'a str>, + pub id: &'a str, + pub managed: bool, + pub mentionable: bool, + pub position: i32, + } + impl<'a> From> for CachedRoleSelectByIdAndGuildId { + fn from( + CachedRoleSelectByIdAndGuildIdBorrowed { + color, + flags, + guild_id, + hoist, + icon, + id, + managed, + mentionable, + position, + }: CachedRoleSelectByIdAndGuildIdBorrowed<'a>, + ) -> Self { + Self { + color, + flags, + guild_id: guild_id.into(), + hoist, + icon: icon.map(|v| v.into()), + id: id.into(), + managed, + mentionable, + position, + } + } + } + pub struct CachedRoleSelectByIdAndGuildIdQuery<'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) -> CachedRoleSelectByIdAndGuildIdBorrowed, + mapper: fn(CachedRoleSelectByIdAndGuildIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedRoleSelectByIdAndGuildIdQuery<'a, C, T, N> + where + C: GenericClient, { - 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> + '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 cached_role_select_by_id_and_guild_id() -> CachedRoleSelectByIdAndGuildIdStmt -{ CachedRoleSelectByIdAndGuildIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub fn map( + self, + mapper: fn(CachedRoleSelectByIdAndGuildIdBorrowed) -> R, + ) -> CachedRoleSelectByIdAndGuildIdQuery<'a, C, R, N> { + CachedRoleSelectByIdAndGuildIdQuery { + 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 cached_role_select_by_id_and_guild_id() -> CachedRoleSelectByIdAndGuildIdStmt { + CachedRoleSelectByIdAndGuildIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedRoles\" WHERE \"id\" = $1 AND - \"guild_id\" = $2")) } pub struct -CachedRoleSelectByIdAndGuildIdStmt(cornucopia_async::private::Stmt); impl CachedRoleSelectByIdAndGuildIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -id: &'a T1,guild_id: &'a T2,) -> CachedRoleSelectByIdAndGuildIdQuery<'a,C, -CachedRoleSelectByIdAndGuildId, 2> -{ - CachedRoleSelectByIdAndGuildIdQuery - { - client, params: [id,guild_id,], stmt: &mut self.0, extractor: - |row| { CachedRoleSelectByIdAndGuildIdBorrowed { color: row.get(0),flags: row.get(1),guild_id: row.get(2),hoist: row.get(3),icon: row.get(4),id: row.get(5),managed: row.get(6),mentionable: row.get(7),position: row.get(8),} }, mapper: |it| { ::from(it) }, + \"guild_id\" = $2", + )) + } + pub struct CachedRoleSelectByIdAndGuildIdStmt(cornucopia_async::private::Stmt); + impl CachedRoleSelectByIdAndGuildIdStmt { + pub fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + id: &'a T1, + guild_id: &'a T2, + ) -> CachedRoleSelectByIdAndGuildIdQuery<'a, C, CachedRoleSelectByIdAndGuildId, 2> + { + CachedRoleSelectByIdAndGuildIdQuery { + client, + params: [id, guild_id], + stmt: &mut self.0, + extractor: |row| CachedRoleSelectByIdAndGuildIdBorrowed { + color: row.get(0), + flags: row.get(1), + guild_id: row.get(2), + hoist: row.get(3), + icon: row.get(4), + id: row.get(5), + managed: row.get(6), + mentionable: row.get(7), + position: row.get(8), + }, + mapper: |it| ::from(it), + } + } + } + impl<'a, C: GenericClient, T1: cornucopia_async::StringSql, T2: cornucopia_async::StringSql> + cornucopia_async::Params< + 'a, + CachedRoleSelectByIdAndGuildIdParams, + CachedRoleSelectByIdAndGuildIdQuery<'a, C, CachedRoleSelectByIdAndGuildId, 2>, + C, + > for CachedRoleSelectByIdAndGuildIdStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedRoleSelectByIdAndGuildIdParams, + ) -> CachedRoleSelectByIdAndGuildIdQuery<'a, C, CachedRoleSelectByIdAndGuildId, 2> + { + self.bind(client, ¶ms.id, ¶ms.guild_id) + } + } } -} }impl <'a, C: GenericClient,T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,> cornucopia_async::Params<'a, -CachedRoleSelectByIdAndGuildIdParams, CachedRoleSelectByIdAndGuildIdQuery<'a, C, -CachedRoleSelectByIdAndGuildId, 2>, C> for CachedRoleSelectByIdAndGuildIdStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedRoleSelectByIdAndGuildIdParams) -> CachedRoleSelectByIdAndGuildIdQuery<'a, C, - CachedRoleSelectByIdAndGuildId, 2> - { self.bind(client, ¶ms.id,¶ms.guild_id,) } -}}pub mod cached_role_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedRoleUpsertParams { pub color: i64,pub icon: Option,pub id: T2,pub guild_id: T3,pub flags: i32,pub hoist: bool,pub managed: bool,pub mentionable: bool,pub position: i32,}pub fn cached_role_upsert() -> CachedRoleUpsertStmt -{ CachedRoleUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedRoles\" (\"color\", \"icon\", \"id\", \"guild_id\", \"flags\", \"hoist\", \"managed\", \"mentionable\", \"position\") + pub mod cached_role_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedRoleUpsertParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + > { + pub color: i64, + pub icon: Option, + pub id: T2, + pub guild_id: T3, + pub flags: i32, + pub hoist: bool, + pub managed: bool, + pub mentionable: bool, + pub position: i32, + } + pub fn cached_role_upsert() -> CachedRoleUpsertStmt { + CachedRoleUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedRoles\" (\"color\", \"icon\", \"id\", \"guild_id\", \"flags\", \"hoist\", \"managed\", \"mentionable\", \"position\") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (\"id\", \"guild_id\") DO UPDATE SET @@ -592,94 +1417,239 @@ ON CONFLICT (\"id\", \"guild_id\") DO UPDATE \"hoist\" = $6, \"managed\" = $7, \"mentionable\" = $8, - \"position\" = $9")) } pub struct -CachedRoleUpsertStmt(cornucopia_async::private::Stmt); impl CachedRoleUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,T3: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -color: &'a i64,icon: &'a Option,id: &'a T2,guild_id: &'a T3,flags: &'a i32,hoist: &'a bool,managed: &'a bool,mentionable: &'a bool,position: &'a i32,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[color,icon,id,guild_id,flags,hoist,managed,mentionable,position,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,T3: cornucopia_async::StringSql,> -cornucopia_async::Params<'a, CachedRoleUpsertParams, std::pin::Pin> + Send + 'a>>, C> for CachedRoleUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedRoleUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.color,¶ms.icon,¶ms.id,¶ms.guild_id,¶ms.flags,¶ms.hoist,¶ms.managed,¶ms.mentionable,¶ms.position,)) } -}}pub mod cached_user_select_by_id -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug, Clone, PartialEq,)] pub struct CachedUserSelectById -{ pub avatar : Option,pub bot : bool,pub id : String,pub discriminator : String,pub global_name : Option,pub name : String,}pub struct CachedUserSelectByIdBorrowed<'a> { pub avatar : Option<&'a str>,pub bot : bool,pub id : &'a str,pub discriminator : &'a str,pub global_name : Option<&'a str>,pub name : &'a str,} -impl<'a> From> for CachedUserSelectById -{ - fn from(CachedUserSelectByIdBorrowed { avatar,bot,id,discriminator,global_name,name,}: CachedUserSelectByIdBorrowed<'a>) -> - Self { Self { avatar: avatar.map(|v| v.into()),bot,id: id.into(),discriminator: discriminator.into(),global_name: global_name.map(|v| v.into()),name: name.into(),} } -}pub struct CachedUserSelectByIdQuery<'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) -> CachedUserSelectByIdBorrowed, - mapper: fn(CachedUserSelectByIdBorrowed) -> T, -} impl<'a, C, T:'a, const N: usize> CachedUserSelectByIdQuery<'a, C, T, N> where C: -GenericClient -{ - pub fn map(self, mapper: fn(CachedUserSelectByIdBorrowed) -> R) -> - CachedUserSelectByIdQuery<'a,C,R,N> - { - CachedUserSelectByIdQuery + \"position\" = $9")) + } + pub struct CachedRoleUpsertStmt(cornucopia_async::private::Stmt); + impl CachedRoleUpsertStmt { + pub async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + color: &'a i64, + icon: &'a Option, + id: &'a T2, + guild_id: &'a T3, + flags: &'a i32, + hoist: &'a bool, + managed: &'a bool, + mentionable: &'a bool, + position: &'a i32, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute(stmt, &[ + color, + icon, + id, + guild_id, + flags, + hoist, + managed, + mentionable, + position, + ]) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + CachedRoleUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for CachedRoleUpsertStmt { - 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> + '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) + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedRoleUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind( + client, + ¶ms.color, + ¶ms.icon, + ¶ms.id, + ¶ms.guild_id, + ¶ms.flags, + ¶ms.hoist, + ¶ms.managed, + ¶ms.mentionable, + ¶ms.position, + )) + } + } } -}pub fn cached_user_select_by_id() -> CachedUserSelectByIdStmt -{ CachedUserSelectByIdStmt(cornucopia_async::private::Stmt::new("SELECT + pub mod cached_user_select_by_id { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug, Clone, PartialEq)] + pub struct CachedUserSelectById { + pub avatar: Option, + pub bot: bool, + pub id: String, + pub discriminator: String, + pub global_name: Option, + pub name: String, + } + pub struct CachedUserSelectByIdBorrowed<'a> { + pub avatar: Option<&'a str>, + pub bot: bool, + pub id: &'a str, + pub discriminator: &'a str, + pub global_name: Option<&'a str>, + pub name: &'a str, + } + impl<'a> From> for CachedUserSelectById { + fn from( + CachedUserSelectByIdBorrowed { + avatar, + bot, + id, + discriminator, + global_name, + name, + }: CachedUserSelectByIdBorrowed<'a>, + ) -> Self { + Self { + avatar: avatar.map(|v| v.into()), + bot, + id: id.into(), + discriminator: discriminator.into(), + global_name: global_name.map(|v| v.into()), + name: name.into(), + } + } + } + pub struct CachedUserSelectByIdQuery<'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) -> CachedUserSelectByIdBorrowed, + mapper: fn(CachedUserSelectByIdBorrowed) -> T, + } + impl<'a, C, T: 'a, const N: usize> CachedUserSelectByIdQuery<'a, C, T, N> + where + C: GenericClient, + { + pub fn map( + self, + mapper: fn(CachedUserSelectByIdBorrowed) -> R, + ) -> CachedUserSelectByIdQuery<'a, C, R, N> { + CachedUserSelectByIdQuery { + 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 cached_user_select_by_id() -> CachedUserSelectByIdStmt { + CachedUserSelectByIdStmt(cornucopia_async::private::Stmt::new( + "SELECT * FROM \"DiscordFrontend\".\"Nightly\".\"CachedUsers\" WHERE - \"id\" = $1")) } pub struct -CachedUserSelectByIdStmt(cornucopia_async::private::Stmt); impl CachedUserSelectByIdStmt -{ pub fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -id: &'a T1,) -> CachedUserSelectByIdQuery<'a,C, -CachedUserSelectById, 1> -{ - CachedUserSelectByIdQuery - { - client, params: [id,], stmt: &mut self.0, extractor: - |row| { CachedUserSelectByIdBorrowed { avatar: row.get(0),bot: row.get(1),id: row.get(2),discriminator: row.get(3),global_name: row.get(4),name: row.get(5),} }, mapper: |it| { ::from(it) }, + \"id\" = $1", + )) + } + pub struct CachedUserSelectByIdStmt(cornucopia_async::private::Stmt); + impl CachedUserSelectByIdStmt { + pub fn bind<'a, C: GenericClient, T1: cornucopia_async::StringSql>( + &'a mut self, + client: &'a C, + id: &'a T1, + ) -> CachedUserSelectByIdQuery<'a, C, CachedUserSelectById, 1> { + CachedUserSelectByIdQuery { + client, + params: [id], + stmt: &mut self.0, + extractor: |row| CachedUserSelectByIdBorrowed { + avatar: row.get(0), + bot: row.get(1), + id: row.get(2), + discriminator: row.get(3), + global_name: row.get(4), + name: row.get(5), + }, + mapper: |it| ::from(it), + } + } + } } -} }}pub mod cached_user_upsert -{ use futures::{{StreamExt, TryStreamExt}};use futures; use cornucopia_async::GenericClient;#[derive( Debug)] pub struct CachedUserUpsertParams { pub avatar: Option,pub id: T2,pub bot: bool,pub name: T3,pub discriminator: T4,pub global_name: Option,}pub fn cached_user_upsert() -> CachedUserUpsertStmt -{ CachedUserUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedUsers\" (\"avatar\", \"id\", \"bot\", \"name\", \"discriminator\", \"global_name\") + pub mod cached_user_upsert { + use cornucopia_async::GenericClient; + use futures; + use futures::{StreamExt, TryStreamExt}; + #[derive(Debug)] + pub struct CachedUserUpsertParams< + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + > { + pub avatar: Option, + pub id: T2, + pub bot: bool, + pub name: T3, + pub discriminator: T4, + pub global_name: Option, + } + pub fn cached_user_upsert() -> CachedUserUpsertStmt { + CachedUserUpsertStmt(cornucopia_async::private::Stmt::new("INSERT INTO \"DiscordFrontend\".\"Nightly\".\"CachedUsers\" (\"avatar\", \"id\", \"bot\", \"name\", \"discriminator\", \"global_name\") VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (\"id\") DO UPDATE SET @@ -687,26 +1657,73 @@ ON CONFLICT (\"id\") DO UPDATE \"bot\" = $3, \"name\" = $4, \"discriminator\" = $5, - \"global_name\" = $6")) } pub struct -CachedUserUpsertStmt(cornucopia_async::private::Stmt); impl CachedUserUpsertStmt -{ pub async fn bind<'a, C: -GenericClient,T1: -cornucopia_async::StringSql,T2: -cornucopia_async::StringSql,T3: -cornucopia_async::StringSql,T4: -cornucopia_async::StringSql,T5: -cornucopia_async::StringSql,>(&'a mut self, client: &'a C, -avatar: &'a Option,id: &'a T2,bot: &'a bool,name: &'a T3,discriminator: &'a T4,global_name: &'a Option,) -> Result -{ - let stmt = self.0.prepare(client).await?; - client.execute(stmt, &[avatar,id,bot,name,discriminator,global_name,]).await -} }impl <'a, C: GenericClient + Send + Sync, T1: cornucopia_async::StringSql,T2: cornucopia_async::StringSql,T3: cornucopia_async::StringSql,T4: cornucopia_async::StringSql,T5: cornucopia_async::StringSql,> -cornucopia_async::Params<'a, CachedUserUpsertParams, std::pin::Pin> + Send + 'a>>, C> for CachedUserUpsertStmt -{ - fn - params(&'a mut self, client: &'a C, params: &'a - CachedUserUpsertParams) -> std::pin::Pin> + Send + 'a>> - { Box::pin(self.bind(client, ¶ms.avatar,¶ms.id,¶ms.bot,¶ms.name,¶ms.discriminator,¶ms.global_name,)) } -}}} \ No newline at end of file + \"global_name\" = $6")) + } + pub struct CachedUserUpsertStmt(cornucopia_async::private::Stmt); + impl CachedUserUpsertStmt { + pub async fn bind< + 'a, + C: GenericClient, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + >( + &'a mut self, + client: &'a C, + avatar: &'a Option, + id: &'a T2, + bot: &'a bool, + name: &'a T3, + discriminator: &'a T4, + global_name: &'a Option, + ) -> Result { + let stmt = self.0.prepare(client).await?; + client + .execute(stmt, &[avatar, id, bot, name, discriminator, global_name]) + .await + } + } + impl< + 'a, + C: GenericClient + Send + Sync, + T1: cornucopia_async::StringSql, + T2: cornucopia_async::StringSql, + T3: cornucopia_async::StringSql, + T4: cornucopia_async::StringSql, + T5: cornucopia_async::StringSql, + > + cornucopia_async::Params< + 'a, + CachedUserUpsertParams, + std::pin::Pin< + Box< + dyn futures::Future> + + Send + + 'a, + >, + >, + C, + > for CachedUserUpsertStmt + { + fn params( + &'a mut self, + client: &'a C, + params: &'a CachedUserUpsertParams, + ) -> std::pin::Pin< + Box> + Send + 'a>, + > { + Box::pin(self.bind( + client, + ¶ms.avatar, + ¶ms.id, + ¶ms.bot, + ¶ms.name, + ¶ms.discriminator, + ¶ms.global_name, + )) + } + } + } +} diff --git a/database/hartex-database-typedsql/src/lib.rs b/database/hartex-database-typedsql/src/lib.rs index f2e404f9a..9f3f6a007 100644 --- a/database/hartex-database-typedsql/src/lib.rs +++ b/database/hartex-database-typedsql/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(let_chains)] /* * SPDX-License-Identifier: AGPL-3.0-only * @@ -19,7 +20,6 @@ * You should have received a copy of the GNU Affero General Public License along * with HarTex. If not, see . */ - #![deny(clippy::pedantic)] #![deny(unsafe_code)] #![deny(warnings)] @@ -30,11 +30,7 @@ mod error; mod schema; #[allow(clippy::missing_errors_doc)] -pub fn generate_queries_with_schemas

( - schemas_dir: P, - _: P, - _: P, -) -> error::Result<()> +pub fn generate_queries_with_schemas

(schemas_dir: P, _: P, _: P) -> error::Result<()> where P: AsRef, { diff --git a/database/hartex-database-typedsql/src/schema.rs b/database/hartex-database-typedsql/src/schema.rs index 141a1d88c..f79aebd65 100644 --- a/database/hartex-database-typedsql/src/schema.rs +++ b/database/hartex-database-typedsql/src/schema.rs @@ -20,6 +20,7 @@ * with HarTex. If not, see . */ +use pg_query::protobuf::node::Node; use std::fs; use std::path::Path; use std::path::PathBuf; @@ -45,7 +46,12 @@ pub(crate) fn read_schemas(dir: &Path) -> crate::error::Result crate::error::Result crate::error::Result { - let _ = pg_query::parse(schema_info.contents.as_str())?; + let result = pg_query::parse(schema_info.contents.as_str())?; + let statements = result.protobuf.stmts; + let _ = statements + .into_iter() + .filter_map(|statement| { + if let Some(Node::CreateStmt(create)) = statement.clone().stmt?.node { + Some(create) + } else { + None + } + }) + .collect::>(); // todo Ok(SchemaInfo) From 5aeb6f5cd93e87ad8fe6a13097631a36a20af60c Mon Sep 17 00:00:00 2001 From: HTGAzureX1212 <39023054+HTGAzureX1212@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:05:41 +0800 Subject: [PATCH 2/3] complete schema construction --- .../schemas/discord_frontend.sql | 3 +- .../hartex-database-typedsql/src/schema.rs | 76 +++++++++++++++++-- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/database/hartex-database-queries/schemas/discord_frontend.sql b/database/hartex-database-queries/schemas/discord_frontend.sql index e854fc4d7..319f51cd5 100644 --- a/database/hartex-database-queries/schemas/discord_frontend.sql +++ b/database/hartex-database-queries/schemas/discord_frontend.sql @@ -30,6 +30,7 @@ CREATE TABLE IF NOT EXISTS "Nightly"."CachedEmojis" ( "managed" BOOLEAN NOT NULL ); +/* CREATE TABLE IF NOT EXISTS "Nightly"."CachedGuilds" ( "default_message_notifications" SMALLINT NOT NULL, "explicit_content_filter" SMALLINT NOT NULL, @@ -81,4 +82,4 @@ CREATE TABLE IF NOT EXISTS "Nightly"."GuildConfigurations" ( "guild_id" TEXT NOT NULL PRIMARY KEY, "enabled_plugins" TEXT ARRAY NOT NULL ); - +*/ \ No newline at end of file diff --git a/database/hartex-database-typedsql/src/schema.rs b/database/hartex-database-typedsql/src/schema.rs index f79aebd65..7f8b418db 100644 --- a/database/hartex-database-typedsql/src/schema.rs +++ b/database/hartex-database-typedsql/src/schema.rs @@ -20,17 +20,37 @@ * with HarTex. If not, see . */ -use pg_query::protobuf::node::Node; use std::fs; use std::path::Path; use std::path::PathBuf; -pub(crate) struct SchemaInfo; +use pg_query::protobuf::node::Node; + +#[allow(dead_code)] +#[derive(Debug)] +pub(crate) struct ColumnInfo { + pub(crate) name: String, + pub(crate) coltype: String, +} + +#[allow(dead_code)] +#[derive(Debug)] +pub(crate) struct SchemaInfo { + pub(crate) name: String, + pub(crate) tables: Vec, +} + +#[allow(dead_code)] +#[derive(Debug)] +pub(crate) struct TableInfo { + pub(crate) name: String, + pub(crate) columns: Vec, +} +#[allow(dead_code)] +#[derive(Debug)] pub(crate) struct RawSchemaInfo { - #[allow(dead_code)] pub(crate) path: PathBuf, - #[allow(dead_code)] pub(crate) name: String, pub(crate) contents: String, } @@ -69,7 +89,7 @@ pub(crate) fn read_schemas(dir: &Path) -> crate::error::Result crate::error::Result { let result = pg_query::parse(schema_info.contents.as_str())?; let statements = result.protobuf.stmts; - let _ = statements + let tables = statements .into_iter() .filter_map(|statement| { if let Some(Node::CreateStmt(create)) = statement.clone().stmt?.node { @@ -78,8 +98,50 @@ pub(crate) fn parse_schema(schema_info: RawSchemaInfo) -> crate::error::Result>(), + ) + }) + .map(|(relation, columns)| TableInfo { + name: relation.relname, + columns, + }) .collect::>(); - // todo - Ok(SchemaInfo) + Ok( + SchemaInfo { + name: schema_info.name, + tables, + } + ) } From 5f24cfd8ae40a51bdfd57a555bc2ca3fb245e4e2 Mon Sep 17 00:00:00 2001 From: HTGAzureX1212 <39023054+HTGAzureX1212@users.noreply.github.com> Date: Tue, 3 Dec 2024 18:19:50 +0800 Subject: [PATCH 3/3] appease clippy --- database/hartex-database-typedsql/src/schema.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/hartex-database-typedsql/src/schema.rs b/database/hartex-database-typedsql/src/schema.rs index 7f8b418db..fac0f65f3 100644 --- a/database/hartex-database-typedsql/src/schema.rs +++ b/database/hartex-database-typedsql/src/schema.rs @@ -101,7 +101,7 @@ pub(crate) fn parse_schema(schema_info: RawSchemaInfo) -> crate::error::Result