Replace conditional compiling of uNN/PgUNN with conditional compiled type alias

This commit is contained in:
bitfl0wer 2024-08-21 19:05:50 +02:00
parent bf94b9c04c
commit 4921487b33
No known key found for this signature in database
GPG Key ID: 8D90CA11485CD14D
15 changed files with 69 additions and 140 deletions

View File

@ -139,6 +139,27 @@ pub mod types;
))]
pub mod voice;
#[cfg(not(feature = "sqlx"))]
pub type UInt128 = u128;
#[cfg(feature = "sqlx")]
pub type UInt128 = sqlx_pg_uint::PgU128;
#[cfg(not(feature = "sqlx"))]
pub type UInt64 = u64;
#[cfg(feature = "sqlx")]
pub type UInt64 = sqlx_pg_uint::PgU64;
#[cfg(not(feature = "sqlx"))]
pub type UInt32 = u32;
#[cfg(feature = "sqlx")]
pub type UInt32 = sqlx_pg_uint::PgU32;
#[cfg(not(feature = "sqlx"))]
pub type UInt16 = u16;
#[cfg(feature = "sqlx")]
pub type UInt16 = sqlx_pg_uint::PgU16;
#[cfg(not(feature = "sqlx"))]
pub type UInt8 = u8;
#[cfg(feature = "sqlx")]
pub type UInt8 = sqlx_pg_uint::PgU8;
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
/// A URLBundle bundles together the API-, Gateway- and CDN-URLs of a Spacebar instance.
///

View File

@ -3,10 +3,9 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use serde::{Deserialize, Serialize};
#[cfg(feature = "sqlx")]
use sqlx_pg_uint::PgU64;
use crate::types::utils::Snowflake;
use crate::UInt64;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, PartialOrd)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
@ -18,20 +17,11 @@ pub struct Attachment {
/// Max 1024 characters
pub description: Option<String>,
pub content_type: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub size: u64,
#[cfg(feature = "sqlx")]
pub size: PgU64,
pub size: UInt64,
pub url: String,
pub proxy_url: String,
#[cfg(not(feature = "sqlx"))]
pub height: Option<u64>,
#[cfg(feature = "sqlx")]
pub height: Option<PgU64>,
#[cfg(not(feature = "sqlx"))]
pub width: Option<u64>,
#[cfg(feature = "sqlx")]
pub width: Option<PgU64>,
pub height: Option<UInt64>,
pub width: Option<UInt64>,
pub ephemeral: Option<bool>,
/// The duration of the audio file (only for voice messages)
pub duration_secs: Option<f32>,
@ -48,18 +38,12 @@ pub struct Attachment {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct PartialDiscordFileAttachment {
#[cfg(not(feature = "sqlx"))]
pub id: Option<u64>,
#[cfg(feature = "sqlx")]
pub id: Option<PgU64>,
pub id: Option<UInt64>,
pub filename: String,
/// Max 1024 characters
pub description: Option<String>,
pub content_type: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub size: Option<u64>,
#[cfg(feature = "sqlx")]
pub size: Option<PgU64>,
pub size: Option<UInt64>,
pub url: Option<String>,
pub proxy_url: Option<String>,
pub height: Option<i32>,

View File

@ -7,13 +7,12 @@ use super::option_vec_arc_rwlock_ptr_eq;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
#[cfg(feature = "sqlx")]
use sqlx_pg_uint::PgU64;
use crate::types::utils::Snowflake;
use crate::types::{
AutoModerationRuleTriggerType, IntegrationType, PermissionOverwriteType, Shared,
};
use crate::UInt64;
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
@ -254,28 +253,16 @@ pub struct AuditEntryInfo {
pub auto_moderation_rule_trigger_type: Option<AutoModerationRuleTriggerType>,
pub channel_id: Option<Snowflake>,
// #[serde(option_string)]
#[cfg(not(feature = "sqlx"))]
pub count: Option<u64>,
#[cfg(feature = "sqlx")]
pub count: Option<PgU64>,
pub count: Option<UInt64>,
// #[serde(option_string)]
#[cfg(not(feature = "sqlx"))]
pub delete_member_days: Option<u64>,
#[cfg(feature = "sqlx")]
pub delete_member_days: Option<PgU64>,
pub delete_member_days: Option<UInt64>,
/// The ID of the overwritten entity
pub id: Option<Snowflake>,
pub integration_type: Option<IntegrationType>,
// #[serde(option_string)]
#[cfg(not(feature = "sqlx"))]
pub members_removed: Option<u64>,
#[cfg(feature = "sqlx")]
pub members_removed: Option<PgU64>,
pub members_removed: Option<UInt64>,
// #[serde(option_string)]
#[cfg(not(feature = "sqlx"))]
pub message_id: Option<u64>,
#[cfg(feature = "sqlx")]
pub message_id: Option<PgU64>,
pub message_id: Option<UInt64>,
pub role_name: Option<String>,
#[serde(rename = "type")]
pub overwrite_type: Option<PermissionOverwriteType>,

View File

@ -5,6 +5,7 @@
#[cfg(feature = "client")]
use crate::gateway::Updateable;
use crate::types::Shared;
use crate::UInt8;
#[cfg(feature = "client")]
use chorus_macros::Updateable;
@ -86,10 +87,7 @@ pub struct AutoModerationRuleTriggerMetadataForKeywordPreset {
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata>
pub struct AutoModerationRuleTriggerMetadataForMentionSpam {
/// Max 50
#[cfg(not(feature = "sqlx"))]
pub mention_total_limit: u8,
#[cfg(feature = "sqlx")]
pub mention_total_limit: sqlx_pg_uint::PgU8,
pub mention_total_limit: UInt8,
pub mention_raid_protection_enabled: bool,
}

View File

@ -22,6 +22,7 @@ use crate::gateway::GatewayHandle;
#[cfg(feature = "client")]
use crate::gateway::Updateable;
use crate::UInt64;
#[cfg(feature = "client")]
use chorus_macros::{observe_option_vec, Composite, Updateable};
@ -296,10 +297,7 @@ pub struct ThreadMember {
pub id: Option<Snowflake>,
pub user_id: Option<Snowflake>,
pub join_timestamp: Option<DateTime<Utc>>,
#[cfg(not(feature = "sqlx"))]
pub flags: Option<u64>,
#[cfg(feature = "sqlx")]
pub flags: Option<sqlx_pg_uint::PgU64>,
pub flags: Option<UInt64>,
pub member: Option<Shared<GuildMember>>,
}

View File

@ -17,6 +17,7 @@ use crate::types::{
interfaces::WelcomeScreenObject,
utils::Snowflake,
};
use crate::UInt64;
use super::{option_arc_rwlock_ptr_eq, vec_arc_rwlock_ptr_eq, PublicUser};
@ -273,10 +274,7 @@ pub struct GuildScheduledEvent {
pub entity_id: Option<Snowflake>,
pub entity_metadata: Option<GuildScheduledEventEntityMetadata>,
pub creator: Option<Shared<User>>,
#[cfg(not(feature = "sqlx"))]
pub user_count: Option<u64>,
#[cfg(feature = "sqlx")]
pub user_count: Option<sqlx_pg_uint::PgU64>,
pub user_count: Option<UInt64>,
pub image: Option<String>,
}

View File

@ -10,6 +10,7 @@ use crate::types::{
utils::Snowflake,
Shared,
};
use crate::{UInt16, UInt8};
#[derive(Default, Debug, Deserialize, Serialize, Clone)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
@ -23,14 +24,8 @@ pub struct Integration {
pub syncing: Option<bool>,
pub role_id: Option<String>,
pub enabled_emoticons: Option<bool>,
#[cfg(not(feature = "sqlx"))]
pub expire_behaviour: Option<u8>,
#[cfg(feature = "sqlx")]
pub expire_behaviour: Option<sqlx_pg_uint::PgU8>,
#[cfg(not(feature = "sqlx"))]
pub expire_grace_period: Option<u16>,
#[cfg(feature = "sqlx")]
pub expire_grace_period: Option<sqlx_pg_uint::PgU16>,
pub expire_behaviour: Option<UInt8>,
pub expire_grace_period: Option<UInt16>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Shared<User>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]

View File

@ -10,6 +10,7 @@ use crate::types::{
Guild, InviteFlags, InviteTargetType, InviteType, Shared, Snowflake, VerificationLevel,
WelcomeScreenObject,
};
use crate::{UInt32, UInt8};
use super::guild::GuildScheduledEvent;
use super::{Application, Channel, GuildMember, NSFWLevel, User};
@ -39,14 +40,8 @@ pub struct Invite {
pub invite_type: Option<InviteType>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub inviter: Option<User>,
#[cfg(not(feature = "sqlx"))]
pub max_age: Option<u32>,
#[cfg(feature = "sqlx")]
pub max_age: Option<sqlx_pg_uint::PgU32>,
#[cfg(not(feature = "sqlx"))]
pub max_uses: Option<u8>,
#[cfg(feature = "sqlx")]
pub max_uses: Option<sqlx_pg_uint::PgU8>,
pub max_age: Option<UInt32>,
pub max_uses: Option<UInt8>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub stage_instance: Option<InviteStageInstance>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
@ -56,10 +51,7 @@ pub struct Invite {
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub target_user: Option<User>,
pub temporary: Option<bool>,
#[cfg(not(feature = "sqlx"))]
pub uses: Option<u32>,
#[cfg(feature = "sqlx")]
pub uses: Option<sqlx_pg_uint::PgU32>,
pub uses: Option<UInt32>,
}
/// The guild an invite is for.

View File

@ -15,6 +15,7 @@ use crate::types::{
utils::Snowflake,
Shared,
};
use crate::{UInt32, UInt8};
use super::option_arc_rwlock_ptr_eq;
@ -150,10 +151,7 @@ pub enum MessageReferenceType {
pub struct MessageInteraction {
pub id: Snowflake,
#[serde(rename = "type")]
#[cfg(not(feature = "sqlx"))]
pub interaction_type: u8,
#[cfg(feature = "sqlx")]
pub interaction_type: sqlx_pg_uint::PgU8,
pub interaction_type: UInt8,
pub name: String,
pub user: User,
pub member: Option<Shared<GuildMember>>,
@ -285,14 +283,8 @@ pub struct EmbedField {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Reaction {
#[cfg(not(feature = "sqlx"))]
pub count: u32,
#[cfg(feature = "sqlx")]
pub count: sqlx_pg_uint::PgU32,
#[cfg(not(feature = "sqlx"))]
pub burst_count: u32,
#[cfg(feature = "sqlx")]
pub burst_count: sqlx_pg_uint::PgU32,
pub count: UInt32,
pub burst_count: UInt32,
#[serde(default)]
pub me: bool,
#[serde(default)]

View File

@ -8,6 +8,7 @@ use serde_aux::prelude::deserialize_option_number_from_string;
use std::fmt::Debug;
use crate::types::utils::Snowflake;
use crate::{UInt16, UInt32};
#[cfg(feature = "client")]
use chorus_macros::{Composite, Updateable};
@ -32,10 +33,7 @@ pub struct RoleObject {
pub hoist: bool,
pub icon: Option<String>,
pub unicode_emoji: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub position: u16,
#[cfg(feature = "sqlx")]
pub position: sqlx_pg_uint::PgU16,
pub position: UInt16,
#[serde(default)]
pub permissions: PermissionFlags,
pub managed: bool,
@ -50,10 +48,7 @@ pub struct RoleObject {
pub struct RoleSubscriptionData {
pub role_subscription_listing_id: Snowflake,
pub tier_name: String,
#[cfg(not(feature = "sqlx"))]
pub total_months_subscribed: u32,
#[cfg(feature = "sqlx")]
pub total_months_subscribed: sqlx_pg_uint::PgU32,
pub total_months_subscribed: UInt32,
pub is_renewal: bool,
}

View File

@ -5,6 +5,7 @@
use serde::{Deserialize, Serialize};
use crate::types::utils::Snowflake;
use crate::UInt64;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
@ -13,10 +14,7 @@ pub struct SecurityKey {
pub user_id: String,
pub key_id: String,
pub public_key: String,
#[cfg(not(feature = "sqlx"))]
pub counter: u64,
#[cfg(feature = "sqlx")]
pub counter: sqlx_pg_uint::PgU64,
pub counter: UInt64,
pub name: String,
}
@ -27,10 +25,7 @@ impl Default for SecurityKey {
user_id: String::new(),
key_id: String::new(),
public_key: String::new(),
#[cfg(not(feature = "sqlx"))]
counter: 0,
#[cfg(feature = "sqlx")]
counter: sqlx_pg_uint::PgU64::from(0),
counter: 0.into(),
name: String::new(),
}
}

View File

@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
use crate::types::entities::User;
use crate::types::Shared;
use crate::types::Snowflake;
use crate::UInt8;
use super::arc_rwlock_ptr_eq;
@ -34,10 +35,7 @@ impl PartialEq for Team {
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TeamMember {
#[cfg(not(feature = "sqlx"))]
pub membership_state: u8,
#[cfg(feature = "sqlx")]
pub membership_state: sqlx_pg_uint::PgU8,
pub membership_state: UInt8,
pub permissions: Vec<String>,
pub team_id: Snowflake,
pub user: Shared<User>,

View File

@ -10,6 +10,7 @@ use crate::types::{
utils::Snowflake,
Shared,
};
use crate::UInt64;
/// See <https://docs.spacebar.chat/routes/#cmp--schemas-template>
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
@ -18,10 +19,7 @@ pub struct GuildTemplate {
pub code: String,
pub name: String,
pub description: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub usage_count: Option<u64>,
#[cfg(feature = "sqlx")]
pub usage_count: Option<sqlx_pg_uint::PgU64>,
pub usage_count: Option<UInt64>,
pub creator_id: Snowflake,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub creator: Shared<User>,

View File

@ -4,6 +4,7 @@
use crate::errors::ChorusError;
use crate::types::utils::Snowflake;
use crate::{UInt32, UInt8};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string;
@ -47,10 +48,7 @@ pub struct User {
pub bot: Option<bool>,
pub system: Option<bool>,
pub mfa_enabled: Option<bool>,
#[cfg(not(feature = "sqlx"))]
pub accent_color: Option<u32>,
#[cfg(feature = "sqlx")]
pub accent_color: Option<sqlx_pg_uint::PgU32>,
pub accent_color: Option<UInt32>,
#[cfg_attr(feature = "sqlx", sqlx(default))]
pub locale: Option<String>,
pub verified: Option<bool>,
@ -61,10 +59,7 @@ pub struct User {
#[serde(deserialize_with = "deserialize_option_number_from_string")]
pub flags: Option<UserFlags>,
pub premium_since: Option<DateTime<Utc>>,
#[cfg(not(feature = "sqlx"))]
pub premium_type: Option<u8>,
#[cfg(feature = "sqlx")]
pub premium_type: Option<sqlx_pg_uint::PgU8>,
pub premium_type: Option<UInt8>,
pub pronouns: Option<String>,
pub public_flags: Option<UserFlags>,
pub banner: Option<String>,
@ -150,19 +145,13 @@ pub struct PublicUser {
pub username: Option<String>,
pub discriminator: Option<String>,
pub avatar: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub accent_color: Option<u32>,
#[cfg(feature = "sqlx")]
pub accent_color: Option<sqlx_pg_uint::PgU32>,
pub accent_color: Option<UInt32>,
pub banner: Option<String>,
pub theme_colors: Option<ThemeColors>,
pub pronouns: Option<String>,
pub bot: Option<bool>,
pub bio: Option<String>,
#[cfg(not(feature = "sqlx"))]
pub premium_type: Option<u8>,
#[cfg(feature = "sqlx")]
pub premium_type: Option<sqlx_pg_uint::PgU8>,
pub premium_type: Option<UInt8>,
pub premium_since: Option<DateTime<Utc>>,
pub public_flags: Option<UserFlags>,
}

View File

@ -6,6 +6,7 @@ use chrono::{serde::ts_milliseconds_option, Utc};
use serde::{Deserialize, Serialize};
use crate::types::Shared;
use crate::{UInt16, UInt32, UInt8};
use serde_aux::field_attributes::deserialize_option_number_from_string;
#[derive(
@ -42,16 +43,10 @@ pub enum UserTheme {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
pub struct UserSettings {
#[cfg(not(feature = "sqlx"))]
pub afk_timeout: Option<u16>,
#[cfg(feature = "sqlx")]
pub afk_timeout: Option<sqlx_pg_uint::PgU16>,
pub afk_timeout: Option<UInt16>,
pub allow_accessibility_detection: bool,
pub animate_emoji: bool,
#[cfg(not(feature = "sqlx"))]
pub animate_stickers: u8,
#[cfg(feature = "sqlx")]
pub animate_stickers: sqlx_pg_uint::PgU8,
pub animate_stickers: UInt8,
pub contact_sync_enabled: bool,
pub convert_emoticons: bool,
pub custom_status: Option<CustomStatus>,
@ -60,10 +55,7 @@ pub struct UserSettings {
pub developer_mode: bool,
pub disable_games_tab: bool,
pub enable_tts_command: bool,
#[cfg(not(feature = "sqlx"))]
pub explicit_content_filter: u8,
#[cfg(feature = "sqlx")]
pub explicit_content_filter: sqlx_pg_uint::PgU8,
pub explicit_content_filter: UInt8,
pub friend_source_flags: FriendSourceFlags,
pub gateway_connected: Option<bool>,
pub gif_auto_play: bool,
@ -156,10 +148,7 @@ impl Default for FriendSourceFlags {
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow, sqlx::Type))]
#[cfg_attr(feature = "sqlx", sqlx(type_name = "interface_type"))]
pub struct GuildFolder {
#[cfg(not(feature = "sqlx"))]
pub color: Option<u32>,
#[cfg(feature = "sqlx")]
pub color: Option<sqlx_pg_uint::PgU32>,
pub color: Option<UInt32>,
pub guild_ids: Vec<String>,
// FIXME: What is this thing?
// It's not a snowflake, and it's sometimes a string and sometimes an integer.