Search code examples
clojuredatomic

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.


Solution

  • 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)