From d133237b62d3ea645e5c240d1894039ab97a4aa6 Mon Sep 17 00:00:00 2001 From: "Nathanael d. Noblet" Date: Fri, 14 Apr 2023 23:40:14 -0600 Subject: [PATCH] added ilike --- config/postgres.yml | 1 + src/Query/Postgresql/Ilike.php | 45 ++++++++++++++++++++++++++++ tests/Query/Postgresql/IlikeTest.php | 16 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/Query/Postgresql/Ilike.php create mode 100644 tests/Query/Postgresql/IlikeTest.php diff --git a/config/postgres.yml b/config/postgres.yml index 0a36cc64..dc38a337 100644 --- a/config/postgres.yml +++ b/config/postgres.yml @@ -22,3 +22,4 @@ doctrine: greatest: DoctrineExtensions\Query\Postgresql\Greatest least: DoctrineExtensions\Query\Postgresql\Least regexp_replace: DoctrineExtensions\Query\Postgresql\RegexpReplace + ilike: DoctrineExtensions\Query\Postgresql\Ilike diff --git a/src/Query/Postgresql/Ilike.php b/src/Query/Postgresql/Ilike.php new file mode 100644 index 00000000..83dd5fa7 --- /dev/null +++ b/src/Query/Postgresql/Ilike.php @@ -0,0 +1,45 @@ +match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + $this->field = $parser->StringExpression(); + $parser->match(Lexer::T_COMMA); + $this->query = $parser->StringExpression(); + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + /** + * @param SqlWalker $sqlWalker + * + * @return string + * @throws ASTException + */ + public function getSql(SqlWalker $sqlWalker) + { + return '(' . $this->field->dispatch($sqlWalker) . ' ILIKE ' . $this->query->dispatch($sqlWalker) . ')'; + } +} diff --git a/tests/Query/Postgresql/IlikeTest.php b/tests/Query/Postgresql/IlikeTest.php new file mode 100644 index 00000000..0202098e --- /dev/null +++ b/tests/Query/Postgresql/IlikeTest.php @@ -0,0 +1,16 @@ +entityManager->createQuery($dql); + $q->setParameter('searchName', '%search term%'); + $sql = 'SELECT p0_.id AS id_0, p0_.name AS name_1, p0_.created AS created_2, p0_.price AS price_3, p0_.weight AS weight_4 FROM Product p0_ WHERE (p0_.name ILIKE ?) = 1'; + + $this->assertEquals($sql, $q->getSql()); + } +}