drupal-jsonapi-params
                                
                                 drupal-jsonapi-params copied to clipboard
                                
                                    drupal-jsonapi-params copied to clipboard
                            
                            
                            
                        add sql-like query strings for more convenience
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 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).
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.
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).