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 bound `i32: diesel::Expression` is not satisfied [E0277] #337

Closed
fuyingfuying opened this Issue May 19, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@fuyingfuying

fuyingfuying commented May 19, 2016

@sgrif
Another error. Please help me.
On ubuntu 15.10.

fuying@fuying-linux:~/rustprojs/simtraining$ cargo --version
cargo 0.11.0-nightly (b304305 2016-05-06)
fuying@fuying-linux:~/rustprojs/simtraining$ rustc --version
rustc 1.10.0-nightly (d91f8ab0f 2016-05-07)
fuying@fuying-linux:~/rustprojs/simtraining$ cargo build
   Compiling simtraining v0.1.0 (file:///home/fuying/rustprojs/simtraining)
src/dev.rs:7:23: 7:23 error: the trait bound `i32: diesel::Expression` is not satisfied [E0277]
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 
'no annotations resulted from: 
Line { line_index: 6, annotations: [Annotation { start_col: 22, end_col: 22, is_primary: true, label: None }] }', 
../src/libsyntax/errors/snippet/mod.rs:495
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `simtraining`.

To learn more, run the command again with --verbose.

up.sql:

CREATE TABLE users (
    uid VARCHAR PRIMARY KEY,
    password VARCHAR NOT NULL,
    level INTEGER NOT NULL,
    realname VARCHAR NOT NULL,
    age INTEGER NOT NULL,
    sex VARCHAR NOT NULL
);
CREATE TABLE training_sessions (
  id SERIAL PRIMARY KEY,
  sec BIGINT NOT NULL,
  nsec INTEGER NOT NULL,
  name VARCHAR NOT NULL,
  xitong_id INTEGER NOT NULL,
  admin_uid VARCHAR NOT NULL,
  users_uid VARCHAR[] NOT NULL,
  actions_id INTEGER[] NOT NULL,
  mode VARCHAR NOT NULL,
  state VARCHAR NOT NULL,
  sec_duration BIGINT NOT NULL,
  nsec_duration INTEGER NOT NULL,
  score_op_order DOUBLE PRECISION NOT NULL,
  score_op_correct DOUBLE PRECISION NOT NULL,
  score_op_duration DOUBLE PRECISION NOT NULL,
  score DOUBLE PRECISION NOT NULL
);

CREATE TABLE training_actions (
  id SERIAL PRIMARY KEY,
  sec BIGINT NOT NULL,
  nsec INTEGER NOT NULL,
  name VARCHAR NOT NULL,
  session_id INTEGER NOT NULL,
  user_uid INTEGER NOT NULL,
  action_type VARCHAR NOT NULL,
  dev_uid VARCHAR NOT NULL,
  zhanwei_uid VARCHAR NOT NULL,
  sec_duration BIGINT NOT NULL,
  nsec_duration INTEGER NOT NULL,
  score_op_order DOUBLE PRECISION NOT NULL,
  score_op_correct DOUBLE PRECISION NOT NULL,
  score_op_duration DOUBLE PRECISION NOT NULL,
  score DOUBLE PRECISION NOT NULL
);

CREATE TABLE zhanweis (
  uid VARCHAR PRIMARY KEY,
  zhanwei_type VARCHAR NOT NULL,
  user_id VARCHAR
);

CREATE TABLE devs (
  uid VARCHAR PRIMARY KEY,
  id INTEGER NOT NULL,
  dev_type VARCHAR NOT NULL
);

dev.rs

use schema::*;
use diesel;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use diesel::result::Error;
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, Queryable)]
#[changeset_for(devs)]
#[insertable_into(devs)]
pub struct Dev {
    pub uid: String,
    pub id: i32,
    pub dev_type: String,
}

impl Dev {
    pub fn new(uid: &str, id: i32, dev_type: &str) -> Dev {
        Dev {
            uid: uid.to_string(),
            id: id,
            dev_type: dev_type.to_string(),
        }
    }
    pub fn create(conn: &PgConnection, _dev: Dev) -> diesel::QueryResult<Dev> {
        let dev = _dev.clone();
        match devs::table.find(_dev.uid).first::<Dev>(conn) {
            Err(Error::NotFound) => {
                return ::diesel::insert(&dev)
                           .into(devs::table)
                           .get_result(conn);
            }
            Ok(_) => return Err(Error::DatabaseError("此用户名已存在".to_string())),
            Err(e) => return Err(e),
        }
    }
    pub fn show_all(conn: &PgConnection) -> diesel::QueryResult<Vec<Dev>> {
        devs::table.load::<Dev>(conn)
    }
    pub fn find_by_id(conn: &PgConnection, _uid: &str) -> diesel::QueryResult<Dev> {
        devs::table.find(_uid.to_string()).first::<Dev>(conn)
    }
    pub fn update(conn: &PgConnection, _uid: &str, data: &Dev) -> diesel::QueryResult<usize> {
        use ::schema::devs::dsl::*;
        diesel::update(devs.filter(uid.eq(_uid.to_string()))).set(data).execute(conn)
    }
    pub fn delete(conn: &PgConnection, _uid: &str) -> diesel::QueryResult<usize> {
        use ::schema::devs::dsl::*;
        diesel::delete(devs.filter(uid.eq(_uid.to_string()))).execute(conn)
    }
}
@fuyingfuying

This comment has been minimized.

fuyingfuying commented May 21, 2016

@sgrif Please help me! I've tried some methods, but no way to solve the error. Is it a bug of diesel or a bug of the nightly rust compiler???

@sgrif

This comment has been minimized.

Member

sgrif commented May 21, 2016

At the moment we don't support having columns on structs called id that isn't the primary key

@fuyingfuying

This comment has been minimized.

fuyingfuying commented May 21, 2016

@sgrif Ok, it works, thanks for your help.

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