Last active
August 29, 2015 14:26
-
-
Save sergiors/ae2bcfc339e50f58092c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Inbep\Doctrine\Query\PostgreSql; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; | |
class JsonbHashGreaterGreater extends FunctionNode | |
{ | |
private $expr1 = null; | |
private $expr2 = null; | |
public function parse(Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->expr1 = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_COMMA); | |
$this->expr2 = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
public function getSql(SqlWalker $sqlWalker) | |
{ | |
return '('. | |
$this->expr1->dispatch($sqlWalker).' #>> '. | |
$this->expr2->dispatch($sqlWalker). | |
')'; | |
} | |
} | |
// how to use | |
$qb = $this->_em->createQueryBuilder() | |
->select('u') | |
->from(User::class, 'u') | |
->andWhere('u.email = ?1') | |
->orWhere("JSONB_HGG(u.metadata, '{phones,mobile}') = ?1") | |
->setParameter(1, $username) | |
->getQuery() | |
->getSingleResult(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment