janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
241 stars 58 forks source link

Writing tools for compiling filters as a declarative description #98

Closed GhostMayor closed 1 year ago

GhostMayor commented 5 years ago

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'))

janhommes commented 5 years ago

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?

GhostMayor commented 5 years ago

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.

melgish commented 4 years ago

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.

janhommes commented 4 years ago

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

janhommes commented 1 year ago

odata-query support added.