LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
284 stars 39 forks source link

Parametrisation of query via a function #19

Closed kotarak closed 13 years ago

kotarak commented 13 years ago

Shouldn't this work?

user=> (defn users-older-than [x] (-> (cql/table nil :users) (cql/project [:name :age])(cql/select (cql/where (> :age x)))))
#'user/users-older-than
user=> (cql/to-sql (users-older-than 5))
java.lang.Exception: Unable to resolve symbol: x in this context (NO_SOURCE_FILE:8)
LauJensen commented 13 years ago

Since where is a macro, it doesnt communicate the local bindings to its driver. I've just pushed a patch which fixes this so the above code will work.

Thanks for raising the issue! Lau

kotarak commented 13 years ago

It still captures locals named like one of the predicates. However, this is unlikely to happen in real code.