drupal-jsonapi-params icon indicating copy to clipboard operation
drupal-jsonapi-params copied to clipboard

add sql-like query strings for more convenience

Open mathislucka opened this issue 5 years ago • 2 comments

This implements a method allowing filters to be constructed from query strings.

It should mainly be more convenient and quicker to type for less complex filters.

Query strings can be written like so:

apiParams.addFilterQuery("pet = 'cat'")
apiParams.addFilterQuery("name CONTAINS 'Jo' memberOf first-name")

mathislucka avatar Jul 20 '20 23:07 mathislucka

@mathislucka thanks for the PR. This is an interesting concept.

So If i understand correctly,

apiParams.addFilter("pet", "cat") can be also written as, apiParams.addFilterQuery("pet = 'cat'")

apiParams.addFilter("name", "Jo", "CONTAINS", "first-name") can be also written as, apiParams.addFilterQuery("name CONTAINS 'Jo' memberOf first-name")

Following complications spring to my mind immediately:

  • Filter parameters are dependent on the operator. So some are single valued, some are multi valued, and some need exactly two parameters.
  • Operators can have space in between (e.g IS NULL)

Am trying to introduce placeholder support in upcoming release. After that I might pickup this feature request https://github.com/d34dman/drupal-jsonapi-params/issues/6 which lets you create DrupalJsonApiParams obj from previously encoded query object. I will keep this PR in mind, so that something like this could be introduced (but making no promises atm).

d34dman avatar Jul 23 '20 20:07 d34dman

Yes, your understandig is correct.

I understand your concerns but I think I addressed these complications:

  • the filter parameters can be passed as JSON representations of the parameters needed. A multi param filter would look like this: apiParams.addFilterQuery("date BETWEEN '[ 2020, 2021 ]'")

If the user does not pass the right amount of parameters or they have the wrong format an error will be thrown because addFilterQuery calls addFilter internally.

  • Operators with a space are not an issue because the regex used to split the string performs an exact match on all allowed operators.

mathislucka avatar Jul 23 '20 20:07 mathislucka

This has been in the backlog for a while and am moving to won't fix. I feel this could be a different library that can depend on drupal-jsonapi-params and achieve the results. (With separate readme and features/bug tracking).

d34dman avatar Jan 05 '23 15:01 d34dman