lithium\data\source\http\adapter\CouchDb::delete PHP Method

delete() public method

Delete document.
public delete ( string $query, array $options = [] ) : boolean
$query string
$options array
return boolean
    public function delete($query, array $options = array())
    {
        $params = compact('query', 'options');
        $conn =& $this->connection;
        $config = $this->_config;
        return $this->_filter(__METHOD__, $params, function ($self, $params) use(&$conn, $config) {
            $query = $params['query'];
            $params = $query->export($self);
            list($_path, $conditions) = $params['conditions'];
            $data = $query->data();
            if (!empty($data['rev'])) {
                $conditions['rev'] = $data['rev'];
            }
            $result = json_decode($conn->delete("{$config['database']}/{$_path}", $conditions));
            $result = isset($result->ok) && $result->ok === true;
            if ($query->entity()) {
                $query->entity()->sync(null, array(), array('dematerialize' => true));
            }
            return $result;
        });
    }

Usage Example

示例#1
0
 public function testDelete()
 {
     $couchdb = new CouchDb($this->_testConfig);
     $this->query->data(array('id' => 12345, 'rev' => '1-1', 'name' => 'Acme Inc'));
     $result = $couchdb->delete($this->query);
     $this->assertTrue($result);
     $expected = '/lithium-test/12345';
     $result = $couchdb->last->request->path;
     $this->assertEqual($expected, $result);
     $expected = 'rev=1-1';
     $result = $couchdb->last->request->params;
     $this->assertEqual($expected, $result);
 }