SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.57k stars 461 forks source link

DateTimeUtc is recognized as TimestampWithTimeZone #2090

Open xtexChooser opened 5 months ago

xtexChooser commented 5 months ago

As the document: image DateTimeUtc should be regarded as Timestamp, however, it is regarded as TimestampWithTimeZone

From the following Model:

    #[sea_orm(column_type = "Timestamp", nullable, default_value = "None")]
    pub col: Option<DateTimeUtc>,

I can get this error: Query Error: error occurred while decoding column \"col\": mismatched types; Rust type core::option::Option<chrono::datetime::DateTime<chrono::offset::utc::Utc>> (as SQL type TIMESTAMPTZ) is not compatible with SQL type TIMESTAMP

On PostgresQL, TIMESTAMP is the same as DATETIME. col, which is with Timestamp column type, should be decoded as the same as DateTime. However the current behaviour should be kept when using with MySQL.

tyt2y3 commented 4 months ago

I see, but sadly in Entity definition there is no way to know whether it is MySQL or Postgres. MySQL does not have timestamptz. But I do think we can specifically convert Timestamp to DateTime<Utc> on the MySQL connector (it's the same data with a different type hint, afterall).

PR would be appreciated.