Skip to content

Use of EctoRange.Num #13

@pcapel

Description

@pcapel

Hello!

Awesome little library, thanks for building it!

I had some questions about the use of the EctoRange.Num type. I've got some numeric ranges that I want to store and for one of them, I'd like to represent it as '[N, infinity]'::numrange. The issue I'm having is figuring out how to get this translated into a valid changeset for the entry.

Additionally, it seems that if you write an empty range, reading it back will fail in loading due to no matching handler for an :empty atom.

Happy to help out with a PR. I've dug around a bit an have some ideas about how this might be addressed, but I wanted to get some thoughts.

Namely, it looks like the cast logic is pretty restrictive in terms of the types it expects. So by widening that out, we could address the issue of infinity.

Loading seems like it just needs a case for normalize_range to handle an empty range.

I was also curious if adding in a parser for string definitions to be cast to ranges would be something you'd be interested in? That is, EctoRange.from("[1,5)") -> %Postgrex.Range{upper: 5, lower: 1, upper_inclusive: true, lower_inclusive: false}. Just a thought. It would make working with numeric ranges a fair bit simpler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions