Lots of sqlx-postgres type changes

This commit is contained in:
bitfl0wer 2024-08-19 17:20:27 +02:00
parent aa706a2c4e
commit 3ca471eaaa
No known key found for this signature in database
GPG Key ID: 8D90CA11485CD14D
17 changed files with 129 additions and 29 deletions

View File

@ -224,7 +224,8 @@ pub struct ApplicationCommandOptionChoice {
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(i32)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
/// # Reference
/// See <https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types>
pub enum ApplicationCommandOptionType {
@ -294,7 +295,8 @@ pub struct ApplicationCommandPermission {
Ord,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
/// See <https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permission-type>
pub enum ApplicationCommandPermissionType {
#[default]

View File

@ -48,7 +48,10 @@ pub struct Attachment {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct PartialDiscordFileAttachment {
pub id: Option<i16>,
#[cfg(not(feature = "sqlx"))]
pub id: Option<u64>,
#[cfg(feature = "sqlx")]
pub id: Option<PgU64>,
pub filename: String,
/// Max 1024 characters
pub description: Option<String>,

View File

@ -110,7 +110,8 @@ pub struct AuditLogChange {
PartialOrd,
Ord,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
/// # Reference:
/// See <https://docs.discord.sex/resources/audit-log#audit-log-events>

View File

@ -32,7 +32,8 @@ pub struct AutoModerationRule {
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default, Copy)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types>
pub enum AutoModerationRuleEventType {
@ -43,7 +44,8 @@ pub enum AutoModerationRuleEventType {
#[derive(
Serialize_repr, Deserialize_repr, Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Copy,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types>
pub enum AutoModerationRuleTriggerType {
@ -91,7 +93,8 @@ pub struct AutoModerationRuleTriggerMetadataForMentionSpam {
#[derive(
Serialize_repr, Deserialize_repr, Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Copy,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types>
pub enum AutoModerationRuleKeywordPresetType {
@ -110,9 +113,20 @@ pub struct AutoModerationAction {
}
#[derive(
Serialize_repr, Deserialize_repr, Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Copy, Hash
Serialize_repr,
Deserialize_repr,
Debug,
Clone,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Copy,
Hash,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types>
pub enum AutoModerationActionType {

View File

@ -32,9 +32,6 @@ use super::option_arc_rwlock_ptr_eq;
pub struct Emoji {
pub id: Snowflake,
pub name: Option<String>,
#[cfg(feature = "sqlx")]
pub roles: Option<sqlx::types::Json<Vec<Snowflake>>>,
#[cfg(not(feature = "sqlx"))]
pub roles: Option<Vec<Snowflake>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Shared<User>>,

View File

@ -303,7 +303,8 @@ impl PartialEq for GuildScheduledEvent {
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, PartialEq, Copy)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
/// See <https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-privacy-level>
pub enum GuildScheduledEventPrivacyLevel {
#[default]
@ -311,7 +312,8 @@ pub enum GuildScheduledEventPrivacyLevel {
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Default, Clone, PartialEq, Copy)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
/// See <https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status>
pub enum GuildScheduledEventStatus {
#[default]
@ -334,7 +336,8 @@ pub enum GuildScheduledEventStatus {
Copy,
Hash,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
/// See <https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-entity-types>
pub enum GuildScheduledEventEntityType {
#[default]
@ -395,7 +398,8 @@ pub enum MessageNotificationLevel {
Ord,
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord-userdoccers.vercel.app/resources/guild#explicit-content-filter-level>
pub enum ExplicitContentFilterLevel {
@ -419,7 +423,8 @@ pub enum ExplicitContentFilterLevel {
Ord,
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord-userdoccers.vercel.app/resources/guild#verification-level>
pub enum VerificationLevel {
@ -445,7 +450,8 @@ pub enum VerificationLevel {
Ord,
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord-userdoccers.vercel.app/resources/guild#verification-level>
pub enum MFALevel {
@ -468,7 +474,8 @@ pub enum MFALevel {
Ord,
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord-userdoccers.vercel.app/resources/guild#verification-level>
pub enum NSFWLevel {
@ -493,7 +500,8 @@ pub enum NSFWLevel {
Ord,
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i8))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord-userdoccers.vercel.app/resources/guild#verification-level>
pub enum PremiumTier {

View File

@ -23,8 +23,14 @@ 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>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Shared<User>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]

View File

@ -5,8 +5,11 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{Snowflake, WelcomeScreenObject, Shared, InviteFlags, InviteType, InviteTargetType, Guild, VerificationLevel};
use crate::types::types::guild_configuration::GuildFeaturesList;
use crate::types::{
Guild, InviteFlags, InviteTargetType, InviteType, Shared, Snowflake, VerificationLevel,
WelcomeScreenObject,
};
use super::guild::GuildScheduledEvent;
use super::{Application, Channel, GuildMember, NSFWLevel, User};
@ -36,8 +39,14 @@ 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>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub stage_instance: Option<InviteStageInstance>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
@ -47,7 +56,10 @@ 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>,
}
/// The guild an invite is for.

View File

@ -150,7 +150,10 @@ 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 name: String,
pub user: User,
pub member: Option<Shared<GuildMember>>,
@ -282,8 +285,14 @@ 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,
#[serde(default)]
pub me: bool,
#[serde(default)]
@ -296,6 +305,8 @@ pub struct Reaction {
}
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, Eq, PartialOrd, Ord)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
pub enum Component {
ActionRow = 1,
Button = 2,
@ -320,7 +331,8 @@ pub struct MessageActivity {
Debug, Default, PartialEq, Clone, Copy, Serialize_repr, Deserialize_repr, Eq, PartialOrd, Ord,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
/// # Reference
/// See <https://docs.discord.sex/resources/message#message-type>

View File

@ -45,7 +45,8 @@ impl PartialEq for Relationship {
Copy,
Hash,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
/// See <https://discord-userdoccers.vercel.app/resources/user#relationship-type>
pub enum RelationshipType {
Suggestion = 6,

View File

@ -32,7 +32,10 @@ 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,
#[serde(default)]
pub permissions: PermissionFlags,
pub managed: bool,
@ -47,11 +50,16 @@ 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 is_renewal: bool,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Hash, Copy, PartialOrd, Ord)]
#[derive(
Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, Hash, Copy, PartialOrd, Ord,
)]
/// See <https://discord.com/developers/docs/topics/permissions#role-object-role-tags-structure>
pub struct RoleTags {
#[serde(default)]

View File

@ -21,8 +21,11 @@ pub struct StageInstance {
pub guild_scheduled_event_id: Option<Snowflake>,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
#[derive(
Serialize_repr, Deserialize_repr, Debug, Clone, Default, Copy, PartialEq, Eq, PartialOrd, Ord,
)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
/// See <https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-privacy-level>
pub enum StageInstancePrivacyLevel {

View File

@ -77,7 +77,8 @@ pub struct StickerItem {
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Hash, Serialize_repr, Deserialize_repr,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[serde(rename = "SCREAMING_SNAKE_CASE")]
/// # Reference
@ -93,7 +94,8 @@ pub enum StickerType {
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Hash, Serialize_repr, Deserialize_repr,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
/// # Reference
/// See <https://docs.discord.sex/resources/sticker#sticker-format-types>

View File

@ -34,7 +34,10 @@ 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 permissions: Vec<String>,
pub team_id: Snowflake,
pub user: Shared<User>,

View File

@ -47,7 +47,10 @@ 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>,
#[cfg_attr(feature = "sqlx", sqlx(default))]
pub locale: Option<String>,
pub verified: Option<bool>,
@ -58,7 +61,10 @@ 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 pronouns: Option<String>,
pub public_flags: Option<UserFlags>,
pub banner: Option<String>,
@ -144,13 +150,19 @@ 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 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_since: Option<DateTime<Utc>>,
pub public_flags: Option<UserFlags>,
}

View File

@ -45,7 +45,10 @@ pub struct UserSettings {
pub afk_timeout: Option<u16>,
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 contact_sync_enabled: bool,
pub convert_emoticons: bool,
pub custom_status: Option<CustomStatus>,
@ -54,7 +57,10 @@ 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 friend_source_flags: FriendSourceFlags,
pub gateway_connected: Option<bool>,
pub gif_auto_play: bool,
@ -82,7 +88,10 @@ impl Default for UserSettings {
afk_timeout: Some(3600),
allow_accessibility_detection: true,
animate_emoji: true,
#[cfg(not(feature = "sqlx"))]
animate_stickers: 0,
#[cfg(feature = "sqlx")]
animate_stickers: 0.into(),
contact_sync_enabled: false,
convert_emoticons: false,
custom_status: None,
@ -91,7 +100,10 @@ impl Default for UserSettings {
developer_mode: true,
disable_games_tab: true,
enable_tts_command: false,
#[cfg(not(feature = "sqlx"))]
explicit_content_filter: 0,
#[cfg(feature = "sqlx")]
explicit_content_filter: 0.into(),
friend_source_flags: Default::default(),
gateway_connected: Some(false),
gif_auto_play: false,
@ -137,7 +149,10 @@ impl Default for FriendSourceFlags {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GuildFolder {
#[cfg(not(feature = "sqlx"))]
pub color: Option<u32>,
#[cfg(feature = "sqlx")]
pub color: Option<sqlx_pg_uint::PgU32>,
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.

View File

@ -71,7 +71,8 @@ impl PartialEq for Webhook {
#[derive(
Serialize, Deserialize, Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
#[repr(u8)]
#[cfg_attr(not(feature = "sqlx"), repr(u8))]
#[cfg_attr(feature = "sqlx", repr(i16))]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
pub enum WebhookType {
#[default]