add test and readme for realise-fn
This commit is contained in:
parent
9c2c899876
commit
7e62bf8898
2 changed files with 22 additions and 3 deletions
13
README.md
13
README.md
|
|
@ -32,7 +32,7 @@ For Leinengen, add this to your project.clj:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
;; The underlying driver -- any newer version can also be used
|
;; The underlying driver -- any newer version can also be used
|
||||||
[org.mongodb/mongodb-driver-sync "4.7.1"]
|
[org.mongodb/mongodb-driver-sync "4.11.1"]
|
||||||
|
|
||||||
;; This wrapper library
|
;; This wrapper library
|
||||||
[mongo-driver-3 "0.7.0"]
|
[mongo-driver-3 "0.7.0"]
|
||||||
|
|
@ -104,6 +104,10 @@ As an example:
|
||||||
;; Find a single document or return nil
|
;; Find a single document or return nil
|
||||||
(mc/find-one db "test" {:v "world"} {:keywordize? false})
|
(mc/find-one db "test" {:v "world"} {:keywordize? false})
|
||||||
; => {"v" "world"}
|
; => {"v" "world"}
|
||||||
|
|
||||||
|
;; Avoid laziness in queries
|
||||||
|
(mc/find db "test" {} {:realise-fn (partial into [])}
|
||||||
|
; => [...]
|
||||||
```
|
```
|
||||||
|
|
||||||
While most options are supported directly, sometimes you may need to some extra control.
|
While most options are supported directly, sometimes you may need to some extra control.
|
||||||
|
|
@ -181,6 +185,13 @@ use `with-open` so the session is closed after both successful and failed transa
|
||||||
(mc/insert-one my-db "coll" {:name "world"})))
|
(mc/insert-one my-db "coll" {:name "world"})))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
1. Run mongo (e.g. via docker):
|
||||||
|
- `docker run -it --rm -p 27017:27017 mongo`
|
||||||
|
2. Run tests
|
||||||
|
- `lein test`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,11 @@
|
||||||
(is (instance? FindIterable (mc/find db "test" {} {:raw? true}))))
|
(is (instance? FindIterable (mc/find db "test" {} {:raw? true}))))
|
||||||
|
|
||||||
(testing "keywordize"
|
(testing "keywordize"
|
||||||
(is (= [{"id" 1}] (mc/find db "test" {} {:keywordize? false :projection {:_id 0 :id 1} :limit 1}))))))
|
(is (= [{"id" 1}] (mc/find db "test" {} {:keywordize? false :projection {:_id 0 :id 1} :limit 1}))))
|
||||||
|
|
||||||
|
(testing "realise-fn"
|
||||||
|
(is (seq? (mc/find db "test" {})))
|
||||||
|
(is (vector? (mc/find db "test" {} {:realise-fn (partial into [])}))))))
|
||||||
|
|
||||||
(deftest ^:integration test-find-one
|
(deftest ^:integration test-find-one
|
||||||
(let [db (new-db @client)
|
(let [db (new-db @client)
|
||||||
|
|
@ -382,7 +386,11 @@
|
||||||
(deftest ^:integration test-list-indexes
|
(deftest ^:integration test-list-indexes
|
||||||
(let [db (new-db @client)
|
(let [db (new-db @client)
|
||||||
_ (mc/create db "test")]
|
_ (mc/create db "test")]
|
||||||
(is (= 1 (count (mc/list-indexes db "test"))) "has default index")))
|
(is (= 1 (count (mc/list-indexes db "test"))) "has default index")
|
||||||
|
|
||||||
|
(testing "realise-fn"
|
||||||
|
(is (seq? (mc/list-indexes db "test")))
|
||||||
|
(is (vector? (mc/list-indexes db "test" {:realise-fn (partial into [])}))))))
|
||||||
|
|
||||||
(deftest ^:integration test-create-index
|
(deftest ^:integration test-create-index
|
||||||
(let [db (new-db @client)
|
(let [db (new-db @client)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue