sqlx_bitflag_derive: Use PgU64 as translation base (#552)
* sqlx_bitflag_derive: Use PgU64 as translation base * Bump version of chorus-macros
This commit is contained in:
parent
ebea18c991
commit
f0dbd3410f
|
@ -282,7 +282,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "chorus-macros"
|
||||
version = "0.4.1"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"quote",
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue