Introduce monger.core/Countable protocol

This commit is contained in:
Michael S. Klishin 2011-08-15 01:43:02 +04:00
parent 1bba60418e
commit 8bd4378f93
2 changed files with 11 additions and 1 deletions

View file

@ -40,3 +40,13 @@
(.getDB *mongodb-connection* name)) (.getDB *mongodb-connection* name))
([^Mongo connection, ^String name] ([^Mongo connection, ^String name]
(.getDB connection name))) (.getDB connection name)))
(defprotocol Countable
(count [this] "Returns size of the object"))
(extend-protocol Countable
com.mongodb.DBCursor
(count [^com.mongodb.DBCursor this]
(.count this)))

View file

@ -138,7 +138,7 @@
(monger.collection/insert collection { :language "Clojure", :name "langohr" }) (monger.collection/insert collection { :language "Clojure", :name "langohr" })
(monger.collection/insert collection { :language "Clojure", :name "incanter" }) (monger.collection/insert collection { :language "Clojure", :name "incanter" })
(monger.collection/insert collection { :language "Scala", :name "akka" }) (monger.collection/insert collection { :language "Scala", :name "akka" })
(is (= 1 (.count (monger.collection/find collection { :language "Scala" })))) (is (= 1 (monger.core/count (monger.collection/find collection { :language "Scala" }))))
(is (= 3 (.count (monger.collection/find collection { :language "Clojure" })))) (is (= 3 (.count (monger.collection/find collection { :language "Clojure" }))))
(is (empty? (monger.collection/find collection { :language "Java" }))))) (is (empty? (monger.collection/find collection { :language "Java" })))))