persvr / rql

Resource Query Language
http://www.persvr.org/
267 stars 49 forks source link

how to use some operators? #74

Open Juravenator opened 8 years ago

Juravenator commented 8 years ago

I can't seem to use the contains() function, while others work just fine. For example:

#!/usr/bin/node
var data = [
  {
    name: "first",
    number: 1,
    somearray: [
      "pizza",
      "nachos"
    ]
  },
  {
    name: "second",
    number: 2,
    somearray: [
      "fish",
      "chips"
    ]
  },
  {
    name: "third",
    number: 3,
    somearray: [
      "pizza",
      "chips"
    ]
  }
];

var queryFactory = require("rql/js-array").query;
var query = queryFactory("sort(-number)&number=gt=0&somearray=contains=chips");
var result = query(data);
console.log(result);

I can use "number=gt=0", "sort()", and "first()". But when I try to use contain it gives the following error:

node_modules/rql/js-array.js:66
            return array instanceof Array && contains(array, value);
                                             ^

TypeError: contains is not a function
    at node_modules/rql/js-array.js:66:37
    at Array.filter (node_modules/rql/js-array.js:301:7)
    at Array.eval (eval at query (node_modules/rql/js-array.js:419:73), <anonymous>:1:237)
    at Array.exports.operators.and (node_modules/rql/js-array.js:106:25)
    at Array.eval (eval at query (node_modules/rql/js-array.js:419:73), <anonymous>:1:58)
    at eval (eval at query (node_modules/rql/js-array.js:419:73), <anonymous>:1:274)
    at Object.<anonymous> (queryDemo.js:31:14)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)

I've tried to use "contains(somearray,chips)", and "somearray=contains=chips". Both give the same error.

Do these require a different syntax, or are these only supported in the new Query().lt("foo",3).gt("foo",10); fashion?

Juravenator commented 8 years ago

The problem is the missing require("./util/contains") in js-array.js. When adding it, everything works normally. commit 4ae84c84817c5e51313012e9cc3d46ed7557947d has solved this, but this isn't included in a release yet.

Any ideas when a next release is planned?