final class Operation
    implements Query
    uses Snapshot
Public API: explicitly declared with @visibility public.

One analyzed statement: its structure, the facts derived against a fixed context, and its SQL.

The constructor is the only way to obtain an operation and it is a checking boundary. It audits the structure, derives every fact, renders the SQL, and confirms that the rendered SQL has the same structure. Nothing is filled in afterwards and nothing can be changed. A different statement is a new operation built from explicit inputs or from newly analyzed SQL; it has no guaranteed relation to this one.

Analyzing against the declaration another statement providesdoctest
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
    $bar = $semantics->analyze('CREATE TABLE bar (foo INTEGER, baz TEXT)');
    $query = $semantics->analyze('SELECT foo FROM bar', [$bar]);
    [$query->field('foo')->column() === $bar->declarations()[0]->columns[0], $query->toString()] // => [true, 'SELECT foo FROM bar']
Building a new root from explicit structuredoctest
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
    $query = $semantics->analyze('SELECT foo FROM bar WHERE foo > 1');
    $other = new \SqlSemantics\Platform\PostgreSql\Model\Statement\Operation($query->context, $semantics->analyze('SELECT baz FROM bar')->statement);
    $other->toString() // => 'SELECT baz FROM bar'

Properties§

public Facts $facts
public AnalysisContext $context
public Statement $statement

Methods§

public function __construct(public AnalysisContext $context, public Statement $statement)

Derives and checks a new root from a context and an explicit statement structure.

A structure outside the closed value domain, a node shared between two positions, or a context of another profile is refused as an invalid construction. A missing rule or a failed correspondence check is a defect of the library and discards the candidate.

Parameters

$contextAnalysisContextThe fixed profile and declaration snapshot
$statementStatementThe requested statement
Calls 2
public function toString(): string

Answers the SQL rendered from the structure and confirmed to correspond to it; never the analyzed text.

Returns

string
Called from 2
public function profile(): LanguageProfile

Answers the fixed language profile the operation was built under.

public function declarations(): list<Table>

Answers the relation declarations the statement provides to a context.

Returns

list<Table>
public function shape(): ?RowShape

Answers the shape of the rows the statement returns, or null when it returns none.

Returns

public function fields(): ?Fields

Answers the complete ordered output fields, or null when the statement returns no rows or its shape is open.

Returns

Called from 1
public function field(string|int $key): Field

Answers the one field at a position or with a name.

This is a convenience for the unique case; use lookupField() to tell absent, ambiguous and dependent lookups apart.

Parameters

$keystring|int

Returns

Throws

InvalidConstruction When no field or more than one field answers the key
Calls 4
public function lookupField(string $name): FieldLookup

Looks an output field up by name, distinguishing unique, absent, ambiguous and dependent results.

Parameters

$namestring

Throws

InvalidConstruction When the statement returns no rows
Called from 1
Calls 1
public function inputRelation(): ?Relation

Answers the input relation structure of a selection, or null when there is none.

Returns

Called from 1
Calls 1
public function singleNamedInput(): NamedRelation

Answers the input when it is exactly one plainly named relation.

Throws

InvalidConstruction When the input is a join, a derived relation, several relations, or absent
Calls 2

Private surface 1§

Implementation details, listed for orientation only.

private string $sql

Test cases 1§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Other tests reaching this symbol 1

Relations§

Instantiated in 1
Method calls 2
Type checks 1
Type declarations 1