final class TablePrimaryKey
    implements TableConstraint
    uses Snapshot
Public API: explicitly declared with @visibility public.

A PRIMARY KEY table constraint.

Rule: SQLITE-TABLE-PRIMARY-KEY-001. The grammar writes the key terms as ordering terms, so any expression parses; SQLite accepts column names only, each optionally with a collation and a sort order ("expressions prohibited

  • in PRIMARY KEY and UNIQUE constraints"). A column name is an identifier, a

double-quoted word or a string literal (LiteralColumn; a plain string literal term is refused at construction, SQLITE-KEY-TERM-001). Each term is derived where the columns and the row identifier of the table are visible. Unlike the column constraint, a single-column key of declared type INTEGER is the row identifier whatever sort order is written. AUTOINCREMENT is written inside the parentheses after the last term. Source: https://sqlite.org/lang_createtable.html#the_primary_key, https://sqlite.org/lang_createtable.html#rowid. Status: Implemented.

Reading the terms of a primary keydoctest
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (a, b, PRIMARY KEY (a, b DESC) ON CONFLICT ROLLBACK)');
    $key = $create->statement->constraints[0]->items[0];
    [count($key->terms), $key->terms[1]->direction?->value, $key->conflict?->value] // => [2, 'DESC', 'ROLLBACK']

Properties§

public non-empty-list<SortTerm> $terms
public ConflictResolution|null $conflict = null
public bool $autoincrement = false

Methods§

public function __construct(
    list<SortTerm> $terms,
    public ConflictResolution|null $conflict = null,
    public bool $autoincrement = false,
)

Parameters

$termslist<SortTerm>The key terms in written order; at least one
$conflictConflictResolution|nullThe written ON CONFLICT resolution
$autoincrementboolWhether AUTOINCREMENT is written after the last key term
Calls 5
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): void

Derives each term where the columns of the table are visible and reports a term that is no column name.

Parameters

$derivationDerivation
$scopeConstraintScope
Calls 6
public function render(Output $out): void

Writes the clause.

Parameters

$outOutput
Calls 2

Test cases 9§

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

Dedicated tests 3
Other tests reaching this symbol 6

Relations§

Instantiated in 1
Type checks 1
Type declarations 1