jirutka/rsql-parser

Is it possible to use arguments as selectors?

AnbazhakanSubramaniam opened this issue · 1 comments

Hi, I'm trying to check if the values of two attributes in the database are identical.
Currently the "arguments" field supports only the values of the entries.

So, Is it possible to use/extend the "arguments" as "selectors"?

For ex: The database entry has the following

	Name : "Item1"
		Attributes:
		ParameterA : "ParamA1"
		ParameterB : "ParamB1"
		
	Name : "Item2"
		Attributes:
			ParameterA : "ParamA2"
			ParameterB : "ParamA2"

Here, the query Attributes.ParameterA=="ParamA1" works fine and fetches the "Item1" as a result.

Now, I would like to query the list of "Items" whose Parameters are identical.

Query will be, Attributes.ParameterA==Attributes.ParameterB should fetch "Item2"

Kindly let me know if its feasible.

Thanks

Maybe a bit tricky but thanks to custom operators you can do what you need.
Imagine the generic regular custom operator =xyz= expecting a constant argument (possibly casted).
Then imagine its mirror version =xyzat= (where suffix 'at' means 'at path') expecting - guess what - a path (not casted, it's just a regular string as for any other selector).
I got it working by taking inspiration from all the code at #29.
I suggest you to read all the thread and take the best from each sample code.
Then to parse the selector argument you can reuse a slightly modified version of the parseProperty method that takes the path in input, instead of using the instance variable property.
Hope that helps.