From peddy at common-lisp.net Thu Jun 4 01:47:49 2009 From: peddy at common-lisp.net (peddy) Date: Wed, 03 Jun 2009 21:47:49 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv4258 Modified Files: clouchdb.lisp Log Message: Incorporated patch from Nate Young that fixes an stacktrace generated when executing create-db via a squid proxy. Thanks Nate! --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/04/20 01:56:58 1.31 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/04 01:47:49 1.32 @@ -450,7 +450,7 @@ and create a new database." (let* ((name (if db-name-p db-name *db-name*)) (res (db-request (cat (url-encode name) "/") - :method :put))) + :method :put :content ""))) (if (equal "file_exists" (document-property :|error| res)) (ecase if-exists ((:ignore) (list (cons :|ok| t) (cons :|ignored| t))) From peddy at common-lisp.net Sat Jun 6 17:56:27 2009 From: peddy at common-lisp.net (peddy) Date: Sat, 06 Jun 2009 13:56:27 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv32506 Modified Files: clouchdb.asd Log Message: Removed document.lisp --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.asd 2009/04/19 22:48:32 1.6 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.asd 2009/06/06 17:56:25 1.7 @@ -45,6 +45,5 @@ :components ((:file "package") (:file "clouchdb") (:file "decoder") - (:file "document") (:file "encoder"))) From peddy at common-lisp.net Sat Jun 6 18:37:10 2009 From: peddy at common-lisp.net (peddy) Date: Sat, 06 Jun 2009 14:37:10 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv9301 Modified Files: clouchdb.lisp Log Message: Cleaned up some dumb code --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/04 01:47:49 1.32 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/06 18:37:10 1.33 @@ -369,15 +369,11 @@ (defun db-request (uri &rest args &key &allow-other-keys) "Used by all Couchdb APIs to make the actual REST request." - ;;(format t "uri: ~S~% args: ~S~%" (make-uri uri) args) (let ((*text-content-types* *text-types*)) (multiple-value-bind (body status headers uri stream must-close reason-phrase) (apply #'drakma:http-request (make-uri uri) args) (declare (ignore reason-phrase stream uri headers status)) - ;;(format t "-> uri: ~a~%" uri) - ;;(format t "-> headers: ~S~%" headers) (cond (must-close - ;;(format t "body: ~A~%" body) (json-to-document body)) (t nil))))) @@ -639,17 +635,16 @@ new document and assign a new ID. Therefore this is an easy method for copying documents. The return value includes the document ID in the :ID property." - (let* ((url (cat (url-encode *db-name*) "/")) - (res (ensure-db () - (db-request url + (let ((res (ensure-db () + (db-request (cat (url-encode *db-name*) "/") :content-type "text/javascript" :external-format-out +utf-8+ :content-length nil + :method :post :content (document-to-json - (document-update-notify *document-update-fn* doc)) - :method :post)))) + (document-update-notify *document-update-fn* doc)))))) (when (document-property :|error| res) - (error 'doc-error) :id nil :reason (document-property :|reason| res)) + (error 'doc-error :id nil :reason (document-property :|reason| res))) res)) (defun create-document (doc &key id attachments) @@ -696,7 +691,7 @@ "?rev=" (url-encode (value-as-string rev))) :method :delete)))) (when (document-property :|error| res) - (error 'doc-error) :id id :reason (document-property :|reason| res)) + (error 'doc-error :id id :reason (document-property :|reason| res))) res))) (cond ((not (null document)) (delete-document :id (document-property :|_id| document) @@ -719,7 +714,7 @@ (defun ad-hoc-view (view &rest options &key key start-key start-key-docid end-key count update descending skip) "Execute query using an ad-hoc view." - (declare (ignore key start-key start-key-docid end-key count + (declare (ignore key start-key start-key-docid end-key count update descending skip)) (ensure-db () (db-request (cat (url-encode *db-name*) "/_temp_view") @@ -798,8 +793,8 @@ returns results in reverse order. If update is t, does not refresh view for query, use for higher performance but possible data inconsistency." - (declare (ignore key start-key start-key-docid end-key count - update descending skip)) + (declare (ignore key start-key start-key-docid end-key + limit update descending skip)) (ensure-db () (db-request (cat (url-encode *db-name*) "/_design/" (url-encode id) "/_view/" (url-encode view)) From peddy at common-lisp.net Sat Jun 6 19:15:18 2009 From: peddy at common-lisp.net (peddy) Date: Sat, 06 Jun 2009 15:15:18 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv20505 Modified Files: tests.lisp Log Message: Changed db existance test to recognized new error message string --- /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/04/19 22:48:32 1.16 +++ /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/06/06 19:15:18 1.17 @@ -292,7 +292,7 @@ db-non-existance-test (ensure (setf *db-name* (create-temp-db-name))) (ensure-same "not_found" (document-property :|error| (get-db-info))) - (ensure-same "Missing" (document-property :|reason| (get-db-info)))) + (ensure-same "no_db_file" (document-property :|reason| (get-db-info)))) (addtest (clouchdb-db-admin-tests) (:documentation "Create a database and ensure it's there, ensure it's deleted too") From peddy at common-lisp.net Sat Jun 27 00:51:45 2009 From: peddy at common-lisp.net (peddy) Date: Fri, 26 Jun 2009 20:51:45 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv19775 Modified Files: clouchdb.lisp Log Message: Add copy-document and all-docs-by-seq --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/06 18:37:10 1.33 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/27 00:51:42 1.34 @@ -654,6 +654,27 @@ (put-document doc :id id :attachments attachments) (post-document doc))) +(defun copy-document (from-id to-id &key revision) + "Copy one document to another document. If the destination already +exists, and the intention is to overwrite the destination, then the +revision parameter must be specified and must be the revision of the +destination document." + (let ((id (if revision (cat to-id "?rev=" revision) to-id))) + (ensure-db () + (db-request (cat (url-encode *db-name*) "/" + (url-encode from-id)) + :content-type "text/plain" + :external-format-out +utf-8+ + :content-length nil + :method :copy + :additional-headers `(("Destination" . ,id)))))) + +(defun all-docs-by-seq () + "See all documents that were updated and deleted, in the order these +actions are done." + (ensure-db () + (db-request (cat (url-encode *db-name*) "/_all_docs_by_seq")))) + (defun as-deleted-document (doc) "Return specified document in a special document format used by bulk-document-update to indicate that the document should be deleted From peddy at common-lisp.net Sat Jun 27 13:05:23 2009 From: peddy at common-lisp.net (peddy) Date: Sat, 27 Jun 2009 09:05:23 -0400 Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: Update of /project/clouchdb/cvsroot/clouchdb/src In directory cl-net:/tmp/cvs-serv14227 Modified Files: clouchdb.lisp Log Message: Updated view parameters to reflect CouchDb changes --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/27 00:51:42 1.34 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/06/27 13:05:23 1.35 @@ -25,8 +25,7 @@ (in-package :clouchdb) (defvar *host* "localhost" "CouchDb server host name") -(defvar *port* "5984" - "As of version 7.2, the IANA assigned CouchDb port (was 8888)") +(defvar *port* "5984" "The IANA assigned CouchDb port") (defvar *db-name* "default" "Default database name") (defvar *protocol* "http" "http or https") (defvar *document-update-fn* nil) @@ -71,10 +70,16 @@ (:start-key . ((:name . "startkey") (:fn . document-to-json))) (:start-key-docid . ((:name . "startkey_docid") (:fn . document-to-json))) (:end-key . ((:name . "endkey") (:fn . document-to-json))) + (:end-key-docid . ((:name . "endkey_docsid") (:fn . document-to-json))) (:limit . ((:name . "limit") (:fn . value-as-string))) - (:update . ((:name . "update") (:fn . false-if-false))) + (:stale . ((:name . "stale") (:fn . value-as-string))) (:descending . ((:name . "descending") (:fn . true-if-true))) - (:skip . ((:name . "skip") (:fn . value-as-integer)))) + (:skip . ((:name . "skip") (:fn . document-to-json))) + (:group . ((:name . "group") (:fn . true-if-true))) + (:group-level . ((:name . "group_level") (:fn . document-to-json))) + (:reduce . ((:name . "reduce") (:fn . false-if-false))) + (:include-docs . ((:name . "include_docs") (:fn . true-if-true))) + (:update . ((:name . "update") (:fn . false-if-false)))) "Definitions for how invoke-view keyword parameters are translated into CouchDb parameters") @@ -669,11 +674,18 @@ :method :copy :additional-headers `(("Destination" . ,id)))))) -(defun all-docs-by-seq () +(defun all-docs-by-seq (&rest options &key key start-key + start-key-docid end-key end-key-docid limit + stale descending skip group group-level reduce + include-docs) "See all documents that were updated and deleted, in the order these actions are done." + (declare (ignore key start-key start-key-docid end-key end-key-docid + limit stale descending skip group group-level + reduce include-docs)) (ensure-db () - (db-request (cat (url-encode *db-name*) "/_all_docs_by_seq")))) + (db-request (cat (url-encode *db-name*) "/_all_docs_by_seq") + :parameters (transform-params options *view-options*)))) (defun as-deleted-document (doc) "Return specified document in a special document format used by @@ -732,11 +744,14 @@ ;; Views API ;; -(defun ad-hoc-view (view &rest options &key key start-key start-key-docid - end-key count update descending skip) +(defun ad-hoc-view (view &rest options &key key start-key + start-key-docid end-key end-key-docid limit stale + descending skip group group-level reduce + include-docs) "Execute query using an ad-hoc view." - (declare (ignore key start-key start-key-docid end-key count - update descending skip)) + (declare (ignore key start-key start-key-docid end-key end-key-docid + limit stale descending skip group group-level + reduce include-docs)) (ensure-db () (db-request (cat (url-encode *db-name*) "/_temp_view") :method :post @@ -804,8 +819,10 @@ (delete-document :id (cat "_design/" (url-encode id)) :revision revision :if-missing if-missing))) -(defun invoke-view (id view &rest options &key key start-key start-key-docid - end-key limit update descending skip) +(defun invoke-view (id view &rest options &key key start-key + start-key-docid end-key end-key-docid limit stale + descending skip group group-level reduce + include-docs) "Invoke a view by specifiying the document ID that contains the view and the name of the contained view. The key parameter specifies an optional value to match against the view's mapped field. The start-key @@ -814,8 +831,9 @@ returns results in reverse order. If update is t, does not refresh view for query, use for higher performance but possible data inconsistency." - (declare (ignore key start-key start-key-docid end-key - limit update descending skip)) + (declare (ignore key start-key start-key-docid end-key end-key-docid + limit stale descending skip group group-level + reduce include-docs)) (ensure-db () (db-request (cat (url-encode *db-name*) "/_design/" (url-encode id) "/_view/" (url-encode view))