-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from Hikariii/json_overlaps
added json_overlaps function
- Loading branch information
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
use Doctrine\DBAL\Platforms\MySqlPlatform; | ||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Lexer; | ||
use Doctrine\ORM\Query\Parser; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
|
||
/** | ||
* "JSON_OVERLAPS" "(" StringPrimary "," StringPrimary ")" | ||
*/ | ||
class JsonOverlaps extends MysqlJsonFunctionNode | ||
{ | ||
const FUNCTION_NAME = 'JSON_OVERLAPS'; | ||
|
||
/** @var string[] */ | ||
protected $requiredArgumentTypes = [self::STRING_PRIMARY_ARG, self::STRING_PRIMARY_ARG]; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Scienta\DoctrineJsonFunctions\Tests\Query\Functions\Mysql; | ||
|
||
use Scienta\DoctrineJsonFunctions\Tests\Query\MysqlTestCase; | ||
use Doctrine\ORM\Query\Expr; | ||
|
||
class JsonOverlapsTest extends MysqlTestCase | ||
{ | ||
public function testJsonOverlapsArray() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT JSON_OVERLAPS('[\"bar\", 2]', '[2,5]') FROM Scienta\DoctrineJsonFunctions\Tests\Entities\Blank b", | ||
"SELECT JSON_OVERLAPS('[\"bar\", 2]', '[2,5]') AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
|
||
public function testJsonOverlapsObject() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT JSON_OVERLAPS('{\"a\":1, \"b\":10}', '{\"c\":1,\"b\":10}') FROM Scienta\DoctrineJsonFunctions\Tests\Entities\Blank b", | ||
"SELECT JSON_OVERLAPS('{\"a\":1, \"b\":10}', '{\"c\":1,\"b\":10}') AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
|
||
public function testJsonOverlapsSingle() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT JSON_OVERLAPS('[\"foo\", 2, 18]', '2') FROM Scienta\DoctrineJsonFunctions\Tests\Entities\Blank b", | ||
"SELECT JSON_OVERLAPS('[\"foo\", 2, 18]', '2') AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
|
||
public function testJsonTestWhere() | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT d.id FROM Scienta\DoctrineJsonFunctions\Tests\Entities\JsonData d WHERE JSON_OVERLAPS(d.jsonData, '[2,6,8]') = 1", | ||
"SELECT j0_.id AS id_0 FROM JsonData j0_ WHERE JSON_OVERLAPS(j0_.jsonData, '[2,6,8]') = 1" | ||
); | ||
} | ||
} |
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