add test and readme for realise-fn

This commit is contained in:
George Narroway 2024-02-07 11:07:55 +08:00
parent 9c2c899876
commit 7e62bf8898
2 changed files with 22 additions and 3 deletions

View file

@ -32,7 +32,7 @@ For Leinengen, add this to your project.clj:
```clojure
;; 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
[mongo-driver-3 "0.7.0"]
@ -104,6 +104,10 @@ As an example:
;; Find a single document or return nil
(mc/find-one db "test" {:v "world"} {:keywordize? false})
; => {"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.
@ -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"})))
```
## Development
1. Run mongo (e.g. via docker):
- `docker run -it --rm -p 27017:27017 mongo`
2. Run tests
- `lein test`
## License
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php

View file

@ -144,7 +144,11 @@
(is (instance? FindIterable (mc/find db "test" {} {:raw? true}))))
(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
(let [db (new-db @client)
@ -382,7 +386,11 @@
(deftest ^:integration test-list-indexes
(let [db (new-db @client)
_ (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
(let [db (new-db @client)