Skip to content

Commit

Permalink
Add support for Row constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
bzanchettin committed Dec 9, 2024
1 parent 74a39dd commit 5e01e0b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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 5e01e0b

Please sign in to comment.