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

seb*_*ssa 5 sqlite rust rust-diesel

我如何使用i64/u64与柴油一起使用?

我真的需要实施 diesel::Expression为原始类型trait 吗?

这是我的代码。

Cargo.toml

[dependencies]
...
diesel = { version = "1.4.5", features = ["sqlite", "numeric"] }
Run Code Online (Sandbox Code Playgroud)

migration/up.sql

[dependencies]
...
diesel = { version = "1.4.5", features = ["sqlite", "numeric"] }
Run Code Online (Sandbox Code Playgroud)

schema.rs

CREATE TABLE books (
  id INTEGER NOT NULL PRIMARY KEY,
  size INTEGER NOT NULL
);
Run Code Online (Sandbox Code Playgroud)

来源:

table! {
    books (id) {
        id -> Integer,
        size -> Integer,
    }
}
Run Code Online (Sandbox Code Playgroud)

这给出了以下错误:

use crate::schema::books;

#[derive(Insertable, Queryable)]
#[table_name="books"]
pub struct BookRecord {
    pub id: Id,
    pub size: i64,
}
Run Code Online (Sandbox Code Playgroud)

如何解决此错误?

Cod*_*256 6

i64对应BigInti32对应Integer。要么更改您的架构以使用BigInt,要么将您的数字更改为i32.