Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\TokenType;
use MartinGeorgiev\Utils\DoctrineOrm;

/**
* Implementation of PostgreSQL json field retrieval, filtered by key (using ->).
*
* Supports both string keys for object property access and integer indices for array element access:
* - JSON_GET_FIELD(json_column, 'property_name') -> json_column->'property_name'
* - JSON_GET_FIELD(json_column, 0) -> json_column->0
*
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
* @since 0.1
*
Expand All @@ -17,7 +27,22 @@
protected function customizeFunction(): void
{
$this->setFunctionPrototype('(%s -> %s)');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}

protected function feedParserWithNodes(Parser $parser): void
{
$shouldUseLexer = DoctrineOrm::isPre219();

// Parse first parameter (always StringPrimary for the JSON column)
$this->nodes[0] = $parser->StringPrimary();
$parser->match($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA);

// Parse second parameter - try ArithmeticPrimary first, then StringPrimary
try {
$this->nodes[1] = $parser->ArithmeticPrimary();

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.

Check failure on line 42 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|string|null>.
} catch (QueryException) {
// If ArithmeticPrimary fails (e.g., when encountering a string), try StringPrimary
$this->nodes[1] = $parser->StringPrimary();

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.

Check failure on line 45 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonGetField.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Property MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction::$nodes (list<Doctrine\ORM\Query\AST\Node|null>) does not accept non-empty-array<int<0, max>, Doctrine\ORM\Query\AST\Node|null>.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
/**
* Implementation of PostgreSQL json field retrieval as integer, filtered by key (using ->> and type casting to BIGINT).
*
* Supports both string keys for object property access and integer indices for array element access:
* - JSON_GET_FIELD_AS_INTEGER(json_column, 'property_name') -> CAST(json_column->>'property_name' as BIGINT)
* - JSON_GET_FIELD_AS_INTEGER(json_column, 0) -> CAST(json_column->>0 as BIGINT)
*
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
* @since 0.3
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class JsonGetFieldAsInteger extends BaseFunction
class JsonGetFieldAsInteger extends JsonGetField
{
protected function customizeFunction(): void
{
$this->setFunctionPrototype('CAST(%s ->> %s as BIGINT)');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
/**
* Implementation of PostgreSQL json field retrieval as text, filtered by key (using ->>).
*
* Supports both string keys for object property access and integer indices for array element access:
* - JSON_GET_FIELD_AS_TEXT(json_column, 'property_name') -> json_column->>'property_name'
* - JSON_GET_FIELD_AS_TEXT(json_column, 0) -> json_column->>0
*
* @see https://www.postgresql.org/docs/9.4/static/functions-json.html
* @since 0.1
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class JsonGetFieldAsText extends BaseFunction
class JsonGetFieldAsText extends JsonGetField
{
protected function customizeFunction(): void
{
$this->setFunctionPrototype('(%s ->> %s)');
$this->addNodeMapping('StringPrimary');
$this->addNodeMapping('StringPrimary');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
namespace Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetField;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetFieldAsInteger;

class JsonGetFieldAsIntegerTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'JSON_GET_FIELD' => JsonGetField::class,
'JSON_GET_FIELD_AS_INTEGER' => JsonGetFieldAsInteger::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
"SELECT CAST(c0_.object1 ->> 'rank' as BIGINT) AS sclr_0 FROM ContainsJsons c0_",
'extracts field as integer' => "SELECT CAST(c0_.object1 ->> 'rank' as BIGINT) AS sclr_0 FROM ContainsJsons c0_",
'extracts array element as integer' => 'SELECT CAST(c0_.object1 ->> 0 as BIGINT) AS sclr_0 FROM ContainsJsons c0_',
'extracts nested array element as integer' => "SELECT CAST((c0_.object1 -> 'scores') ->> 1 as BIGINT) AS sclr_0 FROM ContainsJsons c0_",
];
}

protected function getDqlStatements(): array
{
return [
\sprintf("SELECT JSON_GET_FIELD_AS_INTEGER(e.object1, 'rank') FROM %s e", ContainsJsons::class),
'extracts field as integer' => \sprintf("SELECT JSON_GET_FIELD_AS_INTEGER(e.object1, 'rank') FROM %s e", ContainsJsons::class),
'extracts array element as integer' => \sprintf('SELECT JSON_GET_FIELD_AS_INTEGER(e.object1, 0) FROM %s e', ContainsJsons::class),
'extracts nested array element as integer' => \sprintf("SELECT JSON_GET_FIELD_AS_INTEGER(JSON_GET_FIELD(e.object1, 'scores'), 1) FROM %s e", ContainsJsons::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
namespace Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetField;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetFieldAsText;

class JsonGetFieldAsTextTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'JSON_GET_FIELD' => JsonGetField::class,
'JSON_GET_FIELD_AS_TEXT' => JsonGetFieldAsText::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
"SELECT (c0_.object1 ->> 'country') AS sclr_0 FROM ContainsJsons c0_",
'extracts field as text' => "SELECT (c0_.object1 ->> 'country') AS sclr_0 FROM ContainsJsons c0_",
'extracts array element as text' => 'SELECT (c0_.object1 ->> 0) AS sclr_0 FROM ContainsJsons c0_',
'extracts nested array element as text' => "SELECT ((c0_.object1 -> 'tags') ->> 1) AS sclr_0 FROM ContainsJsons c0_",
];
}

protected function getDqlStatements(): array
{
return [
\sprintf("SELECT JSON_GET_FIELD_AS_TEXT(e.object1, 'country') FROM %s e", ContainsJsons::class),
'extracts field as text' => \sprintf("SELECT JSON_GET_FIELD_AS_TEXT(e.object1, 'country') FROM %s e", ContainsJsons::class),
'extracts array element as text' => \sprintf('SELECT JSON_GET_FIELD_AS_TEXT(e.object1, 0) FROM %s e', ContainsJsons::class),
'extracts nested array element as text' => \sprintf("SELECT JSON_GET_FIELD_AS_TEXT(JSON_GET_FIELD(e.object1, 'tags'), 1) FROM %s e", ContainsJsons::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ protected function getExpectedSqlStatements(): array
return [
'extracts top-level field from json' => "SELECT (c0_.object1 -> 'key') AS sclr_0 FROM ContainsJsons c0_",
'extracts nested field from json' => "SELECT ((c0_.object1 -> 'nested') -> 'key') AS sclr_0 FROM ContainsJsons c0_",
'extracts array element by index' => 'SELECT (c0_.object1 -> 0) AS sclr_0 FROM ContainsJsons c0_',
'extracts nested array element by index' => "SELECT ((c0_.object1 -> 'tags') -> 1) AS sclr_0 FROM ContainsJsons c0_",
'extracts field from array element by index' => "SELECT ((c0_.object1 -> 0) -> 'name') AS sclr_0 FROM ContainsJsons c0_",
];
}

Expand All @@ -29,6 +32,9 @@ protected function getDqlStatements(): array
return [
'extracts top-level field from json' => \sprintf("SELECT JSON_GET_FIELD(e.object1, 'key') FROM %s e", ContainsJsons::class),
'extracts nested field from json' => \sprintf("SELECT JSON_GET_FIELD(JSON_GET_FIELD(e.object1, 'nested'), 'key') FROM %s e", ContainsJsons::class),
'extracts array element by index' => \sprintf('SELECT JSON_GET_FIELD(e.object1, 0) FROM %s e', ContainsJsons::class),
'extracts nested array element by index' => \sprintf("SELECT JSON_GET_FIELD(JSON_GET_FIELD(e.object1, 'tags'), 1) FROM %s e", ContainsJsons::class),
'extracts field from array element by index' => \sprintf("SELECT JSON_GET_FIELD(JSON_GET_FIELD(e.object1, 0), 'name') FROM %s e", ContainsJsons::class),
];
}
}
Loading