I have a Spring Boot application to implement a RESTful API. One of the GET requests have two query parameters: from and until (of type date). Those parameters are optional, so user-agents can send both, none or just one of them.
The query parameters are then used ("down") in the flow to filter data sets by (a typical) created_on column in the database using a BETWEEN clause. The problem for me is that I'm using Spring Data JPA, so any nullable value will fail the query with some exception.
So I was thinking to:
- Normalize the values when received (
from, ifnullwill be set toInstant.MIN;until, ifnullwill be set toInstant.now), then I can keep the query without modification - Leave the values as they come, and have 4 queries: when both are
null, whenfromis notnull, whenuntilis notnull, when none arenull
Not sure if there is a better alternative. I can't do a custom SQL query for the moment — that's a constraint on my end.
Eventually the first alternative is easier, but I'm not sure if going with those defaults is a good idea. I would like better to execute the SQL query accordingly, but having a wide range (in case non of the parameters are sent) should have certain impact on the performance of the query.
Any advice?