cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Feature request: Ability to choose chrono instead of time #209

Open jacobsvante opened 1 year ago

jacobsvante commented 1 year ago

Currently time fields seem bound to the time library. Working with time zones with time is a PITA so I was saddened to see that cornucopia does not support chrono.

Might implement this myself after Easter. @LouisGariepy @Virgiel Should I implement as a crate feature, e.g. chrono + time where time is default?

Or maybe #207 would solve this?

Virgiel commented 1 year ago

The simplest solution for now, would be to use SystemTime for timestamp and timestamptz and let the user match to time or chrono. Latter we could add a feature to make this more ergonomic.

In postgres, timestamps are just microseconds and dates are just number of day. We should use types that match this reality.

jacobsvante commented 1 year ago

I didn't know SystemTime can be used to store historical dates..?

Either way I think the feature approach I mentioned might make more sense though, as postgres-types does it this way. I don't think it makes use of SystemTime at all.

LouisGariepy commented 1 year ago

@jacobsvante I didn't add chrono support originally because of the whole unsoundness debacle. I tried to not include crates with serious known vulnerabilities.

This has been fixed in version 4.20, but only if you disable default features and don't enable the oldtime feature. The sound implementation will be the default in a future 0.5.0 release https://github.com/chronotope/chrono/issues/970.

In any case, disregarding the soundness issues, this will probably be actionable via the new codegen architecture #211.

jacobsvante commented 1 year ago

Okay, sounds good 👍