Repository navigation
|
I just updated from sqlx version 0.8.6 to version 0.9.0 and noticed that it broke my build in an unusual way that I can't solve. To begin with, I have a wrapper type called Here's the code that I had when I used version 0.8.6: impl Encode<'_, Sqlite> for Cents {
fn encode(
self,
buf: &mut <Sqlite as Database>::ArgumentBuffer<'_>,
) -> Result<IsNull, BoxDynError>
where
Self: Sized,
{
buf.push(SqliteArgumentValue::Int64(
self.0
.mul(BigDecimal::from(100))
.to_i64()
.expect("Unable to encode Cents for database"),
));
Result::Ok(IsNull::No)
}
// ... Other functions omitted
}When I updated to 0.9.0, firstly, I got an error that It seems Just as a note, the impl Decode<'_, Sqlite> for Cents {
fn decode(value: <Sqlite as Database>::ValueRef<'_>) -> Result<Self, BoxDynError> {
let cents = <i64 as Decode<Sqlite>>::decode(value)?;
let decoded = BigDecimal::from_i64(cents)
.expect("Unable to decode Cents for database")
.div(BigDecimal::from(100));
Result::Ok(Cents(decoded))
}
} |
Replies: 1 comment 1 reply
|
Since impl Encode<'_, Sqlite> for Cents {
fn encode_by_ref(&self, buf: &mut <Sqlite as Database>::ArgumentBuffer) -> Result<IsNull, BoxDynError> {
let cents = self.0.clone().mul(BigDecimal::from(100)).to_i64().ok_or("Cents out of i64 range")?;
<i64 as Encode<Sqlite>>::encode(cents, buf)
}
}In 0.9.0 I tried this with sqlx 0.9.0 on rustc 1.94.1 (with |
Since
Centsis stored as an INTEGER, you don't need the buffer at all. Convert the value and hand it to sqlx's owni64impl:In 0.9.0
bufis no longer a plainVec: #3957 wrapped it inSqliteArgumentsBuffer, whosepushispub(crate). Thei64impl insqlx-sqlite/src/types/int.rsnow does that push internally. #4287 proposed makingpushpublic again, and its author closed it, noting you …