o.js icon indicating copy to clipboard operation
o.js copied to clipboard

Writing tools for compiling filters as a declarative description

Open GhostMayor opened this issue 5 years ago • 4 comments

What do you think about writing tools for compiling filters as a declarative description ? example: o('User') .filter(tools.eq('age', 20).and().startswith('name', 'A'))

GhostMayor avatar Sep 29 '19 22:09 GhostMayor

I like that idea. As the new version doesn't have a filter method we might want to put it on the query() function, as this allows to add any URLSearchParameter to the resource.

Smth like:

o('user').query(filterBuilder.eq('age', 20).and().startswith('name', 'A'))

And the filter builder returns an object like

{ 
  '$filter': 'age eq 20 and startswith(name, 'A')'
}

But how could you combine and/or like this (age eq 20 or age eq 19) and birthyear eq 1986?

janhommes avatar Oct 07 '19 08:10 janhommes

easy and(or(eq('age', 20), eq('age', 19)),eq('birthday',1986)) or or(eq('age', 20), eq('age', 19).and(eq('birthday',1986))) function returned object wich has methods or. er, and .. etc. or used toString() get complited query.

GhostMayor avatar Oct 07 '19 20:10 GhostMayor

I recently had to translate ag-grid's filter model to fit our odata service. It wasn't pretty. I'm not sure that kind code should be inside o.js But a library for building odata filters would be very useful as an opt-in add-on.

melgish avatar Jun 04 '20 19:06 melgish

Do you think of it as a secondary package? So you wouldn't add it as functionality this lib?

janhommes avatar Jun 06 '20 07:06 janhommes

odata-query support added.

janhommes avatar Sep 22 '23 08:09 janhommes