问题描述
我想对名为topic的表的记录进行计数。我几乎是在book
但是当我这样做
let count: u64 = topics.select(count_star()).first(&conn).unwrap();
[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.
所以我应该在这里做一些类型转换,但老实说,我不知道在哪一点。
解决方法
错误告诉您,count_star会生成一个documentation。
并且正如BigInt的文档所指出的那样,BigInt可与i64(而非u64)进行相互转换。
我猜想,尽管MySQL具有无符号整数,但Diesel不支持它们,因为SQL并未指定无符号整数,因此并非所有数据库引擎都具有无符号整数(例如Postgres没有)。
无论如何,您的count
应该是i64
,否则您需要设置从BigInt
到i64
到u64
的更明确的转换