diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 5af0e6ab4e..4c87a6be12 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -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 diff --git a/src/Appwrite/Database/Adapter.php b/src/Appwrite/Database/Adapter.php index bb650e844f..d8a1d0ecfc 100644 --- a/src/Appwrite/Database/Adapter.php +++ b/src/Appwrite/Database/Adapter.php @@ -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 diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index 86d79a1122..fc3370c778 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -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']; diff --git a/src/Appwrite/Database/Adapter/Redis.php b/src/Appwrite/Database/Adapter/Redis.php index 4e5619c5ff..68946b0469 100644 --- a/src/Appwrite/Database/Adapter/Redis.php +++ b/src/Appwrite/Database/Adapter/Redis.php @@ -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) { diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index bf1033eb81..400a145168 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -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));