Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\NotFound as NotFoundException;
use Utopia\Database\Exception\Query as QueryException;
use Utopia\Database\Exception\Transaction as TransactionException;
use Utopia\Database\Query;

Expand Down Expand Up @@ -1606,10 +1605,6 @@ public function getSQLConditions(array $queries, array &$binds, string $separato
{
$conditions = [];
foreach ($queries as $query) {
if (!$query instanceof Query) {
throw new QueryException('Invalid query type: "' . \gettype($query) . '". Expected instances of "' . Query::class . '"');
}

if ($query->getMethod() === Query::TYPE_SELECT) {
continue;
}
Expand Down
30 changes: 30 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,8 @@ public function getDocument(string $collection, string $id, array $queries = [],

$attributes = $collection->getAttribute('attributes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentValidator($attributes);
if (!$validator->isValid($queries)) {
Expand Down Expand Up @@ -4336,6 +4338,8 @@ public function updateDocuments(
$attributes = $collection->getAttribute('attributes', []);
$indexes = $collection->getAttribute('indexes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentsValidator(
$attributes,
Expand Down Expand Up @@ -5734,6 +5738,8 @@ public function deleteDocuments(
$attributes = $collection->getAttribute('attributes', []);
$indexes = $collection->getAttribute('indexes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentsValidator(
$attributes,
Expand Down Expand Up @@ -5923,6 +5929,8 @@ public function find(string $collection, array $queries = [], string $forPermiss
$attributes = $collection->getAttribute('attributes', []);
$indexes = $collection->getAttribute('indexes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentsValidator(
$attributes,
Expand Down Expand Up @@ -6152,6 +6160,8 @@ public function count(string $collection, array $queries = [], ?int $max = null)
$attributes = $collection->getAttribute('attributes', []);
$indexes = $collection->getAttribute('indexes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentsValidator(
$attributes,
Expand Down Expand Up @@ -6200,6 +6210,8 @@ public function sum(string $collection, string $attribute, array $queries = [],
$attributes = $collection->getAttribute('attributes', []);
$indexes = $collection->getAttribute('indexes', []);

$this->checkQueriesType($queries);

if ($this->validate) {
$validator = new DocumentsValidator(
$attributes,
Expand Down Expand Up @@ -6685,4 +6697,22 @@ public function getCacheKeys(string $collectionId, ?string $documentId = null, a
$documentHashKey ?? null
];
}

/**
* @param array<Query> $queries
* @return void
* @throws QueryException
*/
public function checkQueriesType(array $queries)
{
foreach ($queries as $query) {
if (!$query instanceof Query) {
throw new QueryException('Invalid query type: "' . \gettype($query) . '". Expected instances of "' . Query::class . '"');
}

if ($query->isNested()) {
$this->checkQueriesType($query->getValues());
}
}
}
}