From 6c1493f362fc0533b86417b93e5210a2208323a3 Mon Sep 17 00:00:00 2001 From: Quat3rnion Date: Tue, 4 Jun 2024 22:21:48 -0400 Subject: [PATCH] Add sqlx Type, Encode, Decode impl for InviteFlags bitflag object. --- src/types/schema/channel.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/types/schema/channel.rs b/src/types/schema/channel.rs index 91e7d30..d716399 100644 --- a/src/types/schema/channel.rs +++ b/src/types/schema/channel.rs @@ -137,6 +137,29 @@ bitflags! { } } +#[cfg(feature = "sqlx")] +impl sqlx::Type for InviteFlags { + fn type_info() -> sqlx::mysql::MySqlTypeInfo { + u64::type_info() + } +} + +#[cfg(feature = "sqlx")] +impl<'q> sqlx::Encode<'q, sqlx::MySql> for InviteFlags { + fn encode_by_ref(&self, buf: &mut >::ArgumentBuffer) -> sqlx::encode::IsNull { + u64::encode_by_ref(&self.0.0, buf) + } +} + +#[cfg(feature = "sqlx")] +impl<'r> sqlx::Decode<'r, sqlx::MySql> for InviteFlags { + fn decode(value: >::ValueRef) -> Result { + let raw = u64::decode(value)?; + + Ok(Self::from_bits(raw).unwrap()) + } +} + #[derive(Debug, Deserialize, Serialize, Clone, Copy, Default, PartialOrd, Ord, PartialEq, Eq)] #[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[serde(rename_all = "SCREAMING_SNAKE_CASE")]