I'd like to do a count on records of a table named topics. I'm doing it almost by the book
but when I do
let count: u64 = topics.select(count_star()).first(&conn).unwrap();
I keep getting (.first is underlined as error):
[rustc E0277] [E] the trait bound `u64: diesel::deserialize::FromSql<diesel::
sql_types::BigInt, diesel::mysql::Mysql>` is not satisfied
the trait `diesel::deserialize::FromSql<diesel::sql_types::BigInt, diesel::
mysql::Mysql>` is not implemented for `u64`
help: the following implementations were found:
<u64 as diesel::deserialize::FromSql<diesel::sql_types::
// I guess there's more information but Vim's
// Pmenu only shows up to eight lines.
So propably I need to do some type casting here, but honestly, I have no idea at which point.
As the error tells you, count_star generates a BigInt.
And as BigInt's documentation indicates, BigInt is convertible to and from i64, not u64.
I guess despite MySQL having unsigned integers Diesel doesn't support them because SQL doesn't specify unsigned integers, so not all database engines have them (e.g. Postgres does not).
Anyway your
count
should be ani64
, or you need to set up a more explicit conversion from aBigInt
to ani64
to anu64
.