Пример #1
0
 public function delete()
 {
     try {
         $doc = couchDocument::getInstance(self::$client, $this->properties['_id']);
         self::$client->deleteDoc($doc);
     } catch (Exception $ex) {
         throw new Exception('Document doesn\'t exist');
     }
 }
 public function testViewGroup()
 {
     $this->_makeView();
     $docs = array(array("_id" => "one", "type" => "test", "param" => 1), array("_id" => "two", "type" => "test2", "param" => 2), array("_id" => "three", "type" => "test", "param" => 2), array("_id" => "four", "type" => "test3", "param" => 1), array("_id" => "five", "type" => "test2", "param" => 1));
     $this->client->storeDocs($docs);
     $infos = $this->client->getDatabaseInfos();
     $this->assertEquals($infos->doc_count, 6);
     $doc = couchDocument::getInstance($this->aclient, "_design/test");
     $views = $doc->views;
     $views->multigroup = new stdClass();
     $views->multigroup->map = "function (doc) {\n\t\t\tif ( doc.type && doc.param ) {\n\t\t\t\temit( [doc.type, doc.param], 1);\n\t\t\t}\n\t\t}";
     $views->multigroup->reduce = "function(keys,values) {\n\t\t\treturn sum(values);\n\t\t}";
     $doc->views = $views;
     $test = $this->client->group(true)->getView("test", "multigroup");
     $this->assertInternalType("object", $test);
     $this->assertObjectHasAttribute("rows", $test);
     $this->assertInternalType("array", $test->rows);
     $this->assertEquals(count($test->rows), 5);
     $test = $this->client->group(true)->group_level(1)->getView("test", "multigroup");
     $this->assertInternalType("object", $test);
     $this->assertObjectHasAttribute("rows", $test);
     $this->assertInternalType("array", $test->rows);
     $this->assertEquals(count($test->rows), 3);
 }