-
Notifications
You must be signed in to change notification settings - Fork 55
Primary attributes #623
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
Merged
Merged
Primary attributes #623
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
769f1ac
Introduce ID type
fogelito 06f06fe
Sequence validator
fogelito 5b4bb75
Hnadle zero and null to ID attribute
fogelito a78d777
Remove var_dumps
fogelito 0902764
Add attribute with schema
fogelito 5eb97a5
Fix unit test
fogelito c2e3679
Fix index
fogelito 41e6f76
Add $idAttributeType
fogelito 1ef3855
Order
fogelito fd1b288
gettype
fogelito 98c22c1
lint
fogelito 49fceb9
Use constant
fogelito 549323a
Use constant
fogelito e10670a
Remove Sequence type
fogelito bfce6cf
$tenant as VAR_ID
fogelito ae8b047
$tenant as VAR_ID
fogelito 9f3114d
Merge branch 'cast-internals' of github.com:utopia-php/database into …
fogelito df82400
Cast internals
fogelito e4cd537
Remove \n
fogelito da47c32
stopOnFailure
fogelito 07ab3f3
Merge branch 'main' of github.com:utopia-php/database into primary-at…
fogelito 9961ba2
Merge branch 'main' of github.com:utopia-php/database into primary-at…
fogelito d56038e
Fix unit tests
fogelito 50f5c56
Fix unit tests
fogelito b109641
Merge branch 'main' of github.com:utopia-php/database into primary-at…
fogelito ab1d5c8
Merge branch 'main' of github.com:utopia-php/database into primary-at…
fogelito f7ba958
Apply suggestions from code review
abnegate 755a2f8
Update tests
abnegate 7d77337
Fix tests
abnegate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Database\Validator; | ||
|
|
||
| use Utopia\Database\Database; | ||
| use Utopia\Validator; | ||
| use Utopia\Validator\Integer; | ||
| use Utopia\Validator\Range; | ||
|
|
||
| class Sequence extends Validator | ||
| { | ||
| private string $idAttributeType; | ||
| private bool $primary; | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return 'Invalid sequence value'; | ||
| } | ||
|
|
||
| /** | ||
| * Expression constructor | ||
| */ | ||
| public function __construct(string $idAttributeType, bool $primary) | ||
| { | ||
| $this->primary = $primary; | ||
| $this->idAttributeType = $idAttributeType; | ||
| } | ||
|
|
||
| public function isArray(): bool | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| public function getType(): string | ||
| { | ||
| return self::TYPE_STRING; | ||
| } | ||
|
|
||
| public function isValid($value): bool | ||
| { | ||
| if ($this->primary && empty($value)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (gettype($value) !== 'string') { | ||
|
abnegate marked this conversation as resolved.
Outdated
|
||
| return false; | ||
| } | ||
|
|
||
| if ($this->idAttributeType === Database::VAR_ID_MONGO) { | ||
| return preg_match('/^[a-f0-9]{24}$/i', $value) === 1; | ||
| } elseif ($this->idAttributeType === Database::VAR_ID_INT) { | ||
| $validator = new Integer(loose: true); | ||
| if (!$validator->isValid($value)) { | ||
| return false; | ||
| } | ||
|
|
||
| $start = ($this->primary) ? 1 : 0; | ||
|
|
||
| $validator = new Range($start, Database::BIG_INT_MAX, Database::VAR_INTEGER); | ||
| if (!$validator->isValid($value)) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.