diff --git a/.env.example b/.env.example index e5219cad0..3333b6b09 100644 --- a/.env.example +++ b/.env.example @@ -19,4 +19,5 @@ KAFKA_TOPIC_OUTBOUND_COMMUNICATION=kafka_topic_outbound_communication # PostgreSQL things API_BACKEND_PGSQL_URL=api_pgsql_url -DISCORD_FRONTEND_PGSQL_URL=discord_frontend_nightly_pgsql_url +CONFIGURATION_PGSQL_URL=configuration_pgsql_url +DISCORD_FRONTEND_PGSQL_URL=discord_frontend_pgsql_url diff --git a/database/hartex-database-queries/build.rs b/database/hartex-database-queries/build.rs index 084e723ef..0b56aab09 100644 --- a/database/hartex-database-queries/build.rs +++ b/database/hartex-database-queries/build.rs @@ -21,51 +21,6 @@ */ pub fn main() { - /*let api_backend_queries_path = "queries/api_backend"; - println!("cargo::rerun-if-changed={api_backend_queries_path}"); - - let url = env::var("API_PGSQL_URL").unwrap(); - cornucopia::generate_live( - &mut Client::connect(&url, NoTls).unwrap(), - api_backend_queries_path, - Some("generated/api_backend.rs"), - CodegenSettings { - derive_ser: false, - is_async: true, - }, - ) - .unwrap(); - - let configuration_queries_path = "queries/configuration"; - println!("cargo::rerun-if-changed={configuration_queries_path}"); - - let url = env::var("HARTEX_NIGHTLY_PGSQL_URL").unwrap(); - cornucopia::generate_live( - &mut Client::connect(&url, NoTls).unwrap(), - configuration_queries_path, - Some("generated/configuration.rs"), - CodegenSettings { - derive_ser: false, - is_async: true, - }, - ) - .unwrap(); - - let discord_frontend_queries_path = "queries/discord_frontend"; - println!("cargo::rerun-if-changed={discord_frontend_queries_path}"); - - let url = env::var("HARTEX_NIGHTLY_PGSQL_URL").unwrap(); - cornucopia::generate_live( - &mut Client::connect(&url, NoTls).unwrap(), - discord_frontend_queries_path, - Some("generated/discord_frontend.rs"), - CodegenSettings { - derive_ser: false, - is_async: true, - }, - ) - .unwrap();*/ - if let Err(error) = hartex_database_typedsql::generate_crate("schemas", "queries", "src") { println!("cargo::error=Error while generating typed queries: {error:?}"); } diff --git a/database/hartex-database-queries/generated/api_backend.rs b/database/hartex-database-queries/generated/api_backend.rs deleted file mode 100644 index 3977f5ff6..000000000 --- a/database/hartex-database-queries/generated/api_backend.rs +++ /dev/null @@ -1,183 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types {} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod start_timestamp_select_by_component { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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, - { - 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 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), - } - } - } - } - pub mod start_timestamp_upsert { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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< - 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 deleted file mode 100644 index ef2eef6a9..000000000 --- a/database/hartex-database-queries/generated/configuration.rs +++ /dev/null @@ -1,126 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types {} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod plugin_enabled { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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, - { - 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 fn plugin_enabled() -> PluginEnabledStmt { - PluginEnabledStmt(cornucopia_async::private::Stmt::new( - "SELECT EXISTS( - SELECT - TRUE - FROM - \"Nightly\".\"GuildConfigurations\" - 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, - } - } - } - 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) - } - } - } -} diff --git a/database/hartex-database-queries/generated/discord_frontend.rs b/database/hartex-database-queries/generated/discord_frontend.rs deleted file mode 100644 index 28777cc16..000000000 --- a/database/hartex-database-queries/generated/discord_frontend.rs +++ /dev/null @@ -1,1742 +0,0 @@ -// This file was generated with `cornucopia`. Do not modify. - -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod types {} -#[allow(clippy::all, clippy::pedantic)] -#[allow(unused_variables)] -#[allow(unused_imports)] -#[allow(dead_code)] -pub mod queries { - pub mod cached_emoji_select_by_guild_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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, - { - 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), - } - } - } - } - pub mod cached_emoji_select_by_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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, - { - 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), - } - } - } - } - pub mod cached_emoji_upsert { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for CachedEmojiUpsertStmt - { - 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 mod cached_guild_select_by_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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), - } - } - } - } - pub mod cached_guild_upsert { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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 - SET - \"default_message_notifications\" = $1, - \"explicit_content_filter\" = $2, - \"features\" = $3, - \"icon\" = $4, - \"large\" = $5, - \"mfa_level\" = $9, - \"name\" = $6, - \"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< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for CachedGuildUpsertStmt - { - 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 mod cached_member_select_by_guild_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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), - } - } - } - } - pub mod cached_member_select_by_user_id_and_guild_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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 - { - 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), - } - } - } - 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 cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for CachedMemberUpsertStmt - { - 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 mod cached_role_select_by_guild_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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), - } - } - } - } - pub mod cached_role_select_by_id_and_guild_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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, - { - 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), - } - } - } - 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 cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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 - \"color\" = $1, - \"icon\" = $2, - \"flags\" = $5, - \"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< - Box< - dyn futures::Future> - + Send - + 'a, - >, - >, - C, - > for CachedRoleUpsertStmt - { - 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 mod cached_user_select_by_id { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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), - } - } - } - } - pub mod cached_user_upsert { - use cornucopia_async::GenericClient; - use futures; - use futures::StreamExt; - use futures::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 - \"avatar\" = $1, - \"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< - 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-queries/src/lib.rs b/database/hartex-database-queries/src/lib.rs index c7e6ed321..8fce1cd23 100644 --- a/database/hartex-database-queries/src/lib.rs +++ b/database/hartex-database-queries/src/lib.rs @@ -25,9 +25,6 @@ #![deny(warnings)] #![feature(result_flattening)] -#[path = "../generated/discord_frontend.rs"] -pub mod discord_frontend; - mod internal; pub mod queries; pub mod result;