-
-
Notifications
You must be signed in to change notification settings - Fork 232
Add postgres range type #1007
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
Add postgres range type #1007
Conversation
|
The current dilemma is that I need to implement |
|
i see, shall we move that to a separate type crate? something like |
|
I will create a create for postgres only now, so the 2nd. And addressing the |
|
sounds good, thank you! I will take a closer look |
|
@tyt2y3 I started to move Range to the sea-query-postgres-types crate but I am struggling a bit.
If you can tell me what to change to fix the 1st point I can go on. |
|
thank you. the problem is
dont worry if you can't get CI to pass 100%, I will be able to fix that
this is un-avoidable so I'll set one of them to a very loose requirement, i.e. |
|
The next obstactle is how to implement I don't think this goes to a good direction, though. The other option is to implement the ToSql trait with using postgres-protocol, which used by postgres-types. https://docs.rs/postgres-protocol/latest/postgres_protocol/types/enum.Range.html Although I need to figure out how to construct that value for the sake of conversion. Because it has a lifetime and I don't want to have a RangeType with lifetimes. Also I am leaning toward the generic RangeType implementation, and during ToSql conversion we can restrict the types we accept. So we will have 6 different impl block like |
|
Finally I implemented by |
|
Okay, I think I am ready with that. I managed to run almost all checks with build-tools/rustclippy.sh |
|
The next obstactle - quite a big one - is to implement sqlx::Encode with RangeType. The problem is that in sea-query-sqlx we either make a PgRange conversion, which is not possible since our Value type is not generic. Or we need to implement Encode trait by hand in sea-query-postgres-types which is not easy since all the supporting types are private in sqlx. https://docs.rs/sqlx-postgres/0.8.6/src/sqlx_postgres/types/range.rs.html#291-293 I think this is the last step since other cases I feel are covered. |
|
thank you for the great work so far! for you personal use case, do you use |
|
I started to use this for a postgres database for a proof of concept, but to be honest I just wanted to contribute to know better Rust. |
tyt2y3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! if this works for you let's get this merged for now.
can create a followup PR for SQLx.
I think the strategy is to convert our own RangeType to sqlx's Range on the fly and call bind()
|
I've pushed some commits to adjust the crate structure |
PR Info
New Features
RangeTypeto implement Postgres range typeDoubts
hashable-valuefeatures. I put that in thewith_range.rswith-json