Skip to content

Commit

Permalink
work with skunk
Browse files Browse the repository at this point in the history
  • Loading branch information
fons committed May 19, 2010
1 parent 5bd5f56 commit 37f7ed4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/document.lisp
Expand Up @@ -52,6 +52,9 @@ is supplied.
(defmethod rm-element ( (key string) (document document) )
(remhash key (elements document)))

(defun doc-id (doc)
"return the unique document id"
(id (_id doc)))

;;
;; When the to-hash-able finalizer is used, embedded docs/tables in the response aren't converted
Expand Down Expand Up @@ -110,7 +113,16 @@ is supplied.
(if exists-p (add-element key value doc)))))
doc)))

(defun mapdoc (fn document)
(let ((lst ())
(ht (elements document)))
(with-hash-table-iterator (iterator ht)
(dotimes (repeat (hash-table-count ht))
(multiple-value-bind (exists-p key value) (iterator)
(if exists-p (push (funcall fn key value) lst)))))
(nreverse lst)))


(defgeneric doc-elements (document) )

(defmethod doc-elements ( (document hash-table) )
Expand All @@ -122,4 +134,4 @@ is supplied.
lst))

(defmethod doc-elements ( (document document) )
(doc-elements (elements document)))
(doc-elements (elements document)))
6 changes: 6 additions & 0 deletions src/mongo.lisp
Expand Up @@ -91,6 +91,12 @@ the default port is 27017; the default db is admin."))
(db *mongo-default-db*) (name :default) )
(or (gethash name (mongo-registry)) (make-mongo :host host :port port :db db :name name)))

(defgeneric mongo-registered (name)
(:documentation "Return a conection registered by this name or nil.."))

(defmethod mongo-registered (name)
(gethash name (mongo-registry)))

(defun mongo-show()
" Show all registered connections and their session id"
(with-hash-table-iterator (iterator (mongo-registry))
Expand Down
3 changes: 3 additions & 0 deletions src/packages.lisp
Expand Up @@ -16,9 +16,12 @@
:get-element
:rm-element
:ht->document
:mapdoc
:doc-id

;;commands
:mongo
:mongo-registered
:mongo-show
:mongo-close
:mongo-swap
Expand Down

0 comments on commit 37f7ed4

Please sign in to comment.