1
0
Fork 0
mirror of synced 2024-06-02 02:44:47 +12:00

fix(database): properly cast to int

This commit is contained in:
Torsten Dittmann 2021-07-05 11:33:47 +02:00
parent ae8583f3a2
commit d9986cb205
5 changed files with 25 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,15 @@ class MySQL extends Adapter
//$path = implode('.', $path);
$castToInt = array_key_exists($key, $filterTypes) && $filterTypes[$key] === 'numeric';
$key = $this->getPDO()->quote($key, PDO::PARAM_STR);
$value = $this->getPDO()->quote($value, PDO::PARAM_STR);
if ($castToInt) {
$value .= '+0';
}
//$path = $this->getPDO()->quote($path, PDO::PARAM_STR);
$options['offset'] = (int) $options['offset'];
$options['limit'] = (int) $options['limit'];
@ -676,7 +684,7 @@ class MySQL extends Adapter
ORDER BY sort_ff {$options['orderType']} %s";
$st = $this->getPDO()->prepare(\sprintf($query, $select, $range));
var_dump(\sprintf($query, $select, $range));
$st->execute();
$results = ['data' => []];

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