diff --git a/docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md b/docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md index 508d5629..bad99383 100644 --- a/docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md +++ b/docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md @@ -44,6 +44,7 @@ | json_object_agg | JSON_OBJECT_AGG | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonObjectAgg` | | json_object_keys | JSON_OBJECT_KEYS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonObjectKeys` | | json_strip_nulls | JSON_STRIP_NULLS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonStripNulls` | +| json_typeof | JSON_TYPEOF | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonTypeof` | | jsonb_array_elements | JSONB_ARRAY_ELEMENTS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbArrayElements` | | jsonb_agg | JSONB_AGG | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbAgg` | | jsonb_array_elements_text | JSONB_ARRAY_ELEMENTS_TEXT | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbArrayElementsText` | diff --git a/docs/INTEGRATING-WITH-SYMFONY.md b/docs/INTEGRATING-WITH-SYMFONY.md index 4442a2dd..9d471eb7 100644 --- a/docs/INTEGRATING-WITH-SYMFONY.md +++ b/docs/INTEGRATING-WITH-SYMFONY.md @@ -106,6 +106,7 @@ doctrine: JSON_STRIP_NULLS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonStripNulls TO_JSON: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToJson ROW_TO_JSON: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\RowToJson + JSON_TYPEOF: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonTypeof # jsonb specific functions JSONB_AGG: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonbAgg diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeof.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeof.php new file mode 100644 index 00000000..bdd08151 --- /dev/null +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeof.php @@ -0,0 +1,20 @@ +setFunctionPrototype('json_typeof(%s)'); + $this->addNodeMapping('StringPrimary'); + } +} diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeofTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeofTest.php new file mode 100644 index 00000000..4efffe4f --- /dev/null +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonTypeofTest.php @@ -0,0 +1,32 @@ + 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), + ]; + } +}