Add support for select queries

This commit is contained in:
Matej Bačo 2025-08-26 15:15:10 +02:00
parent 34658aac9b
commit 43f75d082e
2 changed files with 49 additions and 23 deletions

View file

@ -11,6 +11,7 @@ use Utopia\Database\Validator\Query\Filter;
use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Limit;
use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\Query\Offset;
use Utopia\Database\Validator\Query\Order; use Utopia\Database\Validator\Query\Order;
use Utopia\Database\Validator\Query\Select;
class Base extends Queries class Base extends Queries
{ {
@ -40,6 +41,7 @@ class Base extends Queries
$allowedAttributesLookup[$attribute] = true; $allowedAttributesLookup[$attribute] = true;
} }
$allAttributes = [];
$attributes = []; $attributes = [];
foreach ($collection['attributes'] as $attribute) { foreach ($collection['attributes'] as $attribute) {
$key = $attribute['$id']; $key = $attribute['$id'];
@ -48,33 +50,43 @@ class Base extends Queries
continue; continue;
} }
$attributes[] = new Document([ $attributeDocument = new Document([
'key' => $key, 'key' => $key,
'type' => $attribute['type'], 'type' => $attribute['type'],
'array' => $attribute['array'], 'array' => $attribute['array'],
]); ]);
$attributes[] = $attributeDocument;
$allAttributes[] = $attributeDocument;
} }
$attributes[] = new Document([ $internalAttributes = [
'key' => '$id', new Document([
'type' => Database::VAR_STRING, 'key' => '$id',
'array' => false, 'type' => Database::VAR_STRING,
]); 'array' => false,
$attributes[] = new Document([ ]),
'key' => '$createdAt', new Document([
'type' => Database::VAR_DATETIME, 'key' => '$createdAt',
'array' => false, 'type' => Database::VAR_DATETIME,
]); 'array' => false,
$attributes[] = new Document([ ]),
'key' => '$updatedAt', new Document([
'type' => Database::VAR_DATETIME, 'key' => '$updatedAt',
'array' => false, 'type' => Database::VAR_DATETIME,
]); 'array' => false,
$attributes[] = new Document([ ]),
'key' => '$sequence', new Document([
'type' => Database::VAR_INTEGER, 'key' => '$sequence',
'array' => false, 'type' => Database::VAR_INTEGER,
]); 'array' => false,
])
];
foreach($internalAttributes as $attribute) {
$attributes[] = $attribute;
$allAttributes[] = $attribute;
}
$validators = [ $validators = [
new Limit(), new Limit(),
@ -84,6 +96,15 @@ class Base extends Queries
new Order($attributes), new Order($attributes),
]; ];
if($this->isSelectQueryAllowed()) {
$validators[] = new Select($allAttributes);
}
parent::__construct($validators); parent::__construct($validators);
} }
public function isSelectQueryAllowed(): bool
{
return true;
}
} }

View file

@ -22,4 +22,9 @@ class Deployments extends Base
{ {
parent::__construct('deployments', self::ALLOWED_ATTRIBUTES); parent::__construct('deployments', self::ALLOWED_ATTRIBUTES);
} }
public function isSelectQueryAllowed(): bool
{
return true;
}
} }