[Diesel] use of #[derive(Insertable)] causes a compile error?


I have a Diesel project that almost works (i.e. I can generate my migration, I have a Queryable struct etc), except for this piece, which fails to compile:

#[derive(Debug, Clone, Insertable)]
#[table_name = "msgs"]
pub struct InsertableMsg {
    process: String,

    revision: u64,

    kind: String,

    origin: Option<String>,

    sent_at_ns: u64,

    received_at_ns: u64,

    wire_time_ns: u64,

It fails with this error:

error[E0277]: the trait bound `u64: diesel::Expression` is not satisfied
  --> src/bin/amplify/visualization_server.rs:83:24
83 | #[derive(Debug, Clone, Insertable)]
   |                        ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u64`
   = note: required because of the requirements on the impl of `diesel::Expression` for `&'insert u64`
   = note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Integer>` for `&'insert u64`
   = note: this error originates in a macro outside of the current crate

There are more errors, but this is the baffling one.

I was under the impression I could actually define an Insertable struct however I see fit, so this makes no sense to me.
Can anyone explain what’s going on here?

And as a follow-up question, how would this problem be solved for a field of some user-defined type?

EDIT: I’ve narrowed the issue to something akin to diesel does not like Rust's large unsized integer types, since the code compiles if I change the type to i32, yet usize and u32 cause compile errors, like u64. Is there really no way to define a table + struct such that I can write a u64 value to a sqlite db with diesel?


I think I found the problem, which is actually split into 2 parts.

Part I: I use the infer_schema! macro, which means that the schemas defined in the migrations directory effectively become the definitions. The corresponding fields were all of type INTEGER, rather than type UNSIGNED BIG INT. Correcting this mistake cleared up all compile errors.

Part II: The u64 type appears to be unsupported. So I compromised by making the Insertable struct field type i64 instead.