bi-tm / express-nedb-rest

rest api for nedb database, based on express http server
MIT License
24 stars 13 forks source link

$filter issue #5

Closed CharlesNepote closed 7 years ago

CharlesNepote commented 7 years ago

Based on this given json:

{
  "_id": "1",
  "datetime": "2017-04-06T08:39:44.016Z",
}

fruits?$filter=datetime $regex 2017 => ok

fruits?$filter=datetime $eq 2017-04-06T08:39:44.016Z => KO

unvalid $filter Lexical error on line 1. Unrecognized text.
datetime $regex 2017-04-06T08:39:44.016Z
--------------------^

fruits?$filter=datetime $regex 2017-04-06T08:39:44.016Z => KO

unvalid $filter Lexical error on line 1. Unrecognized text.
datetime $eq 2017-04-06T08:39:44.016Z
-----------------^

Is it filter.js definition of a word fault? ["\\w+\\b", "return 'WORD';"],

bi-tm commented 7 years ago

Hello Charles,

i created a new branch named "dateHandling". The modified coding converts date strings ((ISO 8601) into date objects. So in your example the datetime field will be stored not as String, but as Date.

i also fixed the parser error. now it should be possible to filter a date field.

please checkout the branch and give me feedback.

best wishes Torsten

CharlesNepote commented 7 years ago

Thanks a lot Torsten! Works fine with the branch "dateHandling"!

That said, I found another anoying issue. Given this JSON:

{
    "_id": "1491487724954",
    "schema": {
        "author": "Jacques Martin"
    }
}

http://127.0.0.1:8100/test?$filter=schema.author $regex Jacques => KO

unvalid $filter Lexical error on line 1. Unrecognized text.
schema.author $regex Charl
------^

Do I open another issue?

bi-tm commented 7 years ago

Hello Charles, what a nice NeDb feature! I've never thought about deep structures, my false. I agree, that i should provide the possibility to filter for structured fields. First i will deploy the new date feature, and afterwards i'll work on deep structures. Kindly Torsten

CharlesNepote commented 7 years ago

Great! I think the syntax for deep structures should be the same as in javascript but I understand it can be difficult.

Based on this JSON example:

{
    "_id": "1491487724954",
    "schema": {
       "author": "Jacques Martin",
       "fields": [
         {
            "name": "field1"
         }
       ]
    }
}

$filter=schema.fields[0].name $eq field1 should return this document.

We can discuss about it. My best, Charles.

bi-tm commented 7 years ago

Hello Charles, perhaps it will be complicate to code bigger filter statements in an URL query string. I have the idea to put the filter as JSON string into HTTP body. This would have several advantages:

bi-tm commented 7 years ago

Hello Charles, i just published v1.2.2 to npm. Now you can filter deep structured using the notation as described at NeDB: i.e. $filter=schema.fields.0.name $eq field1 Please close the issue if this solves your issue. Regards Torsten

CharlesNepote commented 7 years ago

Hi Torsten, Great job! Your solutions seem to be very interesting. New $skip and $limit parameters also sound good. I'll make some tests earlier, in the very next days, and give you a complete feedback. Regards, Charles.