Support serialization of Clojure sets (or anything that implements java.util.Set)
This commit is contained in:
parent
5c62e47de7
commit
6a2698dce2
3 changed files with 27 additions and 8 deletions
|
|
@ -1,5 +1,10 @@
|
|||
## Changes between 1.0.0-beta4 and 1.0.0-beta5
|
||||
|
||||
### Clojure sets now can be serialized
|
||||
|
||||
Monger now supports serialization for all classes that implement `java.util.Set`, including Clojure sets.
|
||||
|
||||
|
||||
### Capped collection support
|
||||
|
||||
`monger.collection/create` provides a way to create collections with fine-tuned attributes (for example, capped collections)
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
(ns monger.conversion
|
||||
(:import [com.mongodb DBObject BasicDBObject BasicDBList DBCursor]
|
||||
[clojure.lang IPersistentMap Named Ratio]
|
||||
[java.util List Map Date]
|
||||
[clojure.lang IPersistentMap Named Keyword Ratio]
|
||||
[java.util List Map Date Set]
|
||||
org.bson.types.ObjectId))
|
||||
|
||||
(defprotocol ConvertToDBObject
|
||||
|
|
@ -35,10 +35,6 @@
|
|||
(to-db-object [input]
|
||||
input)
|
||||
|
||||
Object
|
||||
(to-db-object [input]
|
||||
input)
|
||||
|
||||
String
|
||||
(to-db-object [^String input]
|
||||
input)
|
||||
|
|
@ -51,6 +47,9 @@
|
|||
(to-db-object [^Ratio input]
|
||||
(double input))
|
||||
|
||||
Keyword
|
||||
(to-db-object [^Keyword input] (.getName input))
|
||||
|
||||
Named
|
||||
(to-db-object [^Named input] (.getName input))
|
||||
|
||||
|
|
@ -64,8 +63,15 @@
|
|||
List
|
||||
(to-db-object [^List input] (map to-db-object input))
|
||||
|
||||
Set
|
||||
(to-db-object [^Set input] (map to-db-object input))
|
||||
|
||||
DBObject
|
||||
(to-db-object [^DBObject input] input))
|
||||
(to-db-object [^DBObject input] input)
|
||||
|
||||
Object
|
||||
(to-db-object [input]
|
||||
input))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,15 @@
|
|||
id (ObjectId.)
|
||||
doc { :keyword :kwd "_id" id }
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
(is (= (name :kwd) (:keyword (mgcol/find-map-by-id collection id)))))) ;
|
||||
(is (= (name :kwd) (:keyword (mgcol/find-map-by-id collection id))))))
|
||||
|
||||
(deftest insert-a-document-with-clojure-keyword-in-a-set-in-it
|
||||
(let [collection "widgets"
|
||||
id (ObjectId.)
|
||||
doc { :keyword1 {:keyword2 #{:kw1 :kw2}} "_id" id }
|
||||
result (mgcol/insert "widgets" doc)]
|
||||
(is (= (sort ["kw1" "kw2"])
|
||||
(sort (get-in (mgcol/find-map-by-id collection id) [:keyword1 :keyword2]))))))
|
||||
|
||||
|
||||
(defrecord Metrics
|
||||
|
|
|
|||
Loading…
Reference in a new issue