-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jimpil/master
various optimisations/fixes
- Loading branch information
Showing
6 changed files
with
140 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ pom.xml.asc | |
/.nrepl-port | ||
.hgignore | ||
.hg/ | ||
.lsp/ | ||
.clj-kondo/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
(ns mongo-driver-3.data-literals | ||
(:import (org.bson.types ObjectId) | ||
(java.io Writer))) | ||
(java.io Writer) | ||
(java.util Date) | ||
(java.nio ByteBuffer))) | ||
|
||
|
||
(defmethod print-method ObjectId [c ^Writer w] (.write w ^String (str "#mongo/id \"" (.toHexString c) "\""))) | ||
(defmethod print-dup ObjectId [c ^Writer w] (.write w ^String (str "#mongo/id \"" (.toHexString c) "\""))) | ||
(defmethod print-method ObjectId [^ObjectId c ^Writer w] (.write w (str "#mongo/id " \" (.toHexString c) \"))) | ||
(defmethod print-dup ObjectId [^ObjectId c ^Writer w] (.write w (str "#mongo/id " \" (.toHexString c) \"))) | ||
|
||
(defn mongo-id [o] | ||
(ObjectId. o)) | ||
(defprotocol AsObjectId | ||
(oid-from [this])) | ||
|
||
(extend-protocol AsObjectId | ||
(Class/forName "[B") | ||
(oid-from [this] (ObjectId. ^bytes this)) | ||
nil | ||
(oid-from [_] (ObjectId.)) | ||
String | ||
(oid-from [this] (ObjectId. this)) | ||
Date | ||
(oid-from [this] (ObjectId. this)) | ||
ByteBuffer | ||
(oid-from [this] (ObjectId. this)) | ||
) | ||
|
||
|
||
|
||
(defn mongo-id ;; https://mongodb.github.io/mongo-java-driver/4.8/apidocs/bson/org/bson/types/ObjectId.html | ||
(^ObjectId [] (ObjectId.)) | ||
(^ObjectId [o] (oid-from o)) | ||
(^ObjectId [o1 o2] | ||
(if (and (int? o1) | ||
(int? o2)) | ||
(ObjectId. (int o1) (int o2)) | ||
(ObjectId. ^Date o1 (int o2))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns mongo-driver-3.iterable | ||
(:require [mongo-driver-3.model :as m])) | ||
|
||
(defn documents | ||
"Given a MongoIterable <it>, returns an eduction which will | ||
eventually yield all the documents (per `m/from-document`)." | ||
[it keywordize?] | ||
(eduction (map #(m/from-document % keywordize?)) it)) |
Oops, something went wrong.