CouchDB icon indicating copy to clipboard operation
CouchDB copied to clipboard

Extend Result with more helpers

Open h4cc opened this issue 9 years ago • 1 comments

I added some more helpers to the Result class, like this:

    public function getFirstDoc()
    {
        $row = $this->getFirstRow();

        return $row ? $row['doc'] : false;
    }

    public function getDocs()
    {
        return array_map(function($row) {
            return $row['doc'];
        }, $this->getRows());
    }

    public function isEmpty()
    {
        return !(bool)$this->data['rows'];
    }

    public function isError()
    {
        return array_key_exists('error', $this->data);
    }

    public function isNotFound()
    {
        return $this->isError() && ($this->data['error'] == 'not_found');
    }

Maybe these could be usefull in your Result class.

h4cc avatar Jul 09 '15 07:07 h4cc

The result class isn't really finished yet. Submit a PR, i will review and merge it :)

Baachi avatar Jul 11 '15 07:07 Baachi