Merge pull request #1349 from TorstenDittmann/fix-database-int-casting
fix(database): properly cast to int
This commit is contained in:
commit
0d4c5ab01e
|
@ -436,6 +436,12 @@ App::get('/v1/database/collections/:collectionId/documents')
|
|||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
$types = [];
|
||||
foreach ($collection->getAttribute('rules') as $rule) {
|
||||
/** @var Document $rule */
|
||||
$types[$rule->getAttribute('key')] = $rule->getAttribute('type');
|
||||
}
|
||||
|
||||
$list = $projectDB->getCollection([
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
|
@ -446,7 +452,7 @@ App::get('/v1/database/collections/:collectionId/documents')
|
|||
'filters' => \array_merge($filters, [
|
||||
'$collection='.$collectionId,
|
||||
]),
|
||||
]);
|
||||
], $types);
|
||||
|
||||
// if (App::isDevelopment()) {
|
||||
// $collection
|
||||
|
|
|
@ -130,10 +130,11 @@ abstract class Adapter
|
|||
* Filter data sets using chosen queries
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $filterTypes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getCollection(array $options);
|
||||
abstract public function getCollection(array $options, array $filterTypes = []);
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
|
|
|
@ -517,12 +517,13 @@ class MySQL extends Adapter
|
|||
* Get Collection.
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $filterTypes
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
public function getCollection(array $options, array $filterTypes = [])
|
||||
{
|
||||
$start = \microtime(true);
|
||||
$orderCastMap = [
|
||||
|
@ -568,8 +569,14 @@ class MySQL extends Adapter
|
|||
|
||||
//$path = implode('.', $path);
|
||||
|
||||
if(array_key_exists($key, $filterTypes) && $filterTypes[$key] === 'numeric') {
|
||||
$value = (float) $value;
|
||||
} else {
|
||||
$value = $this->getPDO()->quote($value, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$key = $this->getPDO()->quote($key, PDO::PARAM_STR);
|
||||
$value = $this->getPDO()->quote($value, PDO::PARAM_STR);
|
||||
|
||||
//$path = $this->getPDO()->quote($path, PDO::PARAM_STR);
|
||||
$options['offset'] = (int) $options['offset'];
|
||||
$options['limit'] = (int) $options['limit'];
|
||||
|
|
|
@ -210,14 +210,15 @@ class Redis extends Adapter
|
|||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param array $filterTypes
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
public function getCollection(array $options, array $filterTypes = [])
|
||||
{
|
||||
$data = $this->adapter->getCollection($options);
|
||||
$data = $this->adapter->getCollection($options, $filterTypes);
|
||||
$keys = [];
|
||||
|
||||
foreach ($data as $node) {
|
||||
|
|
|
@ -145,10 +145,11 @@ class Database
|
|||
|
||||
/**
|
||||
* @param array $options
|
||||
* @param array $filterTypes
|
||||
*
|
||||
* @return Document[]
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
public function getCollection(array $options, array $filterTypes = [])
|
||||
{
|
||||
$options = \array_merge([
|
||||
'offset' => 0,
|
||||
|
@ -161,7 +162,7 @@ class Database
|
|||
'filters' => [],
|
||||
], $options);
|
||||
|
||||
$results = $this->adapter->getCollection($options);
|
||||
$results = $this->adapter->getCollection($options, $filterTypes);
|
||||
|
||||
foreach ($results as &$node) {
|
||||
$node = $this->decode(new Document($node));
|
||||
|
|
Loading…
Reference in a new issue