【问题标题】:trait not satisfied for select(count_star()).first特征不满足 select(count_star()).first
【发布时间】:2021-02-04 02:38:38
【问题描述】:

我想对名为主题的表的记录进行计数。我几乎是通过book

但是当我这样做时

let count: u64 = topics.select(count_star()).first(&conn).unwrap();

我不断收到(.first 下划线为错误):

[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.

所以我可能需要在这里做一些类型转换,但老实说,我不知道在什么时候。

【问题讨论】:

标签: rust rust-diesel


【解决方案1】:

正如错误告诉你的那样,count_star 会生成一个BigInt

正如 BigInt 的文档所示,BigInt 可以与 i64 相互转换,而不是 u64。

我猜尽管 MySQL 有无符号整数 Diesel 不支持它们,因为 SQL 没有指定无符号整数,所以并非所有数据库引擎都有它们(例如 Postgres 没有)。

无论如何,您的count 应该是i64,或者您需要设置从BigInti64u64 的更明确的转换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-30
    • 2022-11-27
    • 2021-08-23
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2021-06-23
    • 2021-03-28
    相关资源
    最近更新 更多