-
-
Notifications
You must be signed in to change notification settings - Fork 47
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 string concatenation (using
||
operator) (#226)
Co-authored-by: Martin Georgiev <martin-georgiev@users.noreply.github.com>
- Loading branch information
1 parent
75b1fb5
commit c3e1766
Showing
5 changed files
with
58 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
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
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
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/StrConcat.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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSQL's string concatenation operator (using `||`). | ||
* | ||
* @see https://www.postgresql.org/docs/15/functions-string.html | ||
* @since 2.6.0 | ||
* | ||
* @author Alexander Makarov <sam@rmcreative.ru> | ||
*/ | ||
class StrConcat extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s || %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/StrConcatTest.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,32 @@ | ||
<?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\StrConcat; | ||
|
||
class StrConcatTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'STRCONCAT' => StrConcat::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
"SELECT (c0_.text1 || 'text2') AS sclr_0 FROM ContainsTexts c0_", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf("SELECT STRCONCAT(e.text1, 'text2') FROM %s e", ContainsTexts::class), | ||
]; | ||
} | ||
} |