Skip to content
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

Improve parameters for the RQL contains operator #603

Closed
AaronTrippaers opened this issue Apr 22, 2022 · 2 comments · Fixed by #604
Closed

Improve parameters for the RQL contains operator #603

AaronTrippaers opened this issue Apr 22, 2022 · 2 comments · Fixed by #604
Labels
enhancement New feature or request

Comments

@AaronTrippaers
Copy link
Contributor

What do I want to achieve?

Change the RQL function signature of contains to and execute the and function on the list:

contains: (field: string, ...list: RQLString[]) => RQLBuilder;

Why is it better?

  • The and is always needed when providing an expression. If only one check is performed the contains operator can be easily removed.
// Following operation:
.contains("data",rqlBuilder().gt("heartrate", "60").intermediate())
// Can be replaced with:
gt("data.heartrate","60")
  • The function signature above makes it in my opinion more clear that the checks have to be given separately and that the following code won't work.
.contains("data",rqlBuilder().gt("heartrate", "60").lt("heartrate", "90").intermediate())
  • It makes the code more concise and readable by removing the and function and its intermediate call. See the difference between the 2 examples below.

Before:

.contains(
    "data",
    rqlBuilder().and(
            rqlBuilder().gt("heartrate", "60").intermediate(),
            rqlBuilder().lt("heartrate", "90").intermediate()
    ).intermediate()
)

After:

.contains(
    "data",
    rqlBuilder().gt("heartrate", "60").intermediate(),
    rqlBuilder().lt("heartrate", "90").intermediate()
)
@AaronTrippaers AaronTrippaers added the enhancement New feature or request label Apr 22, 2022
@FilipAben
Copy link
Contributor

I agree it would be better, as long as it's done in a way that it doesn't break existing applications.

So

.contains(
    "data",
    rqlBuilder().and(
            rqlBuilder().gt("heartrate", "60").intermediate(),
            rqlBuilder().lt("heartrate", "90").intermediate()
    ).intermediate()
)

should still work fine

@AaronTrippaers
Copy link
Contributor Author

@FilipAben I have a proposal PR here: #604. It still supports the example you gave. The url will just contain an unnecessary but not breaking and statement as you can see below:

?contains(and(and(gt(heartrate,60),lt(heartrate,60))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants