Skip to content
Discussion options

You must be logged in to vote

Since Cents is stored as an INTEGER, you don't need the buffer at all. Convert the value and hand it to sqlx's own i64 impl:

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 buf is no longer a plain Vec: #3957 wrapped it in SqliteArgumentsBuffer, whose push is pub(crate). The i64 impl in sqlx-sqlite/src/types/int.rs now does that push internally. #4287 proposed making push public again, and its author closed it, noting you …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KPull
Comment options

Answer selected by KPull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants