Drivers

The CouchDB Driver

Introduction

The CouchDB Driver is based on Mamluk's Couch DB client at https://1x.ax/mamluk/couchdb and provides a simple way to manage you CouchDB from your API. The driver supports connectivity to multiple CouchDB servers.

Installation

Install the driver via composer by running:

composer require kipchak/driver-couchdb

Initialise the Driver

Add the following line to your drivers/drivers.php file:

\Mamluk\Kipchak\Driver\CouchDB\CouchDB::iniitalise($container);

Configuration

The configuration in kipchak.couchdb.php can be used to configure muliple CouchDB servers:

return [
    'enabled' => true,
    'connections' => [
        'default' => [
            'host' => env('COUCHDB_HOST', 'http://couchdb'),
            'port' => env('COUCHDB_PORT', 5984),
            'username' => env('COUCHDB_USER', 'api'),
            'password' => env('COUCHDB_PASSWORD', 'api'),
            'database' => env('COUCHDB_DATABASE', 'api_database')
        ]
    ]
];

Please see the configuration file in the starter project at https://1x.ax/mamluk/kipchak/starter/~files/master/config/kipchak.couchdb.php for full configuration details.

Usage

Use it anywhere in the API. A Controller, Model, etc.

use Kipchak\Driver\CouchDB\CouchDB;

$db = CouchDB::get('default');

// Create database (if needed)
$db->createDatabase();

// Create document
$document = json_encode(['name' => 'John', 'email' => 'john@example.com']);
$db->create('user-123', $document);

// Read document
$result = $db->read('user-123');

// Update document
$updatedDoc = json_encode(['name' => 'John Doe', 'email' => 'john@example.com']);
$db->update('user-123', $updatedDoc);

// Delete document
$db->delete('user-123');

Git Repository

The source code for this driver is available on 1x.ax at https://1x.ax/mamluk/kipchak/drivers/couchdb.

Previous
Doctrine