diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index ebb28d2e7..369f38203 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -38,6 +38,7 @@ use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey; use Chill\MainBundle\Doctrine\DQL\Greatest; use Chill\MainBundle\Doctrine\DQL\JsonAggregate; use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength; +use Chill\MainBundle\Doctrine\DQL\JsonbContains; use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray; use Chill\MainBundle\Doctrine\DQL\JsonBuildObject; use Chill\MainBundle\Doctrine\DQL\JsonExtract; @@ -283,6 +284,7 @@ class ChillMainExtension extends Extension implements 'STRICT_WORD_SIMILARITY_OPS' => StrictWordSimilarityOPS::class, 'ST_CONTAINS' => STContains::class, 'JSONB_ARRAY_LENGTH' => JsonbArrayLength::class, + 'JSONB_CONTAINS' => JsonbContains::class, 'ST_X' => STX::class, 'ST_Y' => STY::class, 'GREATEST' => Greatest::class, diff --git a/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonbContains.php b/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonbContains.php new file mode 100644 index 000000000..24a0af964 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Doctrine/DQL/JsonbContains.php @@ -0,0 +1,42 @@ + %s', + $this->expr1->dispatch($sqlWalker), + $this->expr2->dispatch($sqlWalker) + ); + } + + public function parse(Parser $parser): void + { + $parser->match(\Doctrine\ORM\Query\TokenType::T_IDENTIFIER); + $parser->match(\Doctrine\ORM\Query\TokenType::T_OPEN_PARENTHESIS); + $this->expr1 = $parser->StringPrimary(); + $parser->match(\Doctrine\ORM\Query\TokenType::T_COMMA); + $this->expr2 = $parser->InputParameter(); + $parser->match(\Doctrine\ORM\Query\TokenType::T_CLOSE_PARENTHESIS); + } +} diff --git a/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonbContainsTest.php b/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonbContainsTest.php new file mode 100644 index 000000000..3be3a61f0 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/JsonbContainsTest.php @@ -0,0 +1,43 @@ +em = self::getContainer()->get(EntityManagerInterface::class); + } + + public function testDQLFunctionWorks() + { + $result = $this->em + ->createQuery('SELECT JSONB_CONTAINS(u.attributes, :param) FROM '.User::class.' u') + ->setParameter('param', ['fr'], Types::JSON) + ->getResult(); + + $this->assertIsArray($result); + } +}