-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2eeec4e
commit ff1528b
Showing
3 changed files
with
64 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
20 changes: 20 additions & 0 deletions
20
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Row.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql Row Constructor expression. | ||
* | ||
* @see https://www.postgresql.org/docs/14/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS | ||
*/ | ||
class Row extends BaseVariadicFunction | ||
{ | ||
protected string $commonNodeMapping = 'InParameter'; | ||
|
||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('ROW(%s)'); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RowTest.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsDates; | ||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsIntegers; | ||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons; | ||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsTexts; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Row; | ||
|
||
class RowTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'ROW' => Row::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
'SELECT ROW(c0_.text1, c0_.text2) AS sclr_0 FROM ContainsTexts c0_', | ||
'SELECT ROW(c0_.date1, c0_.date2) AS sclr_0 FROM ContainsDates c0_', | ||
'SELECT ROW(c0_.object1, c0_.object2) AS sclr_0 FROM ContainsJsons c0_', | ||
"SELECT c0_.id AS id_0 FROM ContainsTexts c0_ WHERE ROW(c0_.text1, c0_.text2) > ROW('test', 'test')", | ||
"SELECT c0_.id AS id_0 FROM ContainsIntegers c0_ WHERE ROW(c0_.integer1, c0_.integer2, 'This is a test') > ROW(1, 2, 'This')", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf('SELECT ROW(e.text1, e.text2) FROM %s e', ContainsTexts::class), | ||
\sprintf('SELECT ROW(e.date1, e.date2) FROM %s e', ContainsDates::class), | ||
\sprintf('SELECT ROW(e.object1, e.object2) FROM %s e', ContainsJsons::class), | ||
\sprintf("SELECT e.id FROM %s e WHERE ROW(e.text1, e.text2) > ROW('test', 'test')", ContainsTexts::class), | ||
\sprintf("SELECT e.id FROM %s e WHERE ROW(e.integer1, e.integer2, 'This is a test') > ROW(1, 2, 'This')", ContainsIntegers::class), | ||
]; | ||
} | ||
} |