json-server icon indicating copy to clipboard operation
json-server copied to clipboard

or logic in filtering

Open stushurik opened this issue 6 years ago • 9 comments
trafficstars

In my db I have something like this:

[
  {
    "id": "89be578a-ef59-4cf2-96ca-5911bf95d959",
    "count": 1
  },
  {
    "id": "464e2921-2a44-4bfb-b533-89f2a75f8ba5",
    "count": 5
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 6
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 8
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 10
  }
]

And I would like to request like this

/connections?count=1&count_gte=8 

and get items with count 1,8 and 10.

Currently it seems that json-server applies some kind of "and" logic and this request become mutually exclusive. As a result I get empty array

Proposal allow "or" request

stushurik avatar Mar 26 '19 12:03 stushurik

@typicode what do you think about it?

stushurik avatar Mar 26 '19 12:03 stushurik

I would love to see such an option! Maybe someone may fork this project #1219 ?

MickL avatar Feb 11 '21 13:02 MickL

How would you define an "or" in the parameter?

Maybe with _or_: /connections?count=1_or_count_gte=8?

MickL avatar Feb 13 '21 14:02 MickL

I can imagine something like this: /connections?count=1&count_or_gte=8 Inspired by: https://gt-tech.bitbucket.io/spring-data-querydsl-value-operators/README.html https://gt-tech.bitbucket.io/spring-data-querydsl-value-operators/EXAMPLE_APPLICATION.html

stushurik avatar Feb 13 '21 15:02 stushurik

I like. What about multiple fields? How is that done in spring? E.g.:

?idA=123_or_idB=123

MickL avatar Feb 13 '21 17:02 MickL

Would be magic if can consider the Lucene or ElasticSearch syntax, it's really useful

oceangravity avatar Mar 13 '21 13:03 oceangravity

How does the syntax look exactly?

MickL avatar Mar 13 '21 16:03 MickL

Obviously it's add more complexity: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

oceangravity avatar Mar 13 '21 16:03 oceangravity

Any updates on this?

BigSamu avatar Dec 05 '24 12:12 BigSamu

Any updates on this?

LargatSeif avatar Jul 13 '25 01:07 LargatSeif