Skip to content

Commit 1a30571

Browse files
author
Josh Marchán
committed
Added create_target and continuous replication support to REPLICATE.
1 parent cede099 commit 1a30571

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/db.lisp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,21 @@ where appropriate, which makes for a nicer Lisp-side API."
127127
"Requests the current configuration from SERVER."
128128
(couch-request server "_config"))
129129

130-
(defun replicate (server source target)
130+
(defun replicate (server source target &key create-target-p continuousp
131+
&aux (alist `(("source" . ,source) ("target" . ,target))))
131132
"Replicates the database in SOURCE to TARGET. SOURCE and TARGET can both be either database names
132-
in the local server, or full URLs. Note that TARGET must already exist before replication can occur."
133-
(couch-request server :method :post
134-
:uri (format nil "_replicate?source=~A&target=~A" source target)))
133+
in the local server, or full URLs to local or remote databases. If CREATE-TARGET-P is true, the target
134+
database will automatically be created if it does not exist. If CONTINUOUSP is true, CouchDB will
135+
continue propagating any changes in SOURCE to TARGET."
136+
;; There are some caveats to the keyword arguments -
137+
;; create-target-p: doesn't actually seem to work at all in CouchDB 0.10
138+
;; continuousp: The CouchDB documentation warns that this continuous replication
139+
;; will only last as long as the CouchDB daemon is running. If the
140+
;; daemon is restarted, replication must be restarted as well.
141+
;; Note that there are plans to add 'persistent' replication.
142+
(when create-target-p (push '("create_target" . t) alist))
143+
(when continuousp (push '("continuous" . t) alist))
144+
(couch-request server "_replicate" :method :post :content (document-to-json alist)))
135145

136146
(defun stats (server)
137147
"Requests general statistics from SERVER."

0 commit comments

Comments
 (0)