mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Add support for select queries
This commit is contained in:
parent
34658aac9b
commit
43f75d082e
2 changed files with 49 additions and 23 deletions
|
|
@ -11,6 +11,7 @@ use Utopia\Database\Validator\Query\Filter;
|
|||
use Utopia\Database\Validator\Query\Limit;
|
||||
use Utopia\Database\Validator\Query\Offset;
|
||||
use Utopia\Database\Validator\Query\Order;
|
||||
use Utopia\Database\Validator\Query\Select;
|
||||
|
||||
class Base extends Queries
|
||||
{
|
||||
|
|
@ -40,6 +41,7 @@ class Base extends Queries
|
|||
$allowedAttributesLookup[$attribute] = true;
|
||||
}
|
||||
|
||||
$allAttributes = [];
|
||||
$attributes = [];
|
||||
foreach ($collection['attributes'] as $attribute) {
|
||||
$key = $attribute['$id'];
|
||||
|
|
@ -47,34 +49,44 @@ class Base extends Queries
|
|||
if (!isset($allowedAttributesLookup[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attributes[] = new Document([
|
||||
|
||||
$attributeDocument = new Document([
|
||||
'key' => $key,
|
||||
'type' => $attribute['type'],
|
||||
'array' => $attribute['array'],
|
||||
]);
|
||||
}
|
||||
|
||||
$attributes[] = new Document([
|
||||
'key' => '$id',
|
||||
'type' => Database::VAR_STRING,
|
||||
'array' => false,
|
||||
]);
|
||||
$attributes[] = new Document([
|
||||
'key' => '$createdAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]);
|
||||
$attributes[] = new Document([
|
||||
'key' => '$updatedAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]);
|
||||
$attributes[] = new Document([
|
||||
'key' => '$sequence',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'array' => false,
|
||||
]);
|
||||
$attributes[] = $attributeDocument;
|
||||
$allAttributes[] = $attributeDocument;
|
||||
}
|
||||
|
||||
$internalAttributes = [
|
||||
new Document([
|
||||
'key' => '$id',
|
||||
'type' => Database::VAR_STRING,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$createdAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$updatedAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$sequence',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'array' => false,
|
||||
])
|
||||
];
|
||||
|
||||
foreach($internalAttributes as $attribute) {
|
||||
$attributes[] = $attribute;
|
||||
$allAttributes[] = $attribute;
|
||||
}
|
||||
|
||||
$validators = [
|
||||
new Limit(),
|
||||
|
|
@ -83,7 +95,16 @@ class Base extends Queries
|
|||
new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES),
|
||||
new Order($attributes),
|
||||
];
|
||||
|
||||
if($this->isSelectQueryAllowed()) {
|
||||
$validators[] = new Select($allAttributes);
|
||||
}
|
||||
|
||||
parent::__construct($validators);
|
||||
}
|
||||
|
||||
public function isSelectQueryAllowed(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,9 @@ class Deployments extends Base
|
|||
{
|
||||
parent::__construct('deployments', self::ALLOWED_ATTRIBUTES);
|
||||
}
|
||||
|
||||
public function isSelectQueryAllowed(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue