hypersistence-utils icon indicating copy to clipboard operation
hypersistence-utils copied to clipboard

Postgres - Arrays of Ranges mapping

Open jhaygood86 opened this issue 4 years ago • 7 comments

I want to be able to map List<Range<LocalDate>> (or even Range<LocalDate>[]) to a daterange[]

I was able to do it locally with some hackery (I made a ListRangeArrayType extends AbstractArrayType<Object>) that works for reading at least that also had to construct the Range's manually.

jhaygood86 avatar Feb 17 '21 16:02 jhaygood86

If you think it's useful, send me a Pull Request with the implementation and I'll review it when I have some time.

vladmihalcea avatar Feb 17 '21 18:02 vladmihalcea

@jhaygood86 I made a toy example for the Postgres v14 multirange types. I could possibly provide a PR to this repository with an implementation, but this would require you to use Postgres 14.

asdm90 avatar Aug 18 '22 13:08 asdm90

The project can use PostgreSQL 14. It's just a small change in the Testcontainers. So, you can provide the PR, as it can be tested.

vladmihalcea avatar Aug 18 '22 13:08 vladmihalcea

@jhaygood86 What is your use case for this? Do you expect to be able to perform any logic similar to the built-in Postgres functions on multiranges or are you just interested in an equivalent datatype in java to map to an from the database using Hibernate?

asdm90 avatar Sep 06 '22 08:09 asdm90

Bare minimum is mapping a date range array in a Postgres result set to an equivalent Java type when running queries.

jhaygood86 avatar Sep 06 '22 10:09 jhaygood86

@jhaygood86 I have an idea of how to implement this, but it would be somewhat similar to the immutable Range type already present and would require a bit of a refactoring of the Range class. It should be backwards-compatible with the current API for Range though so no problem there.

I suspect that would be satisfactory to your needs?

Which Hibernate version do you target ?

asdm90 avatar Sep 06 '22 10:09 asdm90

Yes

On Tue, Sep 6, 2022, 6:30 AM asdm90 @.***> wrote:

@jhaygood86 https://github.com/jhaygood86 I have an idea of how to implement this, but it would be somewhat similar to the immutable Range type already present and would require a bit of a refactoring of the Range class. It should be backwards-compatible with the current API for Range.

I suspect that would be satisfactory to your needs?

— Reply to this email directly, view it on GitHub https://github.com/vladmihalcea/hibernate-types/issues/297#issuecomment-1237967941, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACX7SLXQ6TAH3PT6VDZ26TV44MNNANCNFSM4XYVCLHA . You are receiving this because you were mentioned.Message ID: @.***>

jhaygood86 avatar Sep 06 '22 10:09 jhaygood86