final class UpsertExpression

A scalar expression from an UPSERT assignment, in no particular dialect.

Every dialect writes "the value that was already there" and "the value that

  • was coming in" differently, so a parser reads its own spelling and builds one

of these; what the expression means is then worked out here, once, for all of them. What each operator means is left to the collaborator that owns it, so this is only the tree and the walk over it.

Type Aliases§

Row = import from TableDefinition
RowValue = import from TableDefinition

Methods§

public function __construct(
    private UpsertExpressionKind $kind,
    private UpsertLiteralSource $literal = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertLiteral(null),
    private UpsertColumnSource|null $columnSource = null,
    private string|null $column = null,
    private list<self> $operands = [],
    private UpsertColumn $columns = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertColumn(),
    private UpsertTruth $truth = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth(),
    private UpsertOperator $operators = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator(),
)

Parameters

$kindUpsertExpressionKindWhat this node is
$literalUpsertLiteralSourceValue a literal stands for
$columnSourceUpsertColumnSource|nullWhich row a column is read from
$columnstring|nullColumn a column node names
$operandslist<self>Nodes this one is written over
$columnsUpsertColumnReads a column off a row
$truthUpsertTruthAnswers what counts as true
$operatorsUpsertOperatorSays what an operator stands for
Test cases 45
Calls 4
public static function literal(mixed $value): self

Builds an expression standing for a value written into the statement.

Parameters

$valuemixedValue as the statement wrote it

Returns

self The expression
Test cases 60
Calls 3
public static function column(UpsertColumnSource $source, string $column): self

Builds an expression standing for a column of one of the two rows.

Parameters

$sourceUpsertColumnSourceWhether the column is read from the existing row or the incoming one
$columnstringColumn as the statement named it

Returns

self The expression

Throws

InvalidDefinitionException When no column was named
Test cases 22
Calls 3
public static function unary(UpsertExpressionKind $kind, self $operand): self

Builds an expression written over one other.

Parameters

$kindUpsertExpressionKindOperator to apply
$operandselfExpression it is applied to

Returns

self The expression

Throws

InvalidDefinitionException When the operator is not one written over a single operand
Test cases 3
Calls 6
public static function binary(UpsertExpressionKind $kind, self $left, self $right): self

Builds an expression written between two others.

Parameters

$kindUpsertExpressionKindOperator to apply
$leftselfExpression on its left
$rightselfExpression on its right

Returns

self The expression

Throws

InvalidDefinitionException When the operator is not one written between two operands
Test cases 58
Calls 8
public function evaluate(Row $existingRow, Row $incomingRow, string $tableName): mixed

Answers what the expression stands for, against the two rows in play.

Parameters

$existingRowRowRow the conflict was found on
$incomingRowRowRow the statement was trying to write
$tableNamestringTable being written to

Returns

mixed The value the expression stands for

Throws

UnsupportedSqlException When an operand is not something the operator can be applied to
Test cases 46
Called from 1
Calls 8
public function matches(Row $existingRow, Row $incomingRow, string $tableName): bool

Reports whether the expression holds, as a condition would have to.

Unknown is not enough: a WHERE that cannot be shown to hold does not select the row, so only a definite true counts.

Parameters

$existingRowRowRow the conflict was found on
$incomingRowRowRow the statement was trying to write
$tableNamestringTable being written to

Returns

bool True when the expression is definitely true

Throws

UnsupportedSqlException When an operand is not something the operator can be applied to
Test cases 2
Calls 2
public function operand(
    int $index,
    Row $existingRow,
    Row $incomingRow,
    string $tableName,
): mixed

Answers what one of the operands stands for.

Parameters

$indexintWhich operand
$existingRowRowRow the conflict was found on
$incomingRowRowRow the statement was trying to write
$tableNamestringTable being written to

Returns

mixed The value that operand stands for

Throws

UnsupportedSqlException When an operand is not something the operator can be applied to
Test cases 42
Called from 2

Private surface 8§

Implementation details, listed for orientation only.

private UpsertExpressionKind $kind
private UpsertLiteralSource $literal = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertLiteral(null)
private UpsertColumnSource|null $columnSource = null
private string|null $column = null
private list<self> $operands = []
private UpsertColumn $columns = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertColumn()
private UpsertTruth $truth = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth()
private UpsertOperator $operators = new \ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator()

Test cases 71§

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

Dedicated tests 48
Other tests reaching this symbol 23

Relations§

Type declarations 10