classJsonObjectConstructor
final class JsonObjectConstructor
implements Scalar, OutputNaming
uses Snapshot
Public API: explicitly declared with
@visibility public.JSON_OBJECT (key : value, ... [NULL | ABSENT ON NULL] [WITH | WITHOUT UNIQUE] [RETURNING type]).
Mirrors PostgreSQL's JsonObjectConstructor. Without pairs, no NULL or uniqueness clause can be written. Rule: PG-JSON-OBJECT-001. Facts: the RETURNING type, otherwise json; never NULL. The result column is named json_object. Source: https://www.postgresql.org/docs/17/functions-json.html#FUNCTIONS-JSON-CREATION-TABLE. Status: Implemented.
$object = new \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Constructor\JsonObjectConstructor([]);
[$object->pairs, $object->outputName()->value] // => [[], 'json_object']new \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Constructor\JsonObjectConstructor([], \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\JsonNullHandling::Absent) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public list<JsonPair> $pairspublic JsonNullHandling|null $nulls = nullpublic JsonUniqueKeys|null $unique = nullpublic JsonReturning|null $returning = nullMethods§
public function __construct(
list<JsonPair> $pairs,
public JsonNullHandling|null $nulls = null,
public JsonUniqueKeys|null $unique = null,
public JsonReturning|null $returning = null,
)Parameters
$pairs | list<JsonPair> | The key and value pairs |
$nulls | JsonNullHandling|null | The NULL clause written |
$unique | JsonUniqueKeys|null | The uniqueness clause written |
$returning | JsonReturning|null | The RETURNING clause |
Calls 6
- static-call Check::listOf() line 58
- class-const JsonPair::class() line 58
- static-call Check::input() line 59
- function-call
countline 60 - method-call Precedence::takesUniqueness() line 61
- new Precedence line 61
public function outputName(): NameNames an unaliased result column.
Returns
Test cases 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the pairs and the returning type.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 4
- new ScalarFact line 82
- new Known line 82
- class-const Builtin::Json() line 82
- class-const Nullability::NotNull() line 82
public function render(Output $out): voidWrites JSON_OBJECT with its pairs and clauses.
Parameters
$out | Output |
Test cases 1
Calls 2
- method-call Output::keyword() line 90
- method-call Output::node() line 94
Test cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
JsonObjectConstructorTest::testDeriveScalarIsJsonOrTheReturningTypecallsJsonObjectConstructorTest::testOutputNameIsJsonObjectcallsJsonObjectConstructorTest::testRejectsALastValueThatWouldTakeTheUniquenesscallsJsonObjectConstructorTest::testRejectsANullClauseWithoutPairscallsJsonObjectConstructorTest::testRenderWritesTheClausescalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:101
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:107