mirror of
https://github.com/doctrine/KeyValueStore.git
synced 2026-03-24 08:42:12 +01:00
Compare commits
4 Commits
master
...
missing-ra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2117eef3e3 | ||
|
|
ff58187a3b | ||
|
|
e878a42d81 | ||
|
|
55f0840706 |
@@ -1,6 +1,8 @@
|
||||
language: php
|
||||
|
||||
services:
|
||||
- cassandra
|
||||
- couchdb
|
||||
- mongodb
|
||||
- redis-server
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"datastax/php-driver": "^1.0",
|
||||
"doctrine/couchdb": "^1.0.0-beta4",
|
||||
"doctrine/couchdb": "^2.0@alpha",
|
||||
"phpunit/phpunit": "^4.8|^5.0",
|
||||
"aws/aws-sdk-php": "^3.8",
|
||||
"riak/riak-client": "dev-master"
|
||||
|
||||
@@ -202,7 +202,7 @@ class RangeQuery
|
||||
/**
|
||||
* Execute query and return a result iterator.
|
||||
*
|
||||
* @return ResultIterator
|
||||
* @return array
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
|
||||
@@ -29,14 +29,14 @@ namespace Doctrine\KeyValueStore\Query;
|
||||
interface RangeQueryStorage
|
||||
{
|
||||
/**
|
||||
* Execute the range query and return a ResultIterator
|
||||
* Execute the range query and return an array
|
||||
*
|
||||
* @param RangeQuery $query
|
||||
* @param string $storageName
|
||||
* @param array $key
|
||||
* @param Closure $hydrateRow
|
||||
*
|
||||
* @return ResultIterator
|
||||
* @return array
|
||||
*/
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Doctrine\KeyValueStore\Storage;
|
||||
use Cassandra\ExecutionOptions;
|
||||
use Cassandra\Session;
|
||||
use Doctrine\KeyValueStore\NotFoundException;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
|
||||
|
||||
/**
|
||||
* Cassandra Storage Engine for KeyValueStore.
|
||||
@@ -31,7 +33,7 @@ use Doctrine\KeyValueStore\NotFoundException;
|
||||
*
|
||||
* @uses https://github.com/datastax/php-driver
|
||||
*/
|
||||
class CassandraStorage implements Storage
|
||||
class CassandraStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
/**
|
||||
* @var \Cassandra\Session
|
||||
@@ -176,6 +178,13 @@ class CassandraStorage implements Storage
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
namespace Doctrine\KeyValueStore\Storage;
|
||||
|
||||
use Doctrine\CouchDB\CouchDBClient;
|
||||
use Doctrine\CouchDB\Mango\MangoQuery;
|
||||
use Doctrine\KeyValueStore\Query\RangeQuery;
|
||||
use Doctrine\KeyValueStore\Query\RangeQueryStorage;
|
||||
|
||||
/**
|
||||
* Key-Value-Storage using a Doctrine CouchDB Client library as backend.
|
||||
@@ -30,7 +33,7 @@ use Doctrine\CouchDB\CouchDBClient;
|
||||
*
|
||||
* @author Emanuele Minotto <minottoemanuele@gmail.com>
|
||||
*/
|
||||
final class CouchDbStorage implements Storage
|
||||
final class CouchDbStorage implements Storage, RangeQueryStorage
|
||||
{
|
||||
/**
|
||||
* @var CouchDBClient
|
||||
@@ -116,7 +119,7 @@ final class CouchDbStorage implements Storage
|
||||
/**
|
||||
* @param string $storageName
|
||||
* @param array|string $key
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function flattenKey($storageName, $key)
|
||||
@@ -137,4 +140,72 @@ final class CouchDbStorage implements Storage
|
||||
|
||||
return $finalKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null)
|
||||
{
|
||||
$mangoQuery = new MangoQuery();
|
||||
$partitionKey = $query->getPartitionKey();
|
||||
|
||||
$conditions = [];
|
||||
foreach ($query->getConditions() as $condition) {
|
||||
switch ($condition[0]) {
|
||||
case RangeQuery::CONDITION_LE:
|
||||
$conditions[] = [
|
||||
$partitionKey => [
|
||||
'$lte' => $condition[1],
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
case RangeQuery::CONDITION_GE:
|
||||
$conditions[] = [
|
||||
$partitionKey => [
|
||||
'$gte' => $condition[1],
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
case RangeQuery::CONDITION_NEQ:
|
||||
$conditions[] = [
|
||||
$partitionKey => [
|
||||
'$ne' => $condition[1],
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
case RangeQuery::CONDITION_STARTSWITH:
|
||||
$conditions[] = [
|
||||
$partitionKey => [
|
||||
'$regex' => '^'.$condition[1],
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$conditions[] = [
|
||||
$partitionKey => [
|
||||
'$'.$condition[0] => $condition[1],
|
||||
],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$mangoQuery
|
||||
->select(['_id', $key])
|
||||
->where(['$and' => $conditions])
|
||||
->limit($query->getLimit());
|
||||
|
||||
$results = [];
|
||||
$mangoResults = $this->client->find($query);
|
||||
|
||||
foreach ($mangoResults as $mangoResult) {
|
||||
$results[] = $hydrateRow($mangoResult);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user