[clouchdb-cvs] CVS clouchdb/public_html

peddy peddy at common-lisp.net
Tue Jun 17 01:13:21 UTC 2008


Update of /project/clouchdb/cvsroot/clouchdb/public_html
In directory clnet:/tmp/cvs-serv14390/public_html

Modified Files:
	index.html 
Log Message:
Fixed comment in source
Updated docs with missing document-update-fn, document-fetch-fn and
other missing information


--- /project/clouchdb/cvsroot/clouchdb/public_html/index.html	2008/06/16 23:42:56	1.22
+++ /project/clouchdb/cvsroot/clouchdb/public_html/index.html	2008/06/17 01:13:20	1.23
@@ -546,7 +546,7 @@
 ;; then ignore the request (don't generate error), return 
 ;; ((:ERROR . "not_found") (:REASON . "missing")) if 
 ;; database did not exist
-(delete-db :db-name "tvland")
+(delete-db :db-name "tvland" :if-missing :ignore)
 <b>=></b> ((:ERROR . "not_found") (:REASON . "missing"))
 </pre>
 </blockquote>
@@ -574,7 +574,8 @@
 </p>
 <blockquote>
   <p>
-    Returns a list of databases that exist in the current database.
+    Returns a list of the databases that exist on the current database
+    host.
   </p>
 
 <pre class="code">
@@ -585,7 +586,7 @@
 
 <p>[Function]<br />
 <a name="sym-set-connection"><b>set-connection</b></a> &key host
-db-name protocol port => no value
+db-name protocol port document-update-fn document-fetch-fn => no value
 </p>
 <blockquote>
 <p>
@@ -594,12 +595,45 @@
 server. Default connection settings are host="localhost",
 protocol="http", port="5984" and database="default".
 </p>
+<p>
+  Functions may be specified that should invoked automatically each
+  time a document is created or updated (document-update-fn) and each
+  time a document is fetched (document-fetch-fn). These functions must
+  take one argument, the document, and return the potentially modified
+  document.
+</p>
+
+<p>
+Example:
+</p>
+<pre class="code">
+;; 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
+(set-connection :document-update-fn #'time-stamper)
+
+;; Test the new time stamping feature
+(create-document '((:hello . "there")) :id "test")
+<b>=></b> ((:|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")
+<b>=></b> ((:|_id| . "test") (:|_rev| . "3721228336") (:TIMESTAMP . 3422649324) 
+  (:HELLO . "there"))
+</pre>
+
 <p> See (<a href="#sym-with-connection">with-connection</a>)</p>
 </blockquote>
 
 <p>[Macro]<br />
 <a name="sym-with-connection"><b>with-connection</b></a> (&key host
-db-name protocol port) &body body => value returned by body
+db-name protocol port document-update-fn document-fetch-fn)  
+&body body => value returned by body
 </p>
 <blockquote>
 <p>
@@ -609,6 +643,13 @@
 expressions in the body.
 </p>
 <p>
+  Additionally functions that are called as documents are created or
+  modified (document-update-fn) and when documents are fetched
+  (document-fetch-fn) may be specified. These functions take one
+  parameter, the document being sent to or fetched from the database,
+  and return a potentially modified document.
+</p>
+<p>
 Example:
 </p>
 <pre class="code">
@@ -853,7 +894,7 @@
 
 <p>[Function]<br />
 <a name="sym-delete-document"><b>delete-document</b></a> &key document
-id revision</p>
+id revision if-missing</p>
 <blockquote>
 <p>
   Delete the specified document, which must include the standard
@@ -863,6 +904,10 @@
   deletes the most current revision by fetching the document by ID and
   using its :|_rev| value for the deletion.
 </p>
+<p>
+  Signals a document-missing error if document does not exist, unless
+  the :if-missing keyword parameter is set to :ignore
+</p>
 </blockquote>
 
 <p>[Function]<br />




More information about the clouchdb-cvs mailing list