From 07792a31e101d11fd366ec598cf8707e112389c5 Mon Sep 17 00:00:00 2001 From: Vito Van Date: Wed, 29 Jul 2015 10:01:05 +0800 Subject: [PATCH 1/4] defun document->ht Convert a document to a hash-table, recursively. --- src/document.lisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/document.lisp b/src/document.lisp index 5f6474d..c8e7998 100644 --- a/src/document.lisp +++ b/src/document.lisp @@ -230,6 +230,19 @@ the document was generated by the client (as opposed to having been read from th (multiple-value-bind (exists-p key value) (iterator) (when exists-p (add-element key value doc))))) doc))) + +(defun document->ht (doc/docs) + "Convert a document to a hash-table, recursively." + (cond + ((equal (type-of doc/docs) 'document) + (let* ((ht (slot-value doc/docs 'cl-mongo::elements)) + (keys (hash-table-keys ht))) + (dolist (x keys) + (sethash x (document->ht (gethash x ht)) ht)) + ht)) + ((listp doc/docs) + (mapcar #'document->ht doc/docs)) + (t doc/docs))) (defun ht->document.1 (ht) (multiple-value-bind (oid oid-supplied) (gethash "_id" ht) From 3ddb2e0d8be768967a3e4beeea34e5e1d99d27ec Mon Sep 17 00:00:00 2001 From: Vito Van Date: Wed, 29 Jul 2015 10:01:43 +0800 Subject: [PATCH 2/4] add :document->ht --- src/packages.lisp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/packages.lisp b/src/packages.lisp index 82ade25..661a66e 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -15,6 +15,7 @@ :collect-all-elements :rm-element :ht->document + :document->ht :mapdoc :doc-id :get-keys From d3b7944771488ec77fb880d39e74a34405df71e8 Mon Sep 17 00:00:00 2001 From: Vito Van Date: Wed, 29 Jul 2015 10:15:59 +0800 Subject: [PATCH 3/4] add bson-time-to-ut to document->ht --- src/document.lisp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/document.lisp b/src/document.lisp index c8e7998..4c04bcc 100644 --- a/src/document.lisp +++ b/src/document.lisp @@ -242,6 +242,8 @@ the document was generated by the client (as opposed to having been read from th ht)) ((listp doc/docs) (mapcar #'document->ht doc/docs)) + ((equal (type-of doc/docs) 'cl-mongo::bson-time) + (bson-time-to-ut doc/docs)) (t doc/docs))) (defun ht->document.1 (ht) From 807fc47b969e06f3987ba135add61d886a0deb08 Mon Sep 17 00:00:00 2001 From: Vito Van Date: Wed, 29 Jul 2015 11:02:05 +0800 Subject: [PATCH 4/4] defmacro sethash --- src/document.lisp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/document.lisp b/src/document.lisp index 4c04bcc..1a03328 100644 --- a/src/document.lisp +++ b/src/document.lisp @@ -245,6 +245,9 @@ the document was generated by the client (as opposed to having been read from th ((equal (type-of doc/docs) 'cl-mongo::bson-time) (bson-time-to-ut doc/docs)) (t doc/docs))) + +(defmacro sethash(key value hash-table) + `(setf (gethash ,key ,hash-table) ,value)) (defun ht->document.1 (ht) (multiple-value-bind (oid oid-supplied) (gethash "_id" ht)