save-doc-list-with-example
Tue Jun 24 17:41:27 PDT 2008 Ryszard Szopa <ryszard.szopa@gmail.com>
* save-doc-list-with-example
diff -rN -u old-cl-couch/object-layer/document.lisp new-cl-couch/object-layer/document.lisp
--- old-cl-couch/object-layer/document.lisp 2014-07-11 23:51:38.000000000 -0700
+++ new-cl-couch/object-layer/document.lisp 2014-07-11 23:51:38.000000000 -0700
@@ -61,6 +61,8 @@
(declare (ignore doc err-on-failure))
t)
+(defmethod default-db-of ((doc doc))
+ (original-db-of doc))
;; Copyright (C) 2008
;; Ryszard Szopa <ryszard.szopa@gmail.com>
diff -rN -u old-cl-couch/object-layer/transaction.lisp new-cl-couch/object-layer/transaction.lisp
--- old-cl-couch/object-layer/transaction.lisp 2014-07-11 23:51:38.000000000 -0700
+++ new-cl-couch/object-layer/transaction.lisp 2014-07-11 23:51:38.000000000 -0700
@@ -1,6 +1,6 @@
(in-package :cl-couchdb-object-layer)
-(export '(with-transaction save-doc delete-doc))
+(export '(with-transaction save-doc delete-doc save-doc-list-with-example))
(defvar *in-transaction* nil)
(defvar *documents-in-transaction* nil)
@@ -25,8 +25,15 @@
(declare (ignore null db server)))
(defmethod save-doc ((list list) &optional db (server *couchdb-server*))
- (let* ((some-doc (car list))
- (db (or db (when (typep some-doc 'validated-doc) (default-db-of some-doc)) (original-db-of some-doc))))
+ (save-doc-list-with-example (car list) db server))
+
+(defgeneric save-doc-list-with-example (example list &optional db server)
+ (:documentation "Save a list of docs, with example provided for
+ class dispatching. This method is called by `save-doc' if called on
+ a list."))
+
+(defmethod save-doc-list-with-example ((doc doc) (list list) &optional db (server *couchdb-server*))
+ (let* ((db (or db (default-db-of doc))))
(iter (for doc in list)
(validates doc))
(destructuring-bind (_ (_results . results))
@@ -35,13 +42,11 @@
;the hello kitty thing is so
;that cl-json knows it is an
;object, not an array :/
-
(declare (ignore _ _results))
(iter (for res in results)
(for doc in list)
(setf (@ doc :_rev) (@ res :rev))))))
-
(defmacro with-transaction ((db &key (server *couchdb-server*)) &body body)
`(let ((*in-transaction* t)
*documents-in-transaction*)