我无法使用 Rocket 和 Diesel 从填充的 mySQL 数据库中检索日期时间。
这是我的模型:
extern crate chrono;
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use schema::chrisms;
use diesel::sql_types::Datetime;
use self::chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
#[derive(Serialize, Deserialize, Queryable)]
pub struct Chrisms {
pub entity_ekklesia_location_id: i32,
pub serie_number: Option<String>,
pub seat_number: Option<String>,
pub date: Datetime,
pub year: i32,
pub deleted: bool,
pub entity_chrism_location_id: Option<i32>,
pub entity_chrism_location_description: Option<String>,
pub entity_rel_mec_id: Option<i32>,
pub entity_rel_mec_description: Option<String>,
pub created_by_user_id: Option<i32>,
pub updated_by_user_id: Option<i32>,
pub deleted_by_user_id: Option<i32>,
pub created_at: Datetime,
pub updated_at: Datetime,
pub id: i32,
}
impl Chrisms {
pub fn read(connection: &MysqlConnection) -> Vec<Chrisms> {
chrisms::table.load::<Chrisms>(connection).unwrap()
}
}
我的架构:
table! {
chrisms (id) {
entity_ekklesia_location_id -> Integer,
serie_number -> Nullable<Varchar>,
seat_number -> Nullable<Varchar>,
date -> Datetime,
year -> Integer,
deleted -> Bool,
entity_chrism_location_id -> Nullable<Integer>,
entity_chrism_location_description -> Nullable<Varchar>,
entity_rel_mec_id -> Nullable<Integer>,
entity_rel_mec_description -> Nullable<Varchar>,
created_by_user_id -> Nullable<Integer>,
updated_by_user_id -> Nullable<Integer>,
deleted_by_user_id -> Nullable<Integer>,
created_at -> Datetime,
updated_at -> Datetime,
id -> Integer,
}
}
这会产生错误:
1. the trait `_IMPL_SERIALIZE_FOR_TemplateContext::_serde::Serialize` is not
implemented for `diesel::sql_types::Datetime`
-required by `_IMPL_SERIALIZE_FOR_TemplateContext::_serde::ser::SerializeStruct::serialize_field`
2. the trait `_IMPL_SERIALIZE_FOR_TemplateContext::_serde::Deserialize<'_>` is
not implemented for `diesel::sql_types::Datetime`
- required by `_IMPL_SERIALIZE_FOR_TemplateContext::_serde::de::SeqAccess::next_element`
- required by `_IMPL_SERIALIZE_FOR_TemplateContext::_serde::de::MapAccess::next_value`
3. the trait `diesel::Queryable<diesel::sql_types::Datetime,
diesel::mysql::Mysql>` is not implemented for `diesel::sql_types::Datetime`
- required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<_, models::chrisms::Chrisms>` for `schema::chrisms::table`
我该如何解决?我测试了一堆用途,比如diesel:mysql_types
,rocket:config
等等,似乎不是问题所在。