Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 58
Feat 5376 improve the select query#287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
07777361ca3476fedafbf0278adfcde877cb93544f3a3b51fe39efe760bae57c4c6e2af901305e61eb130313f8c5fd637327364ea85afec24d20bc3a2d25c4e480ad856dedb3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1331,10 +1331,28 @@ protected function getAttributeProjection(array $selections, string $prefix = '' | ||
| } | ||
| $projection['_uid'] = 1; | ||
| $projection['_id'] = 1; | ||
| $projection['_permissions'] = 1; | ||
| $projection['_createdAt'] = 1; | ||
| $projection['_updatedAt'] = 1; | ||
Comment on lines
1335
to
1336
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to make sure these are not set by default the same as maraidb
| ||
| $projection['_permissions'] = 1; | ||
| if (isset($projection['$id'])) { | ||
| unset($projection['$id']); | ||
| } | ||
| if (isset($projection['$internalId'])) { | ||
| unset($projection['$internalId']); | ||
| } | ||
| if (isset($projection['$permissions'])) { | ||
| unset($projection['$permissions']); | ||
| } | ||
| if (isset($projection['$createdAt'])) { | ||
| unset($projection['$createdAt']); | ||
| } | ||
| if (isset($projection['$updatedAt'])) { | ||
| unset($projection['$updatedAt']); | ||
| } | ||
| if (isset($projection['$collection'])) { | ||
| unset($projection['$collection']); | ||
| } | ||
| return $projection; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -121,6 +121,16 @@ class Database | ||
| public const EVENT_INDEX_CREATE = 'index_create'; | ||
| public const EVENT_INDEX_DELETE = 'index_delete'; | ||
| // Internal Parameters | ||
| public const INTERNAL_ATTRIBUTES = [ | ||
| '$id', | ||
| '$internalId', | ||
| '$createdAt', | ||
| '$updatedAt', | ||
| '$permissions', | ||
| '$collection' | ||
| ]; | ||
| protected Adapter $adapter; | ||
| protected Cache $cache; | ||
| @@ -2284,6 +2294,26 @@ public function getDocument(string $collection, string $id, array $queries = []) | ||
| $this->cache->save($cacheKey, $document->getArrayCopy()); | ||
| } | ||
| foreach ($queries as $query) { | ||
| if ($query->getMethod() == Query::TYPE_SELECT) { | ||
| $queriedValues = $query->getValues(); | ||
| $defaultKeys = Database::INTERNAL_ATTRIBUTES; | ||
| foreach ($queriedValues as $queriedValue) { | ||
| if (in_array($queriedValue, $defaultKeys)) { | ||
| $index = array_search($queriedValue, $defaultKeys); | ||
| unset($defaultKeys[$index]); | ||
| } | ||
| } | ||
| foreach ($defaultKeys as $defaultKey) { | ||
| if ($document->isSet($defaultKey)) { | ||
| $document->removeAttribute($defaultKey); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| $this->trigger(self::EVENT_DOCUMENT_READ, $document); | ||
| return $document; | ||
| @@ -4015,6 +4045,17 @@ public function find(string $collection, array $queries = [], ?int $timeout = nu | ||
| $results = $this->applyNestedQueries($results, $nestedQueries, $relationships); | ||
| // remove default keys $id and $permissions from the results | ||
| foreach ($queries as $query) { | ||
| if ($query->getMethod() === Query::TYPE_SELECT) { | ||
| foreach ($results as $result) { | ||
faisalill marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| foreach (Database::INTERNAL_ATTRIBUTES as $parameter) { | ||
| $result->removeAttribute($parameter); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| $this->trigger(self::EVENT_DOCUMENT_FIND, $results); | ||
| return $results; | ||
| @@ -4351,8 +4392,17 @@ public function decode(Document $collection, Document $document, array $selectio | ||
| } | ||
| } | ||
| if (empty($selections) || \in_array($key, $selections) || \in_array('*', $selections)) { | ||
| $document->setAttribute($key, ($array) ? $value : $value[0]); | ||
| if ( | ||
| empty($selections) | ||
| || \in_array($key, $selections) | ||
| || \in_array('*', $selections) | ||
| || \in_array($key, ['$createdAt', '$updatedAt']) | ||
| ) { | ||
| if (\in_array($key, ['$createdAt', '$updatedAt']) && $value[0] === null) { | ||
| continue; | ||
| } else { | ||
| $document->setAttribute($key, ($array) ? $value : $value[0]); | ||
| } | ||
| } | ||
| } | ||
| @@ -4510,6 +4560,8 @@ private function validateSelections(Document $collection, array $queries): array | ||
| } | ||
| } | ||
| $keys = \array_merge($keys, Database::INTERNAL_ATTRIBUTES); | ||
| $invalid = \array_diff($selections, $keys); | ||
| if (!empty($invalid) && !\in_array('*', $invalid)) { | ||
| throw new DatabaseException('Cannot select attributes: ' . \implode(', ', $invalid)); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.