Doctrine Key Value Stores

简单旧PHP对象映射的键值抽象。(Abstraction for Key-Value to Plain Old PHP Object mapping.)

  • 所有者: doctrine/KeyValueStore
  • 平台: BSD, Linux, Mac, Windows
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Doctrine Key Value Stores

对于NoSQL世界中的许多实现而言,持久性(Persistence)接口相当过度,这些实现只是键值存储,顶部还有一些额外的功能。 Doctrine Key Value Store到救援。 这个项目提供了一个更简单的轻量级API,它以一个键值API为中心来获取/保存对象。

  • 单值或多值主键
  • 映射到对象的非结构化/无模式值
  • 根据实现支持嵌入的值/对象
  • 不需要复杂的映射,只需将@Entity放在类上,除非给出@Transient,否则所有属性都会自动映射。至少有一个属性必须是@Id。尽管取决于底层供应商。
  • 属性不必在类中存在,公共属性是为缺少的属性创建的。
  • 不支持引用其他对象
  • ODM/ORM的EventListener允许管理键值实体及其集合作为属性(postLoad,postUpdate,postPersist,postRemove)
  • 删除对象管理器界面
  • Data-mapper与其他Doctrine库以及持久性和数据对象是分开的。
  • 继承(单个或多个存储)

实现

以下供应商是针对性的:

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

我们很高兴接受任何厂商对驱动的贡献。

示例

假设我们根据广告系列ID和收件人跟踪电子邮件广告系列。

<?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;
    }
}

创建

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

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

$entityManager->flush();

读取

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

更新

与创建相同,只是重复使用相同的ID。

删除

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

配置

还没有简化创建过程的工厂,这里是使用Doctrine Cache后端实例化KeyValue EntityManager所需的完整代码:

<?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);

如果您想使用WindowsAzure表,您可以使用以下配置 实例化存储:

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);

如果您想使用Doctrine DBAL作为后端:

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

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

主要指标

概览
名称与所有者doctrine/KeyValueStore
主编程语言PHP
编程语言PHP (语言数: 2)
平台BSD, Linux, Mac, Windows
许可证MIT License
所有者活动
创建于2012-02-13 16:08:13
推送于2020-05-18 00:09:45
最后一次提交2019-11-15 19:45:19
发布数4
最新版本名称v0.4.0 (发布于 )
第一版名称v0.1 (发布于 2012-05-08 22:31:55)
用户参与
星数200
关注者数17
派生数59
提交数244
已启用问题?
问题数33
打开的问题数15
拉请求数54
打开的拉请求数6
关闭的拉请求数8
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

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", "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.

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:

<?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);