-
I am slightly puzzled how to use
which fails since Using raw statements also failed, regardless if I use a custom type
The Is there a way to make this work accumulatin |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
That statement is incorrect: https://docs.diesel.rs/master/diesel/sql_types/struct.Numeric.html#impl-FromSql%3CNumeric,+Sqlite%3E-for-BigDecimal
That's expected as you miss to derive |
Beta Was this translation helpful? Give feedback.
-
I am a bit confused on how |
Beta Was this translation helpful? Give feedback.
-
Manual implementation of The following works: #[derive(Debug, PartialEq, Clone)]
struct X {
summed: i64,
}
impl QueryableByName<Sqlite> for X {
// Required method
fn build<'a>(row: &impl NamedRow<'a, Sqlite>) -> diesel::deserialize::Result<Self> {
let summed =
NamedRow::<'a, Sqlite>::get::<diesel::sql_types::BigInt, i64>(row, "summed")?;
Ok(Self { summed })
}
}
let maybe_nonce2 = diesel::sql_query("SELECT SUM(nonce) AS summed from deltas where account_id = ? AND num > ? AND num <= ?")
.bind::<diesel::sql_types::Blob, _>(&desired_account_id)
.bind::<diesel::sql_types::BigInt, _>(start)
.bind::<diesel::sql_types::BigInt, _>(end)
.get_result::<Option<X>>(conn)
.optional()?
.flatten(); Alternatively: let maybe_nonce = SelectDsl::select(
schema::deltas::table,
diesel::dsl::sum::<diesel::sql_types::BigInt, _>(schema::deltas::nonce),
)
.filter(
schema::account_deltas::account_id
.eq(desired_account_id)
.and(schema::deltas::num.gt(num))
.and(schema::deltas::num.le(num)),
)
.get_result::<Option<bigdecimal::BigDecimal>>(conn)
.optional()?
.flatten();
let x: i64 = your_conversion(x)?;
``` |
Beta Was this translation helpful? Give feedback.
Manual implementation of
QueryableByName
works, using#[derive(QueryableByName)]
does not, since there is a dependency on the existence ofmod $fieldname
which is only satisfied when used with a column name as generated by the cli tool /table!
.The following works: