Skip to content

Instantly share code, notes, and snippets.

@ejackson
Created October 27, 2011 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejackson/1319377 to your computer and use it in GitHub Desktop.
Save ejackson/1319377 to your computer and use it in GitHub Desktop.
(defn- ipred [[k v]]
(pred/like k v))
(defn- partial-pred [m]
"Turn a map into a predicate format understood by cql. IE {:a 1 :b 2} --> (pred/and* (pred/=* :a 1) (pred/=* :b 2))"
(apply pred/and* (map ipred m)))
(defprotocol MapFindable
"A protocol for clojureQL searchable things that can be found using a map interface"
(find [this search-map]))
(extend-protocol MapFindable
clojure.lang.PersistentArrayMap
(find [{table :table :as schema} m]
(cql/select (cql/table db/db table) (partial-pred m)))
clojureql.core.RTable
(find [rt m]
(cql/select rt (partial-pred m))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment