From peddy at common-lisp.net Sun Jul 13 22:25:43 2008 From: peddy at common-lisp.net (peddy) Date: Sun, 13 Jul 2008 18:25:43 -0400 (EDT) Subject: [clouchdb-cvs] CVS clouchdb/public_html Message-ID: <20080713222543.6BA751603D@common-lisp.net> Update of /project/clouchdb/cvsroot/clouchdb/public_html In directory clnet:/tmp/cvs-serv17445 Modified Files: index.html Log Message: Add doc for missing bulk-document-update function --- /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/06/30 00:52:47 1.3 +++ /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/07/13 22:25:39 1.4 @@ -627,52 +627,6 @@ -
[Special Variable]
-*document-fetch-fn*
-
-- -- A function which is called whenever a document is fetched from the - database. The function takes one argument, the document, and returns - the potentially modified document. -
- -
[Special Variable]
-*document-update-fn*
-
--- A function which is called whenver a document is sent to the - database via put-document, create-document or post-document - functions. The function should take one parameter, which will be the - document, and it should return one value, which should be the - potentially modified document. -
--;; Create a function that adds or updates a timestamp field in a -;; document and returns the modified document -(defun time-stamper (doc) - (set-document-property doc :timestamp (get-universal-time))) - -;; Cause time-stamper to be invoked with each document as -;; it's updated or created -(setf *document-fetch-fn* #'time-stamper) - -;; Test the new time stamping feature -(create-document '((:hello . "there")) :id "test") -=> ((:|ok| . T) (:|id| . "test") (:|rev| . "3721228336")) - -;; The new document should have been created with a timestamp, -;; let's see if it worked: -(get-document "test") -=> ((:|_id| . "test") (:|_rev| . "3721228336") (:TIMESTAMP . 3422649324) - (:HELLO . "there")) -- -
[Function]
get-db-info &key db-name
[Special Variable]
+*document-fetch-fn*
+
++ ++ A function which is called whenever a document is fetched from the + database. The function takes one argument, the document, and returns + the potentially modified document. +
+ +
[Special Variable]
+*document-update-fn*
+
++ ++ A function which is called whenver a document is sent to the + database via put-document, create-document or post-document + functions. The function should take one parameter, which will be the + document, and it should return one value, which should be the + potentially modified document. +
++;; Create a function that adds or updates a timestamp field in a +;; document and returns the modified document +(defun time-stamper (doc) + (set-document-property doc :timestamp (get-universal-time))) + +;; Cause time-stamper to be invoked with each document as +;; it's updated or created +(setf *document-fetch-fn* #'time-stamper) + +;; Test the new time stamping feature +(create-document '((:hello . "there")) :id "test") +=> ((:|ok| . T) (:|id| . "test") (:|rev| . "3721228336")) + +;; The new document should have been created with a timestamp, +;; let's see if it worked: +(get-document "test") +=> ((:|_id| . "test") (:|_rev| . "3721228336") (:TIMESTAMP . 3422649324) + (:HELLO . "there")) ++ +
[Function]
+bulk-document-update documents
+
++ ++ Create or update multiple documents in a single request. This method + is far more efficient than individual document update or create + requests. +
++ Document IDs are specified with the :|_id| name. If the identified + document does not yet exist it will be craeted with the :|_id| + value. If no :|_id| value is specified a new document with a CouchDb + ID will be created. +
+ ++Example: +
++;; Invoke function with three documents. The first is a new document +;; that will use a provided ID. The second is also a new document +;; and because it does not specify an ID it will be assigned one by +;; CouchDb. The third document already exists in the database, it is +;; fetched with (get-document) and its :desc field is updated (or added). + +(bulk-document-update + (list + (set-document-property nil :|_id| "doc1" :desc "Create and speicfy ID") + (set-document-property nil :desc "Create using CouchDB ID") + (set-document-property (get-document "existing") + :desc "Update existing document"))) + +=> ((:|ok| . T) (:|new_revs| ((:|id| . "doc1") (:|rev| . "159627889")) + ((:|id| . "dc8376d34282c9aa7d8055b6f58e7345") (:|rev| . "261873756")) + ((:|id| . "existing") (:|rev| . "2956316650")))) ++
[Function]
delete-document &key document
id revision if-missing