-
-
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.
Add support for JsonTypeof function (#115)
Co-authored-by: Martin Georgiev <[email protected]>
- Loading branch information
1 parent
5e726ec
commit 826d1df
Showing
4 changed files
with
54 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeof.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
||
/** | ||
* Implementation of PostgreSql JSON_TYPEOF(). | ||
* | ||
* @see https://www.postgresql.org/docs/14/functions-json.html | ||
* @since 1.8.0 | ||
*/ | ||
class JsonTypeof extends BaseFunction | ||
{ | ||
protected function customiseFunction(): void | ||
{ | ||
$this->setFunctionPrototype('json_typeof(%s)'); | ||
$this->addNodeMapping('StringPrimary'); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeofTest.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 MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonTypeof; | ||
use Tests\MartinGeorgiev\Doctrine\Fixtures\Entity\ContainsJsons; | ||
|
||
class JsonTypeofTest extends TestCase | ||
{ | ||
protected function getStringFunctions(): array | ||
{ | ||
return [ | ||
'JSON_TYPEOF' => JsonTypeof::class, | ||
]; | ||
} | ||
|
||
protected function getExpectedSqlStatements(): array | ||
{ | ||
return [ | ||
'SELECT json_typeof(c0_.object1) AS sclr_0 FROM ContainsJsons c0_', | ||
]; | ||
} | ||
|
||
protected function getDqlStatements(): array | ||
{ | ||
return [ | ||
\sprintf('SELECT JSON_TYPEOF(e.object1) FROM %s e', ContainsJsons::class), | ||
]; | ||
} | ||
} |