-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6da945
commit eb7f145
Showing
14 changed files
with
323 additions
and
27 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
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
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/AllOnTheRightExistOnTheLeft.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql check if all texts on the right side exist on the left-side JSONB (using ?&). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 2.3.0 | ||
* | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class AllOnTheRightExistOnTheLeft extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s ??& %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/AnyOnTheRightExistsOnTheLeft.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql check if any text on the right side exists on the left-side JSONB (using ?|). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 2.3.0 | ||
* | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class AnyOnTheRightExistsOnTheLeft extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s ??| %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DeleteAtPath.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql deletion of a field at the specified path (using #-). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 2.3.0 | ||
* | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class DeleteAtPath extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s #- %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ReturnsValueForJsonValue.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql check if a given JSON value will return value for teh left-side JSONB (using @?). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 2.3.0 | ||
* | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class ReturnsValueForJsonValue extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s @?? %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TheRightExistsOnTheLeft.php
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql check if the right-side text exists on the left-side JSONB (using ?|). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 2.3.0 | ||
* | ||
* @author Martin Georgiev <[email protected]> | ||
*/ | ||
class TheRightExistsOnTheLeft extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('(%s ?? %s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/AllOnTheRightExistOnTheLeftTest.php
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\AllOnTheRightExistOnTheLeft; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Arr; | ||
|
||
class AllOnTheRightExistOnTheLeftTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'ALL_ON_RIGHT_EXIST_ON_LEFT' => AllOnTheRightExistOnTheLeft::class, | ||
'ARRAY' => Arr::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
"SELECT (c0_.object1 ??& ARRAY['test']) AS sclr_0 FROM ContainsJsons c0_", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf("SELECT ALL_ON_RIGHT_EXIST_ON_LEFT(e.object1, ARRAY('test')) FROM %s e", ContainsJsons::class), | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/AnyOnTheRightExistsOnTheLeftTest.php
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\AnyOnTheRightExistsOnTheLeft; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Arr; | ||
|
||
class AnyOnTheRightExistsOnTheLeftTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'ANY_ON_RIGHT_EXISTS_ON_LEFT' => AnyOnTheRightExistsOnTheLeft::class, | ||
'ARRAY' => Arr::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
"SELECT (c0_.object1 ??| ARRAY['test']) AS sclr_0 FROM ContainsJsons c0_", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf("SELECT ANY_ON_RIGHT_EXISTS_ON_LEFT(e.object1, ARRAY('test')) FROM %s e", ContainsJsons::class), | ||
]; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DeleteAtPathTest.php
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\DeleteAtPath; | ||
|
||
class DeleteAtPathTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'DELETE_AT_PATH' => DeleteAtPath::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
'SELECT (c0_.object1 #- c0_.object2) AS sclr_0 FROM ContainsJsons c0_', | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf('SELECT DELETE_AT_PATH(e.object1, e.object2) FROM %s e', ContainsJsons::class), | ||
]; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ReturnsValueForJsonValueTest.php
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons; | ||
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ReturnsValueForJsonValue; | ||
|
||
class ReturnsValueForJsonValueTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'RETURNS_VALUE_FOR_JSON_VALUE' => ReturnsValueForJsonValue::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
"SELECT (c0_.object1 @?? '$.test[*] ?? (@ > 2)') AS sclr_0 FROM ContainsJsons c0_", | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf("SELECT RETURNS_VALUE_FOR_JSON_VALUE(e.object1, '$.test[*] ?? (@ > 2)') FROM %s e", ContainsJsons::class), | ||
]; | ||
} | ||
} |
Oops, something went wrong.