Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add replicate() method

  • Loading branch information...
commit f25ea4e8091613ad91f2b747ba8a2a7b4dfcc593 1 parent 054089d
Arin Sarkissian authored
Showing with 26 additions and 8 deletions.
  1. +18 −3 Duckk_CouchDB/Duckk/CouchDB.php
  2. +8 −5 examples/employee-example.php
View
21 Duckk_CouchDB/Duckk/CouchDB.php
@@ -415,7 +415,7 @@ public function getAllDocumentsBySequence($database,
return $this->connection->get($uri);
}
-
+
/**
* PUT a design document
*
@@ -428,7 +428,7 @@ public function putDesignDocument($database, Duckk_CouchDB_DesignDocument &$doc)
{
return $this->putDocument($database, $doc);
}
-
+
/**
* GET the result of a view
*
@@ -442,9 +442,24 @@ public function getView($database, $designDocumentID, $viewName)
{
$viewName = preg_replace('/^_view\//', '', trim($viewName, '/'));
$designDocumentID = preg_replace('/^_design\//', '', trim($designDocumentID, '/'));
-
+
return $this->getDocument($database, "_design/{$designDocumentID}/_view/{$viewName}");
}
+
+ public function replicate($sourceDBName, $targetDB)
+ {
+ $data = array(
+ 'source' => $sourceDBName,
+ 'target' => $targetDB
+ );
+
+ $status = $this->connection->post(
+ Duckk_CouchDB_Util::makeDatabaseURI('/_replicate'),
+ json_encode($data)
+ );
+
+ return $status;
+ }
}
?>
View
13 examples/employee-example.php
@@ -49,10 +49,10 @@
$designDoc = new Duckk_CouchDB_DesignDocument();
$designDoc->setId('empData');
$designDoc->addView('all', 'function(doc) { emit(null, doc.salary); }');
-$designDoc->addView('totalPayroll',
- 'function(doc) { emit("salary", doc.salary); }',
+$designDoc->addView('totalPayroll',
+ 'function(doc) { emit("salary", doc.salary); }',
'function(name, salary) { return sum(salary) }'
-);
+);
// PUT the view
$resp = $couchdb->putDocument($database, $designDoc);
@@ -67,6 +67,9 @@
p("Result of the 'totalPayroll' view", $viewResult);
// clean up after ourselves and delete the DB
-$delete = $couchdb->deleteDatabase($database);
-p("deleted database: $database", $db);
+//$delete = $couchdb->deleteDatabase($database);
+//p("deleted database: $database", $db);
+
+$res = $couchdb->replicate("$database", "replicateddb");
+p("replication", $res);
?>
Please sign in to comment.
Something went wrong with that request. Please try again.