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

feat: bootstrap jiff-sqlx development #141

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

tisonkun
Copy link

This refers to #50.

Firstly, I considered to add a separated sqlx-jiff method, but soon I found that due to Rust's orphan rules, implementing sqlx's trait for Timestamp and other types requires the code to be located at the same crate (jiff). Otherwise we need an extra wrapper struct like:

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Timestamp(pub jiff::Timestamp);

I prefer to implement code in jiff and gate it with feature flags.

@BurntSushi This demonstrates the integration implementation direction. I'll complete other parts when we agree on this direction.

@BurntSushi
Copy link
Owner

#50 (comment) discusses this. And the orphan rule is taken into account there. The way to do this integration, short of getting it merged upstream in sqlx itself, is with a wrapper type in a jiff-sqlx crate. The comment linked explains how to do this.

Jiff is a "low level" crate. Having it depend on "high level" crates like sqlx would lead to all sorts of problems, especially if and when the time ever comes for sqlx to add Jiff integration on their end. It's really a non-starter.

Copy link
Author

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BurntSushi Yeah .. Adopt the other way now.

sqlx-jiff/src/lib.rs Outdated Show resolved Hide resolved
sqlx-jiff/src/lib.rs Outdated Show resolved Hide resolved
@BurntSushi
Copy link
Owner

Also, the crate should be called jiff-sqlx, since it lives with jiff.

@tisonkun
Copy link
Author

tisonkun commented Oct 11, 2024

Other type mapping to be wrapped once we agree on the pattern:

  • jiff::civil::Date <-> DATE
  • jiff::civil:Time <-> TIME
  • jiff:civil::DateTime <-> TIMESTAMP
  • jiff::Timestamp <-> TIMESTAMPTZ
  • jiff::SignedDuration <-> INTERVAL

Ref -

@tisonkun tisonkun changed the title feat: bootstrap sqlx-jiff development feat: bootstrap jiff-sqlx development Oct 14, 2024
@tisonkun
Copy link
Author

All bridges submitted. Note that integrations for PgRange and PgTimeTz cannot be added due to the orphan rule.

I'd suspend the task here to start jiff-sqlx with Postgres support first since it's my real use case and I'd avoid adding too many things at the very beginning.

@tisonkun tisonkun requested a review from BurntSushi October 23, 2024 07:21
@tisonkun
Copy link
Author

The failing wasm CI job doesn't seem to be relevant to this patch ..

@maxcountryman
Copy link

  • jiff::SignedDuration <-> INTERVAL

I'm curious why this wouldn't be jiff::Span? That's how I'm doing these conversions manually.

@tisonkun
Copy link
Author

@maxcountryman

It's possible to support multiple type mappings, so it's possible to support both Span and Duration.

However, PG's interval supports only months, days and microseconds parts. Span supports other units. I'm not sure if we can always assume 1 year=12 months, and 1 week=7days.

Anyway, we may support two types together.

@maxcountryman
Copy link

Span supports other units. I'm not sure if we can always assume 1 year=12 months, and 1 week=7days.

As I understand, Span doesn't assume 12 months == 1 year (ergo keeping each unit as a discrete property). I think that might be a reason to use Span here, right? (In particular, I believe Span is needed for full ISO 8601 support.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants