Scott Klarenbach
Scott Klarenbach

Reputation: 38771

Datomic - Dynamic Query Functions

I was surprised that this didn't work:

(d/q '[:find [?e ...]
         :in $ ?field ?op ?value
         :where [?e ?field ?x]
                [(?op ?x ?value)]
         ]
       db
       :my/field
       >
       10))

If I remove the op and explicitly code in > in the where clause it works. Can I not use input parameters to refer to core clojure functions? Would a rule help? Or would I need to build up the entire query at runtime using quoting/unquotinq?

Thanks.

Upvotes: 1

Views: 247

Answers (1)

Valentin Waeselynck
Valentin Waeselynck

Reputation: 6061

Try this:

(defn invoke [f & args] (apply f args))

(d/q '[:find [?e ...]
       :in $ ?field ?op ?value
       :where 
       [?e ?field ?x]
       [(myapp.utils.datomic/invoke ?op ?x ?value)]]
  db :my/field > 10)

Upvotes: 2

Related Questions