2017 © Pedro Peláez
 

library key-value-store

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

image

doctrine/key-value-store

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  • Saturday, July 9, 2016
  • by beberlei
  • Repository
  • 24 Watchers
  • 172 Stars
  • 71,831 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 46 Forks
  • 19 Open issues
  • 9 Versions
  • 6 % Grown

The README.md

Doctrine Key Value Stores

Build Status, (*1)

The Persistence interfaces are rather overkill for many implementations in the NoSQL world that are only key-value stores with some additional features on top. Doctrine Key Value Store to the rescue. This project offers a much simpler lightweight API that is centered on a key-value API to fetch/save objects., (*2)

  • Single- or multi-value primary keys
  • Unstructured/schema-less values that are mapped onto objects
  • Depending on the implementation embedded values/objects are supported
  • No complex mapping necessary, just put @Entity on the class and all properties are automatically mapped unless @Transient is given. At least one property has to be @Id. Depends on the underlying vendor though.
  • Properties dont have to exist on the class, public properties are created for missing ones.
  • No support for references to other objects
  • EventListener for ODM/ORM that allows to manage key-value entities and collections of them as properties (postLoad, postUpdate, postPersist, postRemove)
  • Stripped down Object Manager Interface
  • Data-mapper as any other Doctrine library and persistence and data-objects are separated.
  • Inheritance (Single- or Multiple-Storage)

Implementations

Following vendors are targeted:, (*3)

  • Microsoft Azure Table (Implemented)
  • Doctrine\Common\Cache provider (Implemented)
  • RDBMS (Implemented)
  • Couchbase (Implemented)
  • Amazon DynamoDB (Implemented)
  • CouchDB (Implemented)
  • Cassandra
  • MongoDB (Implemented)
  • Riak (Implemented)
  • Redis (Implemented)

We happily accept contributions for any of the drivers., (*4)

Example

Suppose we track e-mail campaigns based on campaign id and recipients., (*5)

<?php
use Doctrine\KeyValueStore\Mapping\Annotations as KeyValue;

/**
 * @KeyValue\Entity(storageName="responses")
 */
class Response
{
    const RECEIVE = 0;
    const OPEN = 10;
    const CLICK = 20;
    const ACTION = 30;

    /** @KeyValue\Id */
    private $campaign;
    /** @KeyValue\Id */
    private $recipient;
    private $status;
    private $date;

    public function __construct($campaign, $recipient, $status)
    {
        $this->campaign = $campaign;
        $this->recipient = $recipient;
        $this->status = $status;
    }
}

Create

<?php
$response = new Response("1234", "kontakt@beberlei.de", Response::RECEIVE);

$entityManager->persist($response);
//.... persists as much as you can :-)

$entityManager->flush();

Read

<?php
$response = $entityManager->find("Response",array("campaign" => "1234","recipient" => "kontakt@beberlei.de"));

Update

same as create, just reuse the same id., (*6)

Delete

<?php
$response = $entityManager->find("Response",array("1234","kontakt@beberlei.de"));
$entityManager->remove($response);
$entityManager->flush();

Configuration

There is no factory yet that simplifies the creation process, here is the full code necessary to instantiate a KeyValue EntityManager with a Doctrine Cache backend:, (*7)

<?php
use Doctrine\KeyValueStore\EntityManager;
use Doctrine\KeyValueStore\Configuration;
use Doctrine\KeyValueStore\Mapping\AnnotationDriver;
use Doctrine\KeyValueStore\Storage\DoctrineCacheStorage;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Annotations\AnnotationReader;

$cache = new ArrayCache;
$storage = new DoctrineCacheStorage($cache);

$reader = new AnnotationReader();
$metadata = new AnnotationDriver($reader);
$config = new Configuration();
$config->setMappingDriverImpl($metadata);
$config->setMetadataCache($cache);

$entityManager = new EntityManager($storage, $config);

If you want to use WindowsAzure Table you can use the following configuration to instantiate the storage:, (*8)

use Doctrine\KeyValueStore\Storage\AzureSdkTableStorage;
use WindowsAzure\Common\ServicesBuilder;

$connectionString = ""; // Windows Azure Connection string
$builder = ServicesBuilder::getInstance();
$client = $builder->createTableService($connectionString);

$storage = new AzureSdkTableStorage($client);

If you want to use Doctrine DBAL as backend:, (*9)

$params = array();
$tableName = "storage";
$idColumnName = "id";
$dataColumnName = "serialized_data";

$conn = DriverManager::getConnection($params);
$storage = new DBALStorage($conn, $tableName, $idColumnName, $dataColumnName);

The Versions

09/07 2016

dev-force-cs

dev-force-cs

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/07 2016

dev-tests/refactoring

dev-tests/refactoring

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/07 2016

dev-master

9999999-dev

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/01 2016

dev-enhancement/excpetions-hierarchy

dev-enhancement/excpetions-hierarchy

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

16/12 2015

dev-enhancement/abstract-storage

dev-enhancement/abstract-storage

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/07 2015

v0.2

0.2.0.0

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/06 2012

dev-Common21

dev-Common21

Simple Key-Value Store Abstraction Layer that maps to PHP objects, allowing for many backends.

  Sources   Download

MIT

The Requires

 

07/04 2012

dev-ReferenceListener

dev-ReferenceListener

  Sources   Download

The Requires

 

06/04 2012

v0.1

0.1.0.0

  Sources   Download

The Requires