Skip to content

Commit

Permalink
sqlx_bitflag_derive: Use PgU64 as translation base (#552)
Browse files Browse the repository at this point in the history
* sqlx_bitflag_derive: Use PgU64 as translation base

* Bump version of chorus-macros
  • Loading branch information
bitfl0wer authored Aug 25, 2024
1 parent ebea18c commit f0dbd34
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chorus-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chorus-macros"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
license = "MPL-2.0"
description = "Macros for the chorus crate."
Expand Down
7 changes: 3 additions & 4 deletions chorus-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,21 @@ pub fn sqlx_bitflag_derive(input: TokenStream) -> TokenStream {
#[cfg(feature = "sqlx")]
impl sqlx::Type<sqlx::Postgres> for #name {
fn type_info() -> sqlx::postgres::PgTypeInfo {
<Vec<u8> as sqlx::Type<sqlx::Postgres>>::type_info()
<sqlx_pg_uint::PgU64 as sqlx::Type<sqlx::Postgres>>::type_info()
}
}

#[cfg(feature = "sqlx")]
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)
<sqlx_pg_uint::PgU64 as sqlx::Encode<sqlx::Postgres>>::encode_by_ref(&self.bits().into(), buf)
}
}

#[cfg(feature = "sqlx")]
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())
<sqlx_pg_uint::PgU64 as sqlx::Decode<sqlx::Postgres>>::decode(value).map(|v| Self::from_bits_truncate(v.to_uint()))
}
}

Expand Down

0 comments on commit f0dbd34

Please sign in to comment.