final class TableTransitions

Works out what a statement did to each table, by comparing the two shadows.

Nothing records what a rewritten statement changed, so it is recovered by pairing the rows of the shadow before against the rows after. Where a table declares a key, the pairing is by that key, which is what tells an update apart from a delete followed by an insert; where it declares none, only an identical row can be said to be the same row.

An UPDATE is the one case where the pairing is known rather than guessed: the result rows carry both the old key and the new one, so those pairs are taken first and the guessing only fills in what they leave.

Type Aliases§

Row = import from TableDefinition

Methods§

public function __construct(
    private TableDefinitionRegistry $registry,
    private RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch(),
    private MutationRowIdentity $identity = new \ZtdQuery\Shadow\Mutation\MutationRowIdentity(),
)
public function of(
    ShadowStore $before,
    ShadowStore $after,
    ShadowMutation $mutation,
    array<int, Row> $resultRows,
): list<TableTransition>

Answers what happened to every table the statement could have touched.

Parameters

$beforeShadowStoreShadow as it was
$afterShadowStoreShadow as it became
$mutationShadowMutationStatement that was simulated
$resultRowsarray<int, Row>Rows the rewritten statement read back

Returns

list<TableTransition> One entry per table something happened to
Test cases 3
Called from 1
Calls 6
public function between(
    string $table,
    array<int, Row> $beforeRows,
    array<int, Row> $afterRows,
    list<string> $primaryKeys,
    array<int, Row> $identityRows,
): TableTransition

Answers what happened to one table.

Parameters

$tablestringTable being compared
$beforeRowsarray<int, Row>Its rows as they were
$afterRowsarray<int, Row>Its rows as they became
$primaryKeyslist<string>Columns that identify one of its rows
$identityRowsarray<int, Row>Result rows carrying both the old key and the new one

Returns

TableTransition What happened to it
Test cases 8
Called from 1
Calls 8
public function pairIdentical(
    RowPairing $pairing,
    array<int, Row> $beforeRows,
    array<int, Row> $afterRows,
): void

Pairs off the rows that are the same row because they are the same row.

Where a table declares no key there is nothing to say that two rows that differ were once each other, so only an identical row is paired, and no row is ever said to have changed.

Parameters

$pairingRowPairingPairs made so far, added to in place
$beforeRowsarray<int, Row>Rows as they were
$afterRowsarray<int, Row>Rows as they became
Test cases 2
Called from 1
Calls 3
public function pairByIdentity(
    RowPairing $pairing,
    array<int, Row> $beforeRows,
    array<int, Row> $afterRows,
    list<string> $primaryKeys,
    array<int, Row> $identityRows,
): void

Pairs off the rows an UPDATE told us about.

A result row carries both the key the row had and the key it has, so these pairs are known rather than guessed, and taking them first is what keeps a changed key from looking like a delete and an insert.

Parameters

$pairingRowPairingPairs made so far, added to in place
$beforeRowsarray<int, Row>Rows as they were
$afterRowsarray<int, Row>Rows as they became
$primaryKeyslist<string>Columns that identify one row
$identityRowsarray<int, Row>Result rows carrying both the old key and the new one
Test cases 9
Called from 1
Calls 5
public function pairByKey(
    RowPairing $pairing,
    array<int, Row> $beforeRows,
    array<int, Row> $afterRows,
    list<string> $primaryKeys,
): void

Private surface 3§

Implementation details, listed for orientation only.

private TableDefinitionRegistry $registry
private RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch()
private MutationRowIdentity $identity = new \ZtdQuery\Shadow\Mutation\MutationRowIdentity()

Test cases 19§

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

Dedicated tests 15
Other tests reaching this symbol 4

Relations§

Instantiated in 1
Method calls 1