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

Impl Queryable, AsExpression, From/ToSql for ranges from std #1971

Closed
wants to merge 7 commits into from

Conversation

0nkery
Copy link

@0nkery 0nkery commented Jan 29, 2019

Hi, I implemented Queryable, Expression, FromSql, ToSql traits for Range* types from std.

It would be awesome to have these types when working with various intervals in Diesel.

@weiznich weiznich requested a review from a team January 29, 2019 15:26
@0nkery
Copy link
Author

0nkery commented Jan 29, 2019

RangeInclusive and RangeToInclusive seem to fail in the tests because the inferred Bound is always Excluded.

@weiznich
Copy link
Member

From a short look over the code: It seems like the FromSql implementations could possibly fail if the range does not have the right format. Our general policy for FromSql implementations included in diesel core is that they should basically never fail.

That means adding the ToSql implementations and related stuff is fine, but adding FromSql is against that policy.

cc @diesel-rs/core

@0nkery
Copy link
Author

0nkery commented Jan 30, 2019

Seems like it's good to have precise Rust type to represent ranges with specific bounds. But I could remove some (redundant maybe) types like RangeInclusive and RangeToInclusive.

If I leave out FromSql these types cannot be Queryable, I guess?

@weiznich
Copy link
Member

Seems like it's good to have precise Rust type to represent ranges with specific bounds. But I could remove some (redundant maybe) types like RangeInclusive and RangeToInclusive.

Having those is additional types is no problem in my opinion.

If I leave out FromSql these types cannot be Queryable, I guess?

Right, not implementing FromSql implies that Queryable is not supported.

@0nkery
Copy link
Author

0nkery commented Jan 30, 2019

That means adding the ToSql implementations and related stuff is fine, but adding FromSql is against that policy.

I see these types as kind of validation. What is validation policy? Maybe FromSql-like impls (maybe for completely separate trait) should be added to another crate?

@weiznich
Copy link
Member

I see these types as kind of validation. What is validation policy? Maybe FromSql-like impls (maybe for completely separate trait) should be added to another crate?

The policy contains 2 rules:

  • It's a commonly used type
  • The conversion cannot fail for all possible values of that type.

The second rule is not fulfilled because postgres range could contain values that are not valid for a specific Range* type in rust. (For example [0,1] for Range<i32>)

I do not think that a FromSql like trait would be useable in this context without also extending the Connection trait.

@c410-f3r
Copy link
Contributor

Any news?

@weiznich
Copy link
Member

@c410-f3r I do not see any updates here so why ask this question?

@c410-f3r
Copy link
Contributor

c410-f3r commented Apr 27, 2020

It is worth to ask for updates after fifteen months of inactivity. Perhaps it will bring light to this PR, drawing people's attention; perhaps it will serve as a motivation for the author to finish his work; perhaps I will try to fix the commented problems as this feature is in my interest.

Discouraging participation may lead to stagnation and stalled PR's. Nevertheless, I can happily remove my question if it is indeed not desired.

@weiznich
Copy link
Member

@c410-f3r It's much about the wording here. I consider just asking Any news? on an old stale thread as a question similar to "Why is this not fixed yet?". You really should consider that this project is run by volunteers in their free time. A better way would be to just ask the OP if they plan to continue on their work here and communicate that you would be interested in doing that on your own if not.

From a technical point of view: My concerns raised here are remaining valid and are not answered yet.

@0nkery 0nkery closed this by deleting the head repository May 14, 2024
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.

None yet

3 participants