edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
214 stars 26 forks source link

Support chrono DateTime as Queryable #263

Closed hongquan closed 1 year ago

hongquan commented 1 year ago

When define a struct with a DateTime<Utc> field, that struct can not be used as query result.

This is a reproducible repo: https://bitbucket.org/hongquan/edgedb-chrono.

When building it, we get this error:

❯ cargo build
   Compiling edgedb-chrono v0.1.0 (/home/quan/Works/Hobby/edgedb-chrono)
error[E0277]: the trait bound `DateTime<Utc>: decode::queryable::scalars::DecodeScalar` is not satisfied
 --> src/main.rs:5:17
  |
5 | #[derive(Debug, Queryable)]
  |                 ^^^^^^^^^ the trait `decode::queryable::scalars::DecodeScalar` is not implemented for `DateTime<Utc>`
  |
  = help: the following other types implement trait `decode::queryable::scalars::DecodeScalar`:
            String
            SystemTime
            bool
            edgedb_protocol::model::BigInt
            edgedb_protocol::model::ConfigMemory
            edgedb_protocol::model::DateDuration
            edgedb_protocol::model::Datetime
            edgedb_protocol::model::Decimal
          and 12 others
  = note: required for `DateTime<Utc>` to implement `Queryable`
  = note: this error originates in the derive macro `Queryable` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `edgedb-chrono` (bin "edgedb-chrono") due to previous error
AlexDaniel commented 1 year ago

So, is there currently any way to work with datetime? I see some code in the repo for datetimes, but if chrono doesn't work, then what's the intended workflow?

Update: actually, you can use Datetime from use edgedb_protocol::model::Datetime, and it sorta works.

AlexDaniel commented 1 year ago

Apparently, there was https://github.com/edgedb/edgedb-rust/issues/198 and chrono types should now be supported. I have added "chrono" as a feature to edgedb-protocol in my Cargo.toml and yet I get the same error as the OP. In fact, the OP reproduction repo has the feature enabled too. Something is wrong. @tailhook ?

Dhghomon commented 1 year ago

This should be working now thanks to #274 , closing

darshanDevrai commented 5 months ago

Hi @AlexDaniel @Dhghomon @hongquan,

I am still facing the same issue. Here's my Cargo.toml.

chrono = { version = "0.4.26", features = ["serde"] }
edgedb-derive = "0.5.1"
edgedb-protocol = { version = "0.6.0", features = ["chrono", "with-chrono"] }
edgedb-tokio = "0.5.0"