How do I use i64/u64 with Diesel?
Do I really need to implement the diesel::Expression trait for the primitive type?
Here is my code.
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,
}
}
sources:
use crate::schema::books;
#[derive(Insertable, Queryable)]
#[table_name="books"]
pub struct BookRecord {
pub id: Id,
pub size: i64,
}
This gives the following error:
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)
How do I resolve this error?
i64 corresponds to BigInt and i32 corresponds to Integer. Either change your schema to use BigInt, or change your numbers to i32.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With