persvr / rql

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

Error when nested property isn't there #15

Closed benatkin closed 14 years ago

benatkin commented 14 years ago

I saw that nested properties are supported in the language and in js-array. Neat! This is probably not the desired behavior when it can't go deep enough, though:

> rql.query("foo.cat=3", {}, [{"path":[1,2,3]},{"path":[9,3,7]}])
TypeError: Cannot read property 'cat' of undefined
    at Array.<anonymous> (eval at query (/Users/ben/.node_libraries/.npm/rql/0.2.2/package/lib/js-array.js:363:53))
    at Array.<anonymous> (/Users/ben/.node_libraries/.npm/rql/0.2.2/package/lib/js-array.js:91:25)
    at Array.<anonymous> (eval at query (/Users/ben/.node_libraries/.npm/rql/0.2.2/package/lib/js-array.js:363:53))
    at eval at query (/Users/ben/.node_libraries/.npm/rql/0.2.2/package/lib/js-array.js:363:53)
    at Object.query (/Users/ben/.node_libraries/.npm/rql/0.2.2/package/lib/js-array.js:364:18)
    at [object Context]:1:5
    at Interface.<anonymous> (repl:98:19)
    at Interface.emit (events:27:15)
    at Interface._ttyWrite (readline:295:12)
    at Interface.write (readline:132:30)
benatkin commented 14 years ago

Pulled the new version, and it does indeed fix this issue!

> var rql = require('rql/js-array')
> var docs = [{'html':{'head':{'title':'Hello'}}}, {'html':{'head':{'title':'Ben'}}}, {'name': 'Ben', 'age': 28}]
> rql.query('html.head.title=Hello', {}, docs)
[ { html: { head: [Object] } } ]
dvv commented 14 years ago

Have it fixed your first example?!

benatkin commented 14 years ago

Yes, it did. :)

> rql.query("foo.cat=3", {}, [{"path":[1,2,3]},{"path":[9,3,7]}])
[]

Thanks!