Closed
Description
Bug Description
SQLx uses chrono
types even if time
feature is specified.
In Cargo.toml
:
sqlx = { version = "0.7", features = [ "runtime-tokio", "postgres", "tls-rustls", "uuid", "time" ] }
Column in Postgres:
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
Rust model:
#[derive(sqlx::FromRow, Clone, Debug)]
struct Entry {
...
pub created_at: time::OffsetDateTime,
}
Query:
SELECT
...
created_at
FROM entries
LIMIT 1
When I run cargo sqlx prepare
, it finishes without errors.
Then, when I compile the binary, I get the following error:
error[E0277]: the trait bound `OffsetDateTime: From<DateTime<Utc>>` is not satisfied
the trait `From<DateTime<Utc>>` is not implemented for `OffsetDateTime`
As soon as I replace time::OffsetDateTime
with chrono::DateTime<Utc>
in the Rust type without changing anything else, the binary compiles.
Info
- SQLx version:
0.7.1
- SQLx features enabled:
"runtime-tokio", "postgres", "tls-rustls", "uuid", "time"
- Database server and version:
Postgres 15.2
- Operating system:
macOS 13.4
rustc --version
:rustc 1.70.0 (90c541806 2023-05-31)