bitemyapp / revise

RethinkDB client for Clojure
146 stars 8 forks source link

get doesn't appear to work as expected with lambda arguments #13

Open danielytics opened 10 years ago

danielytics commented 10 years ago

I've noticed that sometimes r/get doesn't work as I expect (I could be expecting the wrong thing, but the Javascript driver seems to run the same queries). For example, while testing placeholder from #12, I tried this code, which does not work:

(-> (r/table :test1)
    (r/get "e549f53b-36f5-4140-97e9-61547ce75689")
    (r/get-field :foo)
    (placeholder
      (r/lambda [id]
        (-> (r/table :test2)
            (r/get id))))
    (run conn))

ClassCastException clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.Named clojure.core/name (core.clj:1518)

However, changing the r/get to r/filter works as expected:

(-> (r/table :test1)
    (r/get "e549f53b-36f5-4140-97e9-61547ce75689")
    (r/get-field :foo)
    (placeholder
      (r/lambda [id]
        (-> (r/table :test2)
            (r/filter {:id id}))))
    (run conn))

In javascript (in the data explorer), the get version works:

r.table('test1').get('e549f53b-36f5-4140-97e9-61547ce75689')('foo').do(function(id){
  return r.table('test2').get(id)
})
cesarbp commented 10 years ago

This is because of this line https://github.com/bitemyapp/revise/blob/master/src/bitemyapp/revise/query.clj#L159

A fix is easy (to account for when the key is actually a "variable"). But I think I will delay these fixes till this driver is up to speed with the latest version of rethinkdb. Which will be done by the end of this week at the latest.

danielytics commented 10 years ago

Oh, awesome, thank you! Thanks also for your responsiveness!

I can simply use filter for the time being - I won't need super fast performance just yet :)