[clouchdb-cvs] CVS clouchdb/src
peddy
peddy at common-lisp.net
Sun Jul 12 18:46:53 UTC 2009
Update of /project/clouchdb/cvsroot/clouchdb/src
In directory cl-net:/tmp/cvs-serv22657
Modified Files:
tests.lisp clouchdb.lisp
Log Message:
Doc updates and added top-level clouchdb-error signal type as base type for all other errors
--- /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/07/11 23:34:06 1.21
+++ /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/07/12 18:46:53 1.22
@@ -300,6 +300,15 @@
(ensure-same 0 (document-property :|update_seq| (get-db-info :db *couchdb*)))))
(addtest (clouchdb-db-admin-tests)
+ (:documentation "Be sure differnt get-db-info function invocations return the same results")
+ get-db-info-test
+ (with-temp-db
+ (ensure (tree-equal (get-db-info) (get-db-info :db *couchdb*)
+ :test #'equal))
+ (ensure (tree-equal (get-db-info) (get-db-info :db (db-name *couchdb*))
+ :test #'equal))))
+
+(addtest (clouchdb-db-admin-tests)
(:documentation "Make sure deleting a nonexistant db generates an error")
db-delete-non-existant-db
(ensure-condition 'db-does-not-exist (delete-db :db (create-temp-db-name))))
@@ -346,6 +355,23 @@
(with-temp-db
(ensure (document-property :|ok| (create-db :if-exists :recreate)))))
+(addtest (clouchdb-db-admin-tests)
+ (:documentation "initation compaction")
+ db-compact
+ (with-temp-db
+ (ensure (document-property :|ok| (compact-db)))))
+
+(addtest (clouchdb-db-admin-tests)
+ (:documentation "initation compaction specifying db name")
+ db-compact-name
+ (with-temp-db
+ (ensure (document-property :|ok| (compact-db :db (db-name *couchdb*))))))
+
+(addtest (clouchdb-db-admin-tests)
+ (:documentation "initation compaction specifying structure")
+ db-compact-db-struct
+ (with-temp-db
+ (ensure (document-property :|ok| (compact-db :db *couchdb*)))))
;;
;; Document API Tests
;;
--- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/07/11 23:35:57 1.38
+++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/07/12 18:46:53 1.39
@@ -33,8 +33,7 @@
(defvar *debug-requests* nil)
(defstruct (db (:constructor new-db))
- host port name protocol
- user password
+ host port name protocol user password
document-fetch-fn document-update-fn)
(defun make-default-db ()
@@ -118,7 +117,11 @@
;; Conditions
;;
-(define-condition db-existential-error (error)
+(define-condition clouchdb-error (error)
+ ()
+ (:documentation "The base type of all errors signaled by clouchdb"))
+
+(define-condition db-existential-error (clouchdb-error)
((text :initarg :uri :reader uri)
(db :initarg :db :reader db)
(result :initarg :result :reader result)))
@@ -137,7 +140,7 @@
(db-name (db condition))
(uri condition)))))
-(define-condition doc-error (error)
+(define-condition doc-error (clouchdb-error)
((text :initarg :uri :reader text)
(reason :initarg :reason :reader reason)
(id :initarg :id :reader id))
@@ -187,14 +190,14 @@
(attachments condition))))
(:documentation "Error raised when specified attachment is not found"))
-(define-condition ps-view-def-error (error)
+(define-condition ps-view-def-error (clouchdb-error)
((ps-view-def :initarg :ps-view-def :reader ps-view-def))
(:report (lambda (condition stream)
(format stream "Invalid ps-view definition: ~s"
(ps-view-def condition))))
(:documentation "Error raised for invalid ps-view definition"))
-(define-condition invalid-input (error)
+(define-condition invalid-type (clouchdb-error)
((input :initarg :input :reader input)
(description :initarg :description :reader description))
(:report (lambda (condition stream)
@@ -265,7 +268,7 @@
"Make a database identifier from either a string or db structure."
(cond ((stringp input) input)
((db-p input) (couchdb-database-url input))
- (t (error 'invalid-input
+ (t (error 'invalid-type
:input input
:description "Database must be a string or a database structure"))))
@@ -480,13 +483,13 @@
:document-update-fn document-update-fn
:document-fetch-fn document-fetch-fn)))
-(defmacro with-connection ((&key db db-name port protocol host
- document-update-fn document-fetch-fn)
- &body body)
+(defmacro with-connection ((&key (db *couchdb*) name port protocol
+ host document-update-fn
+ document-fetch-fn) &body body)
"Execute body in the context of the specified database connection
information.."
`(let ((*couchdb* (make-db :db ,db
- :name ,db-name :port ,port
+ :name ,name :port ,port
:protocol ,protocol :host ,host
:document-fetch-fn ,document-fetch-fn
:document-update-fn ,document-update-fn)))
@@ -515,10 +518,11 @@
;; CouchDB Database Management API
;;
-(defun list-dbs ()
+(defun list-dbs (&optional (db *couchdb*))
"Return a list of all databases managed by the current CouchDb
host."
- (db-request "_all_dbs" :method :get))
+ (let ((*couchdb* db))
+ (db-request "_all_dbs" :method :get)))
(defun create-db (&key (db *couchdb*) (if-exists :fail))
"Create database. The db parameter may be either a string which is
@@ -611,7 +615,7 @@
(delete-db))
,result)))
-(defun replicate (target &key (source (make-db)))
+(defun replicate (target &key (source *couchdb*))
"Replicate current database to target, or source to target if source
is specified. Source and target database values must either be strings
or database structures. Use strings to specify simple local database
@@ -834,10 +838,13 @@
:|_deleted| t))
(defun bulk-document-update (docs &key all-or-nothing)
- "Update multiple documents in a single request. The docs parameter
-must be a list of documents. If the provided documents do not contain
-an :|_id| value, then a document is created with a CouchDb assigned
-ID. Any documents containing a (:|_deleted| . t) value will "
+ "Update multiple documents in a single request. The <b>docs</b>
+ parameter is a list of documents. Any document in the list that does
+ not contain an :|_id| value is created with a CouchDb assigned
+ ID. Documents that contain a '(:|_deleted| . t) top-level property
+ will be deleted. Documents that contain an :|_id| property will be
+ updated. If all-or-nothing is true then all operations must succeed
+ for any to succeed, default is false."
(ensure-db ()
(db-request (cat (url-encode (db-name *couchdb*)) "/_bulk_docs")
:method :post
More information about the clouchdb-cvs
mailing list