diesel = { git = "https://github.com/diesel-rs/diesel", tag ="v1.3.1", default-features = false, features = ["chrono", "serde_json", "uuid", "network-address", "numeric", "r2d2", "postgres"] }
let results = contracts.limit(5).load::<Contract>(&connection).expect(
| ^^^^ the trait `diesel::Queryable<diesel::sql_types::Numeric, diesel::pg::Pg>` is not implemented for `bigdecimal::BigDecimal`
Codes:
main.rs
#[macro_use]
extern crate diesel;
extern crate bigdecimal;
extern crate chrono;
extern crate dotenv;
extern crate serde;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv;
use std::env;
mod schema;
use bigdecimal::BigDecimal;
use chrono::{DateTime, Utc};
use diesel::prelude::*;
use diesel::*;
use serde_json::Value;
#[derive(Queryable)]
pub struct Contract {
pub id: i32,
pub conditions: Value,
pub state: i16,
pub self_stake: BigDecimal,
pub rival_stake: BigDecimal,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
pub fn establish_connection() -> PgConnection {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
PgConnection::establish(&database_url).expect(&format!("Error connecting to {}", database_url))
}
fn main() {
let connection = establish_connection();
use self::diesel::prelude::*;
use self::schema::contracts::dsl::*;
let results = contracts
.limit(5)
.load::<Contract>(&connection)
.expect("Error loading posts");
println!("Displaying {} posts", results.len());
for post in results {
println!("{}", post.id);
println!("----------\n");
println!("{}", post.conditions);
println!("{}", post.self_stake);
println!("{}", post.rival_stake);
}
}
schema.rs
table! {
contracts (id) {
id -> Int4,
conditions -> Json,
state -> Int2,
self_stake -> Numeric,
rival_stake -> Numeric,
created_at -> Timestamptz,
updated_at -> Timestamptz,
}
}
NOTE: I'm noob.
That sounds like you are using different versions of bigdecimal. Please doublecheck that your crate depends on the same version as diesel. (Cargo tree could be handy for this)
Closed because this does not contain something actionable for the diesel team.
(If this does not solve the issue, just continue asking here or even better in our gitter room)
thank you. fixed
It would be good if diesel re-exported BigDecimal when the numeric feature is enabled, then there's no chance of a clash.
thanks a lot
Most helpful comment
It would be good if diesel re-exported BigDecimal when the numeric feature is enabled, then there's no chance of a clash.