GithubHelp home page GithubHelp logo

isabella232 / keyvaluestore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doctrine/keyvaluestore

0.0 0.0 0.0 445 KB

Abstraction for Key-Value to Plain Old PHP Object mapping

Home Page: http://www.doctrine-project.org

License: MIT License

PHP 99.74% Shell 0.26%

keyvaluestore's Introduction

Doctrine Key Value Stores

Build Status

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.

  • 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:

  • 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.

Example

Suppose we track e-mail campaigns based on campaign id and recipients.

<?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", "[email protected]", Response::RECEIVE);

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

$entityManager->flush();

Read

<?php
$response = $entityManager->find("Response",array("campaign" => "1234","recipient" => "[email protected]"));

Update

same as create, just reuse the same id.

Delete

<?php
$response = $entityManager->find("Response",array("1234","[email protected]"));
$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:

<?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:

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:

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

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

keyvaluestore's People

Contributors

andreyvital avatar baachi avatar beberlei avatar deeky666 avatar emanueleminotto avatar guilhermeblanco avatar jonmchan avatar kevinyien avatar kick-the-bucket avatar larowlan avatar nicktacular avatar ocramius avatar pierredup avatar ryan-senn avatar samsonasik avatar simonsimcity avatar stanlemon 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.