-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for
split_part
function (#236)
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/SplitPart.php
This file contains 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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql SPLIT_PART(). | ||
* | ||
* @see https://www.postgresql.org/docs/15/functions-string.html | ||
*/ | ||
class SplitPart extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('split_part(%s, %s, %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('SimpleArithmeticExpression'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/SplitPartTest.php
This file contains 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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsTexts; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SplitPart; | ||
|
||
class SplitPartTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'SPLIT_PART' => SplitPart::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
"SELECT split_part(c0_.text1, ',', 1) AS sclr_0 FROM ContainsTexts c0_", | ||
"SELECT split_part(c0_.text2, '-', -2) AS sclr_0 FROM ContainsTexts c0_", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf("SELECT SPLIT_PART(e.text1, ',', 1) FROM %s e", ContainsTexts::class), | ||
\sprintf("SELECT SPLIT_PART(e.text2, '-', -2) FROM %s e", ContainsTexts::class), | ||
]; | ||
} | ||
} |