Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url filters AND OR BETWEEN #199

Open
wcodba opened this issue Nov 28, 2016 · 4 comments
Open

Url filters AND OR BETWEEN #199

wcodba opened this issue Nov 28, 2016 · 4 comments

Comments

@wcodba
Copy link

wcodba commented Nov 28, 2016

Hi,

I understood if I request /resource/?name=["rob","henry"] i will get :
where name in ("rob","henry")

what about chaining AND, OR, and BETWEEN ?
I mean I've a field date, how to query thisdate between DATE1 and DATE2 ?

I there a full documentation on query parameters available ?

Thanks

@sdebionne
Copy link
Contributor

sdebionne commented Jan 5, 2017

I mean I've a field date, how to query thisdate between DATE1 and DATE2 ?

I have the exact same use case and after reading the documentation, it does not seem to be possible out of the box.

@dchester If you could point me in the right direction, I am willing to prepare a PR.

@sdebionne
Copy link
Contributor

It ends up that emulating the $between operator is easy. I didn't realized that multiple search parameters could target the same attributes:

Given a model:

sequelize.define('timeserie', {
    day: {type: DataTypes.DATE},
    value: {type: DataTypes.REAL}
  });

And a resource:

resources.timeserie = epilogue.resource({
  model: models.timeserie,
  endpoints: ['/timeserie'],
  actions: ['list', 'read'],
  search: [
    {operator: '$gte', param: 'begin', attributes: [ 'day' ]},
    {operator: '$lte', param: 'end', attributes: [ 'day' ]}
  ] 
});

One can use /timeserie?begin=2017-01-01&end=2017-01-05 to get value BETWEEN end and begin.

@wcodba
Copy link
Author

wcodba commented Jan 17, 2017

Yes ok but how to avoid to specify attributes: [ 'day' ] ?
Goal is to deliver this resource for all endpoint and all fields, is it possible ?

Cheers.

@zlatinejc
Copy link

It is. It's called dynamic coding.

You should try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants