ihor/ouchbase

Object key/value mapper (OKVM) for Couchbase written in Zephir

dev-master / 0.1.x-dev 2014-06-15 17:23 UTC

This package is auto-updated.

Last update: 2024-10-28 04:03:10 UTC


README

Ouchbase is an object key/value mapper (OKVM) for Couchbase. It is written in Zephir which allows you to write high performance PHP extensions without the headaches and timewastage of a C development cycle.

Installation

Just clone Ouchbase repository and run ./install.sh. If you have Zephir installed then you can execute ./build.sh.

To install Ouchbase with composer add the following to your composer.json

"require": {
    "ihor/ouchbase": "0.1.*@dev"
},
"scripts": {
    "post-install-cmd": ["./vendor/ihor/ouchbase/install.sh"],
    "post-update-cmd": ["./vendor/ihor/ouchbase/install.sh"]
},

Usage

class TestEntity implements \Ouchbase\Entity
{
    private $id;

    public $property;

    public function __construct($id, $property)
    {
        $this->id = $id;
        $this->property = $property;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getProperty()
    {
        return $this->property;
    }
}

class TestEntityRepository extends \Ouchbase\Repository
{
    public $keyPrefix = 'test:';

    protected $className = 'OuchbaseTest\TestEntity';

    public function findByProperty($property) { /** @todo */ }

    public function toObject($data)
    {
        return new TestEntity($data['id'], $data['property']);
    }

    public function toArray($entity)
    {
        return array(
            'id' => $entity->getId(),
            'property' => $entity->getProperty(),
        );
    }
}

$em = new \Ouchbase\EntityManager(new \Couchbase('localhost'));
$em->registerManagedEntityClass('TestEntity', 'TestEntityRepository');

$entity = new TestEntity('test-id', array('hello' => 'world'));

$em->persist($entity);
$em->flush();

$entity->property = array('world' => 'hello');
$em->flush();

$em->delete($entity);
$em->flush();

$entities = $em->getRepository('TestEntity')->findByProperty(42);

You can find more examples in test/OuchbaseTest/OuchbaseTest.php

Documentation

Please check stub.php to see Ouchbase API with documentation. Also use stub.php for autocompletion in your favourite IDE.