techniq/odata-query

IN operator

techniq opened this issue · 3 comments

Currently we explode an in operator into multiple eq/or. For example:

const filter = { SomeProp: { in: [1, 2, 3] } };
const actual = buildQuery({ filter });
=> '?$filter=(SomeProp eq 1 or SomeProp eq 2 or SomeProp eq 3)'

When attempting to do this with a lot of values, I received a 414 (URI Too Long) error. Upon more researching, I found this proposal to support an actual in operator, and it appears to be accepted.: https://issues.oasis-open.org/browse/ODATA-556

I then tested against my WebApi/OData backend and it appears to work when using $filter=Id in (1,2,3,4,5) or $filter=Code in ('abc','def','ghi')

While not in the 4.0 spec, I just found mention of it in the 4.01 spec part1 and part 2.

Considering supporting this and releasing as a breaking change (6.0.0)

This commit seems to supply IN support, but surprisingly I'm still on 7.0.0 and it looks like this wasn't implemented till 7.0.1 - OData/WebApi@116e20d

Hi, the issue seam to be resolved. is it possible to make a new version of this. currently i have built a wrapper to the lib but it would be awesome if the lib could be updated :)

@ulfdahlstrand are you able to share your code for the wrapper? I have the same issue right now and it would safe me some time if you could share your wrapper :) Thx!

Edit: I found out you can just specify filters as strings, so I did that to build my own 'in()' filter by doing this:

const inString = ids.reduce(
    (total, id) => (total === '' ? `'${id}'` : `${total}, '${id}'`),
    '',
);
  queries.filter = [
    `test_id in (${inString})`,
    queries.filter,
  ];