Skip to content

Commit

Permalink
TO_TSVECTOR, TO_TSQUERY, TO_JSON and TO_JSONB accept more varied argu…
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusnordlander authored and martin-georgiev committed May 29, 2019
1 parent d5c6b84 commit b8acbb0
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ToJson extends BaseFunction
protected function customiseFunction(): void
{
$this->setFunctionPrototype('to_json(%s)');
$this->addNodeMapping('InputParameter');
$this->addNodeMapping('NewValue');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ToJsonb extends BaseFunction
protected function customiseFunction(): void
{
$this->setFunctionPrototype('to_jsonb(%s)');
$this->addNodeMapping('InputParameter');
$this->addNodeMapping('NewValue');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Tests\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToJson;
use MartinGeorgiev\Tests\Doctrine\Fixtures\Entity\ContainsText;

class ToJsonTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'TO_JSON' => ToJson::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
'SELECT to_json(c0_.text) AS sclr_0 FROM ContainsText c0_',
'SELECT to_json(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_',
'SELECT to_json(1 + 1) AS sclr_0 FROM ContainsText c0_',
'SELECT to_json(1) AS sclr_0 FROM ContainsText c0_',
'SELECT to_json(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT TO_JSON(e.text) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSON(UPPER(e.text)) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSON(1+1) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSON(true) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSON(LENGTH(e.text)) FROM %s e', ContainsText::class),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Tests\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToJsonb;
use MartinGeorgiev\Tests\Doctrine\Fixtures\Entity\ContainsText;

class ToJsonbTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'TO_JSONB' => ToJsonb::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
'SELECT to_jsonb(c0_.text) AS sclr_0 FROM ContainsText c0_',
'SELECT to_jsonb(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_',
'SELECT to_jsonb(1 + 1) AS sclr_0 FROM ContainsText c0_',
'SELECT to_jsonb(1) AS sclr_0 FROM ContainsText c0_',
'SELECT to_jsonb(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT TO_JSONB(e.text) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSONB(UPPER(e.text)) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSONB(1+1) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSONB(true) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_JSONB(LENGTH(e.text)) FROM %s e', ContainsText::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ protected function getExpectedSqlStatements(): array
{
return [
'SELECT to_tsquery(c0_.text) AS sclr_0 FROM ContainsText c0_',
'SELECT to_tsquery(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT TO_TSQUERY(e.text) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_TSQUERY(UPPER(e.text)) FROM %s e', ContainsText::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ protected function getExpectedSqlStatements(): array
{
return [
'SELECT to_tsvector(c0_.text) AS sclr_0 FROM ContainsText c0_',
'SELECT to_tsvector(LOWER(c0_.text)) AS sclr_0 FROM ContainsText c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT TO_TSVECTOR(e.text) FROM %s e', ContainsText::class),
\sprintf('SELECT TO_TSVECTOR(LOWER(e.text)) FROM %s e', ContainsText::class),
];
}
}

0 comments on commit b8acbb0

Please sign in to comment.