Change sqlx::Any to sqlx::Postgres

This commit is contained in:
bitfl0wer 2024-08-12 17:15:31 +02:00
parent ec9541f38e
commit ccef3128a1
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
3 changed files with 11 additions and 13 deletions

View File

@ -49,13 +49,11 @@ log = "0.4.22"
async-trait = "0.1.81"
chorus-macros = { path = "./chorus-macros", version = "0" } # Note: version here is used when releasing. This will use the latest release. Make sure to republish the crate when code in macros is changed!
sqlx = { version = "0.8.0", features = [
"mysql",
"sqlite",
"json",
"chrono",
"ipnetwork",
"runtime-tokio-rustls",
"any",
"postgres",
], optional = true }
discortp = { version = "0.5.0", optional = true, features = [
"rtp",

View File

@ -164,23 +164,23 @@ pub fn sqlx_bitflag_derive(input: TokenStream) -> TokenStream {
quote!{
#[cfg(feature = "sqlx")]
impl sqlx::Type<sqlx::Any> for #name {
fn type_info() -> sqlx::any::AnyTypeInfo {
<Vec<u8> as sqlx::Type<sqlx::Any>>::type_info()
impl sqlx::Type<sqlx::Postgres> for #name {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<Vec<u8> as sqlx::Type<sqlx::Postgres>>::type_info()
}
}
#[cfg(feature = "sqlx")]
impl<'q> sqlx::Encode<'q, sqlx::Any> for #name {
fn encode_by_ref(&self, buf: &mut <sqlx::Any as sqlx::Database>::ArgumentBuffer<'q>) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
<Vec<u8> as sqlx::Encode<sqlx::Any>>::encode_by_ref(&self.bits().to_be_bytes().into(), buf)
impl<'q> sqlx::Encode<'q, sqlx::Postgres> for #name {
fn encode_by_ref(&self, buf: &mut <sqlx::Postgres as sqlx::Database>::ArgumentBuffer<'q>) -> Result<sqlx::encode::IsNull, sqlx::error::BoxDynError> {
<Vec<u8> as sqlx::Encode<sqlx::Postgres>>::encode_by_ref(&self.bits().to_be_bytes().into(), buf)
}
}
#[cfg(feature = "sqlx")]
impl<'q> sqlx::Decode<'q, sqlx::Any> for #name {
fn decode(value: <sqlx::Any as sqlx::Database>::ValueRef<'q>) -> Result<Self, sqlx::error::BoxDynError> {
let vec = <Vec<u8> as sqlx::Decode<sqlx::Any>>::decode(value)?;
impl<'q> sqlx::Decode<'q, sqlx::Postgres> for #name {
fn decode(value: <sqlx::Postgres as sqlx::Database>::ValueRef<'q>) -> Result<Self, sqlx::error::BoxDynError> {
let vec = <Vec<u8> as sqlx::Decode<sqlx::Postgres>>::decode(value)?;
Ok(Self::from_bits(vec_u8_to_u64(vec)).unwrap())
}
}

View File

@ -342,7 +342,7 @@ pub struct DefaultReaction {
)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[repr(u32)]
#[repr(i32)]
/// # Reference
/// See <https://discord-userdoccers.vercel.app/resources/channel#channel-type>
pub enum ChannelType {