[clouchdb-cvs] CVS clouchdb/src
peddy
peddy at common-lisp.net
Tue Jul 7 19:50:20 UTC 2009
Update of /project/clouchdb/cvsroot/clouchdb/src
In directory cl-net:/tmp/cvs-serv28230
Modified Files:
clouchdb.lisp package.lisp tests.lisp
Log Message:
Renamed db-from-env to make-db
--- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/07/06 22:24:45 1.36
+++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2009/07/07 19:50:19 1.37
@@ -32,16 +32,16 @@
(defvar *debug-requests* nil)
-(defstruct db
+(defstruct (db (:constructor new-db))
host port name protocol
user password
document-fetch-fn document-update-fn)
(defun make-default-db ()
- (make-db :host *default-host*
- :port *default-port*
- :name *default-db-name*
- :protocol *default-protocol*))
+ (new-db :host *default-host*
+ :port *default-port*
+ :name *default-db-name*
+ :protocol *default-protocol*))
(defvar *db* (make-default-db) "A db struct object")
@@ -273,7 +273,7 @@
`(let ((,result (progn , at body)))
(when (and (listp ,result)
(equal "not_found" (document-property :|error| ,result)))
- (let ((*db* (if ,db-name-p (db-from-env :name ,db-name) *db*)))
+ (let ((*db* (if ,db-name-p (make-db :name ,db-name) *db*)))
(if (document-property :|error| (get-db-info))
(error 'db-does-not-exist
:result ,result :db *db* :uri (make-uri)))))
@@ -436,29 +436,29 @@
(json-to-document body)
(values body status reason-phrase)))))
-(defun db-from-env (&key host port name protocol user password
+(defun make-db (&key host port name protocol user password
document-fetch-fn document-update-fn (db *db*))
"Create, populate and return a database structure from the current
special variables and any supplied keyword parameters, the latter take
-precendence over the special vars."
- (make-db :host (or host (db-host db) *default-host*)
- :port (or port (db-port db) *default-port*)
- :name (or name (db-name db) *default-db-name*)
- :protocol (or protocol (db-protocol db) *default-protocol*)
- :user (or user (db-user db))
- :password (or password (db-password db))
- :document-fetch-fn (or document-fetch-fn (db-document-fetch-fn db))
- :document-update-fn (or document-update-fn (db-document-update-fn db))))
+precedence over the special variables."
+ (new-db :host (or host (db-host db) *default-host*)
+ :port (or port (db-port db) *default-port*)
+ :name (or name (db-name db) *default-db-name*)
+ :protocol (or protocol (db-protocol db) *default-protocol*)
+ :user (or user (db-user db))
+ :password (or password (db-password db))
+ :document-fetch-fn (or document-fetch-fn (db-document-fetch-fn db))
+ :document-update-fn (or document-update-fn (db-document-update-fn db))))
(defun set-connection (&key host db-name protocol port
(db *db*) document-update-fn document-fetch-fn)
"Set top-level connection information. The port may be specified as
a string or number. As of CouchDb version 7.2 the default port is
5984, prior to that it was 8888."
- (setf *db* (db-from-env :db db :host host :name db-name
- :protocol protocol :port port
- :document-update-fn document-update-fn
- :document-fetch-fn document-fetch-fn)))
+ (setf *db* (make-db :db db :host host :name db-name
+ :protocol protocol :port port
+ :document-update-fn document-update-fn
+ :document-fetch-fn document-fetch-fn)))
(defmacro with-connection ((&key db-name port protocol host
document-update-fn document-fetch-fn)
@@ -467,10 +467,10 @@
db-name, port or protocol. Port may be a string or a number, protocol
qis http or https. As of CouchDb version 7.2 the default port is 5984,
prior to that it was 8888."
- `(let ((*db* (db-from-env :name ,db-name :port ,port
- :protocol ,protocol :host ,host
- :document-fetch-fn ,document-fetch-fn
- :document-update-fn ,document-update-fn)))
+ `(let ((*db* (make-db :name ,db-name :port ,port
+ :protocol ,protocol :host ,host
+ :document-fetch-fn ,document-fetch-fn
+ :document-update-fn ,document-update-fn)))
(progn , at body)))
(defun document-properties (document)
@@ -500,7 +500,7 @@
can be avoided by specifying :ingore for if-exists. In this case no
error condition is generated. Specify :recreate to potentially delete
and create a new database."
- (let ((*db* (if db-name-p (db-from-env :db db :name db-name) db)))
+ (let ((*db* (if db-name-p (make-db :db db :name db-name) db)))
(let ((res (db-request (cat (url-encode (db-name *db*)) "/")
:method :put :content "")))
(if (equal "file_exists" (document-property :|error| res))
@@ -549,7 +549,7 @@
"Get information for named database, return ((:|error|
. \"not_found\") (:|reason| . \"no_db_file\")) if database does not
exist."
- (let ((*db* (db-from-env :db db :name db-name)))
+ (let ((*db* (make-db :db db :name db-name)))
(db-request (cat (url-encode (db-name *db*)) "/")
:method :get)))
@@ -562,7 +562,7 @@
(defun create-temp-db (&key (db-name-creator #'create-temp-db-name))
"Create a temporary database."
- (let ((db (db-from-env :name (funcall db-name-creator))))
+ (let ((db (make-db :name (funcall db-name-creator))))
(let ((res (create-db :db db)))
(if (document-property :|error| res)
(error (format t "Error ~S creating database: ~A"
@@ -580,7 +580,7 @@
(delete-db))
,result)))
-(defun replicate (target &key (source (db-from-env)))
+(defun replicate (target &key (source (make-db)))
"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
@@ -849,7 +849,7 @@
(document-property :|_attachments|
(cond ((stringp doc-or-id)
(get-document doc-or-id))
- ((and doc-or-id (listp doc-or-id))
+ ((listp doc-or-id)
doc-or-id)
(t nil))))
@@ -920,12 +920,19 @@
(defun save-attachment (doc-or-id attachment path &key
(if-does-not-exist :create)
(if-exists :supersede))
- "Save specified attachement in document to path on file system. The
-doc-or-id parameter must either be a string that identifies the
-document or the actual document that contains the attachment. The
-attachment parameter is either the string value of the attachment
-name, a keyword symbol as returned in the list of attachments or one
-of the elements of a document's attachment list."
+ "Save specified attachement from specified document to path on file
+system. The doc-or-id parameter must either be a document ID string or
+the actual document. The attachment parameter is either the string
+value of the attachment name, e.g. \"file.jpg\", a keyword symbol as
+returned in the car of the list of attachments, .e.g. :|file.jsp|, or
+one of the elements of a document's attachment list,
+e.g: (:|file.jsp| (:|stub| . T) (:|content_type|
+. \"image/jpeg\") (:|length| . 3543434)).
+
+If the path identifies a directory then the target file will be
+created in that directory with the same name as the attachment in the
+document. If the path ends with a file name the attachment will be
+created with that name."
(let ((in (get-attachment-stream doc-or-id attachment))
(output-path (if (> 0 (length (file-namestring path)))
path
@@ -982,6 +989,7 @@
(db-request (cat (url-encode (db-name *db*)) "/_design/" (url-encode id))
:method :put
:external-format-out +utf-8+
+ :content-type "application/json"
:content-length nil
:content
(cat "{\"language\" : \"" language "\","
--- /project/clouchdb/cvsroot/clouchdb/src/package.lisp 2009/07/06 22:24:45 1.12
+++ /project/clouchdb/cvsroot/clouchdb/src/package.lisp 2009/07/07 19:50:20 1.13
@@ -84,7 +84,6 @@
:database
:db-document-fetch-fn
:db-document-update-fn
- :db-from-env
:db-host
:db-name
:db-password
--- /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/07/07 01:28:20 1.19
+++ /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2009/07/07 19:50:20 1.20
@@ -283,7 +283,7 @@
(addtest (clouchdb-db-admin-tests)
(:documentation "Ensure get-db-info reports non-existant databases")
db-non-existance-test
- (let ((*db* (db-from-env :name (create-temp-db-name))))
+ (let ((*db* (make-db :name (create-temp-db-name))))
(ensure-same "not_found" (document-property :|error|
(get-db-info)))
(ensure-same "no_db_file" (document-property :|reason| (get-db-info)))))
@@ -353,7 +353,7 @@
(deftestsuite clouchdb-doc-api-tests ()
()
(:dynamic-variables
- (*db* (db-from-env :db *db*)))
+ (*db* (make-db :db *db*)))
(:setup
(set-connection :db (create-temp-db)))
(:teardown
@@ -615,7 +615,7 @@
(deftestsuite clouchdb-replication-tests ()
()
(:dynamic-variables
- (*db* (db-from-env)))
+ (*db* (make-db)))
(:setup
(progn
(set-connection :db (create-temp-db))
@@ -672,7 +672,7 @@
(deftestsuite clouchdb-view-tests ()
()
(:dynamic-variables
- (*db* (db-from-env :db *db*)))
+ (*db* (make-db :db *db*)))
(:setup
(progn
(set-connection :db (create-temp-db))
More information about the clouchdb-cvs
mailing list