Created
October 27, 2011 12:05
-
-
Save ejackson/1319377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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