New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the trait `diesel::query_builder::QueryFragment<DB>` is not implemented for `u32` #552

Closed
mattico opened this Issue Dec 26, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@mattico

mattico commented Dec 26, 2016

This is probably a simple error, but there aren't really any docs about how Insertable works, and the compiler error is not helpful.

use super::schema::files;

#[derive(Debug, Queryable)]
pub struct File {
    pub id: i64,
    pub file: String,
    pub last_sync: Option<i64>,
    pub size: i64,
    pub attributes: u32,
}

#[derive(Debug, Insertable)]
#[table_name="files"]
pub struct NewFile<'a> {
    pub file: &'a str,
    pub size: i64,
    pub attributes: u32,
}

Gives:

error[E0277]: the trait bound `i64: diesel::Expression` is not satisfied
  --> src\cache\models.rs:15:1
   |
15 | #[derive(Debug, Insertable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `i64`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert i64`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Integer>` for `&'insert i64`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `u32: diesel::Expression` is not satisfied
  --> src\cache\models.rs:15:1
   |
15 | #[derive(Debug, Insertable)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u32`
   |
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert u32`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Integer>` for `&'insert u32`
   = note: this error originates in a macro outside of the current crate

error[E0277]: the trait bound `i64: diesel::Expression` is not satisfied
  --> src\cache\models.rs:15:1

... etc

This error suggests that you can't insert integers? I can't imagine that is true, though the tests don't have any integers that aren't ids.

@mattico

This comment has been minimized.

mattico commented Dec 26, 2016

Oh, and I'm using the SQLite backend. That's probably important 😆

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 26, 2016

The error message is telling you that you are using the wrong integer types. Integer is the equivalent to i32. If you want to use i64 in Rust, you should use BigInt instead. SQL does not have unsigned integers which is why you cannot use u32

@sgrif sgrif closed this Dec 26, 2016

@mattico

This comment has been minimized.

mattico commented Dec 26, 2016

Thanks! 👍

@TheWaWaR

This comment has been minimized.

TheWaWaR commented Jun 30, 2017

INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.

But as soon as INTEGER values are read off of disk and into memory for processing, they are converted to the most general datatype (8-byte signed integer).

http://www.sqlite.org/datatype3.html#storageclasses

Seems INTEGER should map to i64 in SQLite3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment