Skip to content

Commit

Permalink
Add support for Row (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzanchettin authored Dec 19, 2024
1 parent 2eeec4e commit ff1528b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
| regexp_match (with no flags) | REGEXP_MATCH | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\RegexpMatch` |
| regexp_replace (with flags) | FLAGGED_REGEXP_REPLACE | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\FlaggedRegexpReplace` |
| regexp_replace (with no flags) | REGEXP_REPLACE | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\RegexpReplace` |
| row | ROW | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Row` |
| row_to_json | ROW_TO_JSON | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\RowToJson` |
| split_part | SPLIT_PART | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\SplitPart` |
| starts_with | STARTS_WITH | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\StartsWith` |
Expand Down
20 changes: 20 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Row.php
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 tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RowTest.php
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),
];
}
}

0 comments on commit ff1528b

Please sign in to comment.