-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat(#410): add support for functions to use with the LTREE data type
#440
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions
20
fixtures/MartinGeorgiev/Doctrine/Entity/ContainsLtrees.php
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,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Fixtures\MartinGeorgiev\Doctrine\Entity; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
|
|
||
| #[ORM\Entity()] | ||
| class ContainsLtrees extends Entity | ||
| { | ||
| #[ORM\Column(type: 'ltree')] | ||
| public string $ltree1; | ||
|
|
||
| #[ORM\Column(type: 'ltree')] | ||
| public string $ltree2; | ||
|
|
||
| #[ORM\Column(type: 'ltree')] | ||
| public string $ltree3; | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ltree/Index.php
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,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ltree; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction; | ||
|
|
||
| /** | ||
| * Implementation of PostgreSQL index function for ltree. | ||
| * | ||
| * Returns position of first occurrence of b in a, or -1 if not found. | ||
| * The search starts at position offset; negative offset means start -offset labels from the end of the path. | ||
| * | ||
| * @see https://www.postgresql.org/docs/current/ltree.html#LTREE-FUNCTIONS | ||
| * @since 3.5 | ||
| * | ||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||
| * | ||
| * @example Using it in DQL: "SELECT INDEX(e.path, 'Child1') FROM Entity e" | ||
| * Returns integer, position of first occurrence or -1 if not found. | ||
| */ | ||
| class Index extends BaseVariadicFunction | ||
| { | ||
| protected function getNodeMappingPattern(): array | ||
| { | ||
| return ['StringPrimary,StringPrimary,SimpleArithmeticExpression']; | ||
| } | ||
|
|
||
| protected function getFunctionName(): string | ||
| { | ||
| return 'index'; | ||
| } | ||
|
|
||
| protected function getMinArgumentCount(): int | ||
| { | ||
| return 2; | ||
| } | ||
|
|
||
| protected function getMaxArgumentCount(): int | ||
| { | ||
| return 3; | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ltree/Lca.php
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,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ltree; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction; | ||
|
|
||
| /** | ||
| * Implementation of PostgreSQL lca function. | ||
| * | ||
| * Computes longest common ancestor of paths (up to 8 arguments are supported). | ||
| * Also supports array input: lca(ltree[]). | ||
| * | ||
martin-georgiev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @see https://www.postgresql.org/docs/current/ltree.html#LTREE-FUNCTIONS | ||
| * @since 3.5 | ||
| * | ||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||
| * | ||
| * @example Using it in DQL: "SELECT LCA(e.path1, e.path2) FROM Entity e" | ||
| * Returns ltree, longest common ancestor of paths. | ||
| */ | ||
| class Lca extends BaseVariadicFunction | ||
| { | ||
| protected function getNodeMappingPattern(): array | ||
| { | ||
| return ['StringPrimary']; | ||
| } | ||
|
|
||
| protected function getFunctionName(): string | ||
| { | ||
| return 'lca'; | ||
| } | ||
|
|
||
| protected function getMinArgumentCount(): int | ||
| { | ||
| return 2; | ||
| } | ||
|
|
||
| protected function getMaxArgumentCount(): int | ||
| { | ||
| return 8; | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ltree/Ltree2text.php
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,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ltree; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction; | ||
|
|
||
| /** | ||
| * Implementation of PostgreSQL ltree2text function. | ||
| * | ||
| * Casts ltree to text. | ||
| * | ||
| * @see https://www.postgresql.org/docs/current/ltree.html#LTREE-FUNCTIONS | ||
| * @since 3.5 | ||
| * | ||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||
| * | ||
| * @example Using it in DQL: "SELECT LTREE2TEXT(e.path) FROM Entity e" | ||
| * Returns text, converted from ltree. | ||
| */ | ||
| class Ltree2text extends BaseFunction | ||
| { | ||
| protected function customizeFunction(): void | ||
| { | ||
| $this->setFunctionPrototype('ltree2text(%s)'); | ||
| $this->addNodeMapping('StringPrimary'); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ltree/Nlevel.php
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,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ltree; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction; | ||
|
|
||
| /** | ||
| * Implementation of PostgreSQL nlevel function. | ||
| * | ||
| * Returns number of labels in path. | ||
| * | ||
| * @see https://www.postgresql.org/docs/current/ltree.html#LTREE-FUNCTIONS | ||
| * @since 3.5 | ||
| * | ||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||
| * | ||
| * @example Using it in DQL: "SELECT NLEVEL(e.path) FROM Entity e" | ||
| * Returns integer, number of labels in path. | ||
| */ | ||
| class Nlevel extends BaseFunction | ||
| { | ||
| protected function customizeFunction(): void | ||
| { | ||
| $this->setFunctionPrototype('nlevel(%s)'); | ||
| $this->addNodeMapping('StringPrimary'); | ||
| } | ||
| } |
Oops, something went wrong.
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.