final class CandidateKeySet

Relational candidate keys used to detect INSERT conflicts.

Type Aliases§

Row = import from TableDefinition

Methods§

public function __construct(
    private array<string, array<int, string>> $keys,
    private CandidateKeyMatch $values = new \ZtdQuery\Schema\Key\CandidateKeyMatch(),
)

Parameters

$keysarray<string, array<int, string>>Columns of each candidate key, under the key's name
$valuesCandidateKeyMatchReads what a row carries in a key
Calls 1
public static function fromSchema(
    array<int, string> $primaryKey,
    array<string, array<int, string>> $uniqueConstraints = [],
): self

Parameters

$primaryKeyarray<int, string>
$uniqueConstraintsarray<string, array<int, string>>

Returns

self
Test cases 20
Called from 4
Calls 1
public function findConflict(Row $row, array<int, Row> $existingRows): CandidateKeyConflict|null

Answers the first candidate key an incoming row would collide on.

The rows searched may be keyed, and the conflict reports the key it was found at: a caller that has narrowed the rows it is willing to collide with still has to say which of its own rows that was.

Parameters

$rowRowRow that would be written
$existingRowsarray<int, Row>Rows it could collide with, under the keys the caller knows them by

Returns

CandidateKeyConflict|null Where and on which key it collides, or null when it does not
Called from 3
Calls 3

Private surface 2§

Implementation details, listed for orientation only.

private array<string, array<int, string>> $keys
private CandidateKeyMatch $values = new \ZtdQuery\Schema\Key\CandidateKeyMatch()

Test cases 34§

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

Dedicated tests 10
Other tests reaching this symbol 24

Relations§

Instantiated in 4
Static calls 4
Method calls 5
Type declarations 10