1
0
Fork 0
mirror of synced 2024-05-21 21:22:34 +12:00

Merge pull request #1349 from TorstenDittmann/fix-database-int-casting

fix(database): properly cast to int
This commit is contained in:
Eldad A. Fux 2021-07-06 13:43:46 +03:00 committed by GitHub
commit 0d4c5ab01e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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'];

View file

@ -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) {

View file

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