Git Product home page Git Product logo

phouch's Introduction

Phouch

Welcome to Phouch! CouchDB library for PHP.

Will be subject to change, unstable, under-development until version 1.0.0!

Usage

The following examples show common database transactions using Phouch.

###To start

Requiring the Phouch library is as simple as including the phouch autoloader, after that you're able to use the Phouch object to initiate database transactions or create Phouch entities.

require_once 'phouch.php';
$phouch = new Phouch\Phouch(array(
    'host' => 'example.com',
    'port' => 1234,
    'transport' => 'https'
));

###To get all databases

Phouch mirrors the CouchDB API very closely, each built-in database command will have similar, user friendly implementations in Phouch. For example, a GET request for retrieving all databases in Phouch, similar to CouchDB's _all_dbs command, could be used the following way.

$result = $phouch->getAllDatabases();

###Add a new database

Adding new databases to your CouchDB instance with Phouch is simple. We provide a simplified interface, as well as a full object interface for creating and handling Phouch entities (and therefore CouchDB entities) in real object-oriented fashion.

####Simplified

Simply pass an array to the Phouch object, and Phouch\Phouch::addDatabase() will parse the options provided and persist the database.

$result = $phouch->addDatabase(array('name' => 'songs'));

####Using Objects

Create your own Phouch\Database object, and send it to the Phouch object to be persisted with Phouch\Phouch::save(). The Phouch Entity Objects can accept an array in their constructor to set properties for that entity.

$phouch->save(new Phouch\Database(array('name' => 'songs')));

Equally, a full range of setters will be available to the object for integration with complex business logic in an elegant fashion.

$database = new Phouch\Database();

$database->setName('songs');

$phouch->save($database);

###Add new document to database

Phouch will maintain two parallel patterns of thought in usage, supporting the light weight, simplified implementation as well as the full object oriented implementation. Below are these implementations shown when adding documents to a database.

####Simplified

$result = $phouch->addDocument(array(
    'database' => 'songs', 
    'values' => array(
        'title' => 'Ice Ice Baby', 
        'artist' => 'Vanilla Ice')
));

####Using Objects

$phouch->save(new Phouch\Document(array(
    'database' => 'songs', 
    'values' => array(
        'title' => 'Ice Ice Baby', 
        'artist' => 'Vanilla Ice')
));

Equally, using setters on the object, and assigning the document a database from the document itself, then persisting the data.

$document = new Phouch\Document();
$songs = new Phouch\Database(array('name' => 'songs'))

$document->setDatabase($songs);
$document->setValue('title', 'Ice Ice Baby');
$document->setValue('artist', 'Vanilla Ice');

$phouch->save($document);

Same implementation, with the document itself being added to the database, then persisted.

$database = $phouch->getDatabase('songs');

$database->addDocument($document);

$phouch->save($database);

phouch's People

Contributors

dustinmoorman avatar jessiegreen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.