Can't get Diesel to output null Timestamp column in SQLite table
I am trying to use Diesel's inference feature to work with a SQLite table that contains a column with zero timestamps. A complete example is available in an older version of this GitHub project .
The table is books
defined as follows:
create table books (
id integer not null primary key,
title varchar null,
save_date timestamp null
)
I am trying to query it with the following structure:
pub mod domain { use chrono::naive; #[derive(Queryable)] pub struct Book { id : i32, title : Option<String>, save_date : Option<naive::NaiveDateTime>, } }
However, when I try to execute a query like in:
fn main() { use self::schema::books::dsl::*; let database_url = env::var("DATABASE_URL").unwrap(); let conn = sqlite::SqliteConnection::establish(&database_url).unwrap(); let res = books.load::<domain::Book>(&conn); }
The following error message appears:
error[E0277]: the trait bound `std::option::Option<chrono::NaiveDateTime>: diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Timestamp>, _>` is not satisfied --> src/main.rs:32:21 | 32 | let res = books.load::<domain::Book>(&conn); | ^^^^ the trait `diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Timestamp>, _>` is not implemented for `std::option::Option<chrono::NaiveDateTime>` | = help: the following implementations were found: <std::option::Option<chrono::naive::date::NaiveDate> as diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Date>, DB>> <std::option::Option<chrono::naive::time::NaiveTime> as diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Time>, DB>> <std::option::Option<chrono::naive::datetime::NaiveDateTime> as diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Timestamp>, DB>> <std::option::Option<bool> as diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Bool>, DB>> and 26 others = note: required because of the requirements on the impl of `diesel::types::FromSqlRow<(diesel::types::Integer, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Timestamp>), _>` for `(i32, std::option::Option<std::string::String>, std::option::Option<chrono::NaiveDateTime>)` = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::types::Integer, diesel::types::Nullable<diesel::types::Text>, diesel::types::Nullable<diesel::types::Timestamp>), _>` for `domain::Book`
I do not understand why the implementation for is chrono::naive::datetime::NaiveDateTime
not matched and what should I do to make this happen.
I am using the stable toolchain which is currently 1.18.0 and these are my dependencies:
[dependencies]
chrono = "0.4.0"
diesel = { version = "0.13.0", features = [ "chrono", "sqlite" ] }
diesel_codegen = { version = "0.13.0", features = [ "sqlite" ] }
dotenv = "0.9.0"
source to share
No one has answered this question yet
See similar questions:
or similar: