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

Missing trait bound on NaiveDateTime and print_sql!() #307

Closed
anp opened this Issue Apr 25, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@anp
Contributor

anp commented Apr 25, 2016

Per discussion on gitter:

print_sql!(pullrequest.select(sql::<(Date, BigInt)>("created_at::date as d, COUNT(*)"))
                       .filter(created_at.ge(since).and(created_at.le(until)))
                       .group_by(d))

Gives a compiler error:

$ cargo run
   Compiling rust-dashboard v0.1.0 (file:///home/adam/rust-projects/rust-dashboard)
<diesel macros>:5:5: 5:60 error: the trait bound `chrono::NaiveDateTime: diesel::types::ToSql<diesel::types::Timestamp, diesel::backend::Debug>` is not satisfied [E0277]
<diesel macros>:5 ) ; QueryFragment:: < $ crate:: backend:: Debug > :: to_sql (
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<diesel macros>:1:46: 1:69 note: in this expansion of debug_sql! (defined in <diesel macros>)
<std macros>:2:25: 2:56 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
<diesel macros>:1:25: 1:71 note: in this expansion of println! (defined in <std macros>)
src/reports/mod.rs:45:5: 47:37 note: in this expansion of print_sql! (defined in <diesel macros>)
<diesel macros>:5:5: 5:60 help: run `rustc --explain E0277` to see a detailed explanation
<diesel macros>:5:5: 5:60 help: the following implementations were found:
<diesel macros>:5:5: 5:60 help:   <chrono::NaiveDateTime as diesel::types::ToSql<diesel::types::Nullable<diesel::types::Timestamp>, DB>>
<diesel macros>:5:5: 5:60 help:   <chrono::NaiveDateTime as diesel::types::ToSql<diesel::types::Timestamp, diesel::pg::Pg>>
<diesel macros>:5:5: 5:60 note: required by `diesel::query_builder::QueryFragment::to_sql`
src/reports/mod.rs:45:5: 47:37 error: mismatched types:
 expected `std::result::Result<std::collections::BTreeMap<chrono::NaiveDate, i64>, error::DashError>`,
    found `()`
(expected enum `std::result::Result`,
    found ()) [E0308]
src/reports/mod.rs:45     print_sql!(pullrequest.select(sql::<(Date, BigInt)>("created_at::date as d, COUNT(*)"))
src/reports/mod.rs:46                        .filter(created_at.ge(since).and(created_at.le(until)))
src/reports/mod.rs:47                        .group_by(d))
src/reports/mod.rs:45:5: 47:37 note: in this expansion of print_sql! (defined in <diesel macros>)
src/reports/mod.rs:45:5: 47:37 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to 2 previous errors
error: Could not compile `rust-dashboard`.

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

sgrif added a commit that referenced this issue Dec 10, 2016

Add `ToSql<.., Debug>` for various date/time types
Most types do `impl<DB: Backend> ToSql<.., DB>`, but date/times have
backend specific implementations, and need an explicit impl for `Debug`.
I also noticed that we should have been calling `as_query` in the macro,
so that `debug_sql!(users)` can just work. I have left out tests for
this, mainly because I want to heavily revamp how the debug system works
so that this kind of mistake is completely impossible in the future.

Fixes #307.

sgrif added a commit that referenced this issue Dec 10, 2016

Add `ToSql<.., Debug>` for various date/time types
Most types do `impl<DB: Backend> ToSql<.., DB>`, but date/times have
backend specific implementations, and need an explicit impl for `Debug`.
I have left out tests for this, mainly because I want to heavily revamp
how the debug system works so that this kind of mistake is completely
impossible in the future.

Fixes #307.

@sgrif sgrif closed this in #542 Dec 10, 2016

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