belamov / postgres-range

Laravel package for PostgreSQL range types support
MIT License
34 stars 3 forks source link

How to check if my number within the range of the IntegerRange object #23

Open 4n70w4 opened 2 years ago

4n70w4 commented 2 years ago

Hi! Thanks for package.

For example I have code:

$range = new IntegerRange('1', 1_000, '[', ']');

and I want to get a true or false answer, whether my value is in this range like this:

$range->check(10); \\ true
$range->check(10000); \\ false

but I did not find such a method to do it. It will be very helpful!

belamov commented 2 years ago

hello! I dont think this is in scope of this package, it is not range library

you can implement this logic in your code, it is pretty staightforward

also note that you can query your models with these methods

4n70w4 commented 2 years ago

I know that I can do it myself in my code. I did this before I created this issue. I just shared with you my thoughts and experience using your package.

You did not understand. I can't do it in query, since this range needs to be checked for a model that has not yet been saved in the database.

For example, I have a bool in_rank field in a table. I need to calculate its value before writing to the database.

I do not like and do not want to do this, but such a requirement.

belamov commented 2 years ago

got you, thanks! ill look up into this when i have time, but contributions are welcome :)