sqlite - 如何使用 Diesel 将 i64 与 Insertable 结合使用

标签 sqlite rust rust-diesel

我如何使用 i64/u64用柴油?
我真的需要实现 diesel::Expression原始类型的特征?
这是我的代码。Cargo.toml :

[dependencies]
...
diesel = { version = "1.4.5", features = ["sqlite", "numeric"] }
migration/up.sql :
CREATE TABLE books (
  id INTEGER NOT NULL PRIMARY KEY,
  size INTEGER NOT NULL
);
schema.rs :
table! {
    books (id) {
        id -> Integer,
        size -> Integer,
    }
}
来源:
use crate::schema::books;

#[derive(Insertable, Queryable)]
#[table_name="books"]
pub struct BookRecord {
    pub id: Id,
    pub size: i64,
}
这给出了以下错误:
error[E0277]: the trait bound `i64: diesel::Expression` is not satisfied
 --> src/lib/models/book.rs:4:10
  |
4 | #[derive(Insertable, Queryable)]
  |          ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `i64`
  |
  = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Integer>` for `i64`
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
如何解决此错误?

最佳答案

i64 corresponds to BigInt i32 corresponds to Integer .要么更改您的架构以使用 BigInt ,或将您的号码更改为 i32 .

关于sqlite - 如何使用 Diesel 将 i64 与 Insertable 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63848682/

相关文章:

rust - 如何使用易出错的初始化程序延迟初始化/填充 `Option`?

rust - Diesel 是否支持 Postgres `point` 类型?

python-3.x - 当错误涉及 "sqlite3.OperationalError: incomplete input "') 时如何修复 ''

从家里构建相对目录时 Rust PathBuf 出现问题

sqlite - 无法为 Xamarin 的 SQLite 获取正确的 nuget 版本

rust - Rust 宏可以生成可复制的 getter 吗?

rust - 为什么在将使用 Diesel 的特征重写为特征方法的函数时得到 "overflow evaluating the requirement"?

objective-c - 从sqlite表中删除数据iPhone SDK?

NHibernate 的增量生成器 - 无法获取初始值