使用柴油箱进行装载返回错误以便与MySQL数据库交互:
the trait bound `chart_models::Chart: diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Text), _>` is not satisfied
the trait `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Text), _>` is not implemented for `chart_models::Chart`
note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<_, chart_models::Chart>` for `diesel::query_builder::SelectStatement<schema::chart::table, diesel::query_builder::select_clause::DefaultSelectClause, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<diesel::expression::operators::Eq<schema::chart::columns::id, diesel::expression::bound::Bound<diesel::sql_types::Integer, i32>>>>`rustc(E0277)
chart_models.rs(33, 14): the trait `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Numeric, diesel::sql_types::Integer, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Text), _>` is not implemented for `chart_models::Chart`
表架构:
table! {
chart (id) {
id -> Integer,
types -> Integer,
prices -> Decimal,
time -> Nullable<Varchar>,
date -> Varchar,
}
}
chart_models.rs文件:
use diesel;
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use schema::chart;
use schema::chart::dsl::chart as all_chart;
use rust_decimal::Decimal;
pub struct Chart {
pub id: i32,
pub types: i32,
pub prices: Decimal,
pub time: String,
pub date: String,
}
impl Chart {
pub fn show(id: i32, conn: &MysqlConnection) -> Vec<Chart> {
all_chart
.find(id)
.load::<Chart>(conn)
.expect("Error loading chart infos")
}
}
有人可以帮助您发现问题吗?
答案 0 :(得分:0)
您似乎需要Charts结构的Queryable特性。
您可以使用以下派生属性添加它:
#[derive(Queryable)]
pub struct Chart {
pub id: i32,
pub types: i32,
pub prices: Decimal,
pub time: String,
pub date: String,
}
错误消息的重要部分是第二行:
the trait `diesel::Queryable<...(details of your struct)...> is not implemented for `chart_models::Chart`
答案 1 :(得分:0)
您需要确保您的结构与架构中的类型兼容:
pub struct Chart {
pub id: i32,
pub types: i32,
pub prices: Decimal,
pub time: Option<String>, // time must be an Option given it's Nullable in the schema
pub date: String,
}