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
|
## 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
|
### Capped collection support
|
||||||
|
|
||||||
`monger.collection/create` provides a way to create collections with fine-tuned attributes (for example, capped collections)
|
`monger.collection/create` provides a way to create collections with fine-tuned attributes (for example, capped collections)
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
(ns monger.conversion
|
(ns monger.conversion
|
||||||
(:import [com.mongodb DBObject BasicDBObject BasicDBList DBCursor]
|
(:import [com.mongodb DBObject BasicDBObject BasicDBList DBCursor]
|
||||||
[clojure.lang IPersistentMap Named Ratio]
|
[clojure.lang IPersistentMap Named Keyword Ratio]
|
||||||
[java.util List Map Date]
|
[java.util List Map Date Set]
|
||||||
org.bson.types.ObjectId))
|
org.bson.types.ObjectId))
|
||||||
|
|
||||||
(defprotocol ConvertToDBObject
|
(defprotocol ConvertToDBObject
|
||||||
|
|
@ -35,10 +35,6 @@
|
||||||
(to-db-object [input]
|
(to-db-object [input]
|
||||||
input)
|
input)
|
||||||
|
|
||||||
Object
|
|
||||||
(to-db-object [input]
|
|
||||||
input)
|
|
||||||
|
|
||||||
String
|
String
|
||||||
(to-db-object [^String input]
|
(to-db-object [^String input]
|
||||||
input)
|
input)
|
||||||
|
|
@ -51,6 +47,9 @@
|
||||||
(to-db-object [^Ratio input]
|
(to-db-object [^Ratio input]
|
||||||
(double input))
|
(double input))
|
||||||
|
|
||||||
|
Keyword
|
||||||
|
(to-db-object [^Keyword input] (.getName input))
|
||||||
|
|
||||||
Named
|
Named
|
||||||
(to-db-object [^Named input] (.getName input))
|
(to-db-object [^Named input] (.getName input))
|
||||||
|
|
||||||
|
|
@ -64,8 +63,15 @@
|
||||||
List
|
List
|
||||||
(to-db-object [^List input] (map to-db-object input))
|
(to-db-object [^List input] (map to-db-object input))
|
||||||
|
|
||||||
|
Set
|
||||||
|
(to-db-object [^Set input] (map to-db-object input))
|
||||||
|
|
||||||
DBObject
|
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.)
|
id (ObjectId.)
|
||||||
doc { :keyword :kwd "_id" id }
|
doc { :keyword :kwd "_id" id }
|
||||||
result (mgcol/insert "widgets" doc)]
|
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
|
(defrecord Metrics
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue