2017 © Pedro Peláez
 

library couchdb

CouchDB Client

image

doctrine/couchdb

CouchDB Client

  • Monday, May 7, 2018
  • by beberlei
  • Repository
  • 9 Watchers
  • 98 Stars
  • 149,392 Installations
  • PHP
  • 32 Dependents
  • 13 Suggesters
  • 55 Forks
  • 16 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

Doctrine CouchDB v2.x Client

Build Status StyleCI, (*1)

Simple API that wraps around CouchDBs v2.x HTTP API., (*2)

For CouchDB 1.x, please check our release/1.0.0 branch., (*3)

Features

  • Create, Delete, List Databases
  • Create, Update, Delete Documents
  • Bulk API for Creating/Updating Documents
  • Find Documents by ID
  • Generate UUIDs
  • Design Documents
  • Query _all_docs view
  • Query Changes Feed
  • Query Views
  • Compaction Info and Triggering APIs
  • Replication API
  • Symfony Console Commands
  • Find Documents using Mango Query

Installation

With Composer:, (*4)

{
    "require": {
        "doctrine/couchdb": "@dev"
    }
}

Usage

Basic Operations

Covering the basic CRUD Operations for databases and documents:, (*5)

<?php
$client = \Doctrine\CouchDB\CouchDBClient::create(array('dbname' => 'doctrine_example'));

// Create a database.
$client->createDatabase($client->getDatabase());

// Create a new document.
list($id, $rev) = $client->postDocument(array('foo' => 'bar'));

// Update a existing document. This will increment the revision.
list($id, $rev) = $client->putDocument(array('foo' => 'baz'), $id, $rev);

// Fetch single document by id.
$doc = $client->findDocument($id);

// Fetch multiple documents at once.
$docs = $client->findDocuments(array($id));

// Return all documents from database (_all_docs?include_docs=true).
$allDocs = $client->allDocs();

// Delete a single document.
$client->deleteDocument($id, $rev);

// Delete a database.
$client->deleteDatabase($client->getDatabase());

//Search documents using Mango Query CouchDB v2.x

$selector = ['_id'=>['$gt'=>null]];
$options = ['limit'=>1,'skip'=>1,'use_index'=>['_design/doc','index'],'sort'=>[['_id'=>'desc']]];
$query = new \Doctrine\CouchDB\Mango\MangoQuery($selector,$options);
$docs = $client->find($query);

$query = new \Doctrine\CouchDB\Mango\MangoQuery();
$query->select(['_id', 'name'])->where(['$and'=> [
            [
              'name'=> [
                '$eq'=> 'Under the Dome',
              ],
              'genres'=> [
                '$in'=> ['Drama','Comedy'],
              ],
            ],
          ])->sort([['_id'=>'desc']])->limit(1)->skip(1)->use_index(['_design/doc','index']);
$docs = $client->find($query);

Views

A simple example demonstrating how to create views and query them:, (*6)

<?php
class ArticlesDesignDocument implements \Doctrine\CouchDB\View\DesignDocument
{
    public function getData()
    {
        return array(
            'language' => 'javascript',
            'views' => array(
                'by_author' => array(
                    'map' => 'function(doc) {
                        if(\'article\' == doc.type) {
                            emit(doc.author, doc._id);
                        }
                    }',
                    'reduce' => '_count'
                ),
            ),
        );
    }
}

$client->createDesignDocument('articles', new ArticlesDesignDocument());

// Fill database with some data.
foreach (array('Alice', 'Bob', 'Bob') as $author) {
    $client->postDocument(array(
        'type' => 'article',
        'author' => $author,
        'content' => 'Lorem ipsum'
    ));
}

// Query all articles.
$query = $client->createViewQuery('articles', 'by_author');
$query->setReduce(false);
$query->setIncludeDocs(true);
$result = $query->execute();
foreach ($result as $row) {
    $doc = $row['doc'];
    echo 'Article by ', $doc['author'], ': ', $doc['content'], "\n";
}
// Article by Alice: Lorem ipsum
// Article by Bob: Lorem ipsum
// Article by Bob: Lorem ipsum


// Query all articles written by bob.
$query = $client->createViewQuery('articles', 'by_author');
$query->setKey('Bob');
// ...


// Query the _count of articles each author has written.
$query = $client->createViewQuery('articles', 'by_author');
$query->setReduce(true);
$query->setGroupLevel(1); // group_level=1 means grouping by author.
$result = $query->execute();
foreach ($result as $row) {
    echo 'Author ', $row['key'], ' has written ', $row['value'], ' articles', "\n";
}
// Author Alice has written 1 articles
// Author Bob has written 2 articles

The Versions

07/05 2018

dev-master

9999999-dev http://www.doctrine-project.org

CouchDB Client

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

07/05 2018

2.0.0-alpha1

2.0.0.0-alpha1 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

21/12 2017

dev-release/1.0.0

dev-release/1.0.0 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

11/11 2015

1.0.0-beta4

1.0.0.0-beta4 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

11/11 2015

1.0.0-beta3

1.0.0.0-beta3 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

06/07 2015

1.0.0-beta2

1.0.0.0-beta2 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

LGPL

The Requires

 

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

02/07 2015

1.0.0-beta1

1.0.0.0-beta1 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

LGPL

The Requires

 

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

21/05 2015

1.0.0-alpha2

1.0.0.0-alpha2 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

LGPL

The Requires

 

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence

28/07 2013

1.0.0-alpha1

1.0.0.0-alpha1 http://www.doctrine-project.org

CouchDB Client

  Sources   Download

LGPL

The Requires

 

by Benjamin Eberlei
by Lukas Kahwe Smith

couchdb persistence