Skip to content
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

Nullable<diesel::sqlite::sql_types::Timestamptz> throws trait not implement errors #3846

Open
2 of 3 tasks
baarkerlounger opened this issue Oct 28, 2023 · 0 comments
Open
2 of 3 tasks

Comments

@baarkerlounger
Copy link

baarkerlounger commented Oct 28, 2023

Setup

Versions

  • Rust: rustc 1.71.1 (eb26296b5 2023-08-03)
  • Diesel: 2.1.3
  • Database: Sqlite
  • Operating System Debian Trixie (Testing)

Feature Flags

  • diesel: ["sqlite", "chrono"]

Problem Description

Using the type Nullable<diesel::sqlite::sql_types::Timestamptz> together with the Rust type Option<chrono::DateTime<chrono::Local>> throws compiler trait not implemented errors. Using diesel::sql_types::TimestamptzSqlite does not, even though they should be equivalent.

What are you trying to accomplish?

Loading a Nullable Sqlite Timestamp column into a chrono datetime option field.

What is the expected output?

No compiler errors

What is the actual output?

error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Add` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
11 | |         by -> Nullable<Text>,
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |____________^ the trait `diesel::sql_types::ops::Add` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Add`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Add`
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Add` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::sql_types::ops::Add` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Add`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Add`
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Rhs: diesel::Expression` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::Expression` is not implemented for `Rhs`
   |
   = note: required for `Rhs` to implement `AsExpression<diesel::sql_types::Nullable<_>>`
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `Rhs`
   |
16 | }, Rhs: diesel::Expression
   |  +++++++++++++++++++++++++
 
error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Sub` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
11 | |         by -> Nullable<Text>,
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |____________^ the trait `diesel::sql_types::ops::Sub` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Sub`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Sub`
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Sub` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::sql_types::ops::Sub` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Sub`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Sub`
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Add` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::sql_types::ops::Add` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Add`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Add`
note: required for `columns::time` to implement `std::ops::Add<Rhs>`
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |         ^^^^
...  |
15 | |     }
16 | | }
   | |_^
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Rhs: diesel::Expression` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::Expression` is not implemented for `Rhs`
   |
   = note: required for `Rhs` to implement `AsExpression<diesel::sql_types::Nullable<_>>`
note: required for `columns::time` to implement `std::ops::Add<Rhs>`
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |         ^^^^
...  |
15 | |     }
16 | | }
   | |_^
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `Rhs`
   |
16 | }, Rhs: diesel::Expression
   |  +++++++++++++++++++++++++
 
error[E0277]: the trait bound `Timestamptz: diesel::sql_types::ops::Sub` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::sql_types::ops::Sub` is not implemented for `Timestamptz`
   |
   = help: the following other types implement trait `diesel::sql_types::ops::Sub`:
             BigInt
             diesel::sql_types::Date
             diesel::sql_types::Double
             diesel::sql_types::Float
             diesel::sql_types::Integer
             diesel::sql_types::Interval
             diesel::sql_types::Nullable<T>
             diesel::sql_types::Numeric
           and 3 others
   = note: required for `diesel::sql_types::Nullable<Timestamptz>` to implement `diesel::sql_types::ops::Sub`
note: required for `columns::time` to implement `std::ops::Sub<Rhs>`
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |         ^^^^
...  |
15 | |     }
16 | | }
   | |_^
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
 
error[E0277]: the trait bound `Rhs: diesel::Expression` is not satisfied
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
15 | |     }
16 | | }
   | |_^ the trait `diesel::Expression` is not implemented for `Rhs`
   |
   = note: required for `Rhs` to implement `AsExpression<diesel::sql_types::Nullable<_>>`
note: required for `columns::time` to implement `std::ops::Sub<Rhs>`
  --> hackgregator/src/schema.rs:3:1
   |
3  | / diesel::table! {
4  | |     items (id) {
5  | |         id -> Integer,
6  | |         #[sql_name = "type"]
...  |
12 | |         time -> Nullable<diesel::sqlite::sql_types::Timestamptz>,
   | |         ^^^^
...  |
15 | |     }
16 | | }
   | |_^
   = note: this error originates in the macro `diesel::table` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `Rhs`
   |
16 | }, Rhs: diesel::Expression
   |  +++++++++++++++++++++++++
 
For more information about this error, try `rustc --explain E0277`.
error: could not compile `hackgregator` (bin "hackgregator") due to 9 previous errors

Steps to reproduce

// schema.rs

diesel::table! {
    items (id) {
        id -> Integer,
        time -> Nullable<diesel::sql_types::TimestamptzSqlite>,
    }
}
// items.rs

use crate::schema::items;
use chrono::{DateTime, Local};
use diesel::{prelude::*, Insertable, Queryable};

#[derive(Queryable, Insertable, AsChangeset, Selectable, Identifiable, Debug)]
pub struct Item {
    pub id: i32,
    pub time: Option<DateTime<Local>>,
}

Checklist

  • I have already looked over the issue tracker and the discussion forum for similar possible closed issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants