kclay / rethink-scala

Scala Driver for RethinkDB
Other
100 stars 24 forks source link

How to use contains in a filter? #11

Closed ohde closed 10 years ago

ohde commented 10 years ago

Here is an example of the reQL: r.db('5b5hh').table('luc9k').filter(function(user) { return user("identities").contains(function(identity) { return identity('userId').eq('700')})})

I have attempted to accomplish this the following with no luck: .filter((f: Var) => (f \ "identities" contains ((i: Var) => i \ "userId" == "700")))

As you might have guessed, "identite"s is a List of objects which contains "userId".

For reference: I have been using: Map("id" -> 10) Since the following hasn't worked. (f: Var) => f \ "id" eq 10 I got this to work (f: Var) => f \ "id" === 10

kclay commented 10 years ago

Seems I'm missing a way to type to a collection when accessing a field. Let me clean up some of the pending work I have and I'll push an snapshot for this. Btw what scala version are you using?

ohde commented 10 years ago

Ok, that would be great. Thanks. Scala: 2.11.1

kclay commented 10 years ago

Should be able to query now: 0.4.4-SNAPSHOT,

import com.rethinkscala.net.Blocking._ // need to add this
Expr(1 to 10).filter(f=> f("industries").contains(i=> i \ "userId" ==="700"))
Expr(1 to 10).filter(f=> (f \"industries").contains(i=> i \ "userId" ==="700"))
ohde commented 10 years ago

Thanks, it works exactly as desired. I appreciate you taking the time to get it done so quickly.