neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

Implement bracket on queries #254

Open neumino opened 9 years ago

neumino commented 9 years ago

It's not possible on Model, but it should be possible for Query.

marshall007 commented 9 years ago

@neumino are you talking about the bracket ReQL term? Doesn't this already work on Query?

neumino commented 9 years ago

@marshall007 -- Model.filter({foo: 'bar})("field") doesn't work. An instance of Query is an object, not a function.

However, this works fine Model.filter({foo: 'bar}).getField("field"), Model.filter({foo: 'bar}).nth(0)

neumino commented 9 years ago

Ah, I mentionned nth and getField, but bracket also works.

Model.filter({foo: 'bar}).bracket("field")

It's just that you can't do

Model.filter({foo: 'bar})("field")
marshall007 commented 9 years ago

You're right. I was thinking of inner queries using r.row().

avimar commented 9 years ago

BTW, not sure where to doc this, but nth(0) throws a weird error when there's no results... I switched to .get(0) in promises so that I can just check if it's blank or not.

neumino commented 9 years ago

This is expected, it's how RethinkDB behaves. You can catch the out of bound error in RethinkDB with default.