LauJensen / clojureql

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

How to build a query with 'or' using another function call? #125

Closed ariel123 closed 12 years ago

ariel123 commented 12 years ago

Here's the sql that I'd like to form:

(clojureql.core/join (clojureql.core/table db :tableA) (clojureql.core/table db :tableA) (clojureql.core/where (apply and (= :tableA.id :tableB.id) [(apply or [(clojureql.predicates/in :tableA.id [1 2]) (clojureql.predicates/in :tableA.id [3 4])])])))

I'd like to call another function for the "apply or" form, something like this:

(clojureql.core/join (clojureql.core/table db :tableA) (clojureql.core/table db :tableA) (clojureql.core/where (apply and (= :tableA.id :tableB.id) [(my-or-f)])))

where my-of-f function is:

(defn my-or-f [](apply or [%28clojureql.predicates/in :tableA.id [1 2]%29 %28clojureql.predicates/in :tableA.id [3 4]%29]))

however this function throws this exception: java.lang.Exception: Can't take value of a macro: #'clojure.core/or (NO_SOURCE_FILE:2)

I've also tried using a macro for my-or-f. It compiles but it throws the same exception when I try running the query using this macro

(defmacro my-or-f [] `(apply or [(clojureql.predicates/in :tableA.id [1 2]) (clojureql.predicates/in :tableA.id [3 4])]))

Is there another way that I could use the "apply or"?

Thanks.

LauJensen commented 12 years ago

(where) is a macro which does a very simple rewrite. Look up the source and either do what it does or write your own where macro.