classColumnPrimaryKey
final class ColumnPrimaryKey
implements ColumnConstraint
uses Snapshot
@visibility public.A PRIMARY KEY column constraint.
Rule: SQLITE-COLUMN-PRIMARY-KEY-001. The column alone is the primary key of the table. What follows from that (whether the column is the row identifier, whether it can hold NULL) depends on the declared type, the sort order and the table options and is derived by the table definition: a column declared INTEGER PRIMARY KEY DESC is not an alias of the rowid, which is why the sort order is kept even though it does not order anything. Source: https://sqlite.org/lang_createtable.html#the_primary_key, https://sqlite.org/lang_createtable.html#rowid, https://sqlite.org/autoinc.html. Status: Implemented.
$create = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('CREATE TABLE t (id INTEGER PRIMARY KEY ASC ON CONFLICT FAIL AUTOINCREMENT)');
$key = $create->statement->columns[0]->constraints[0];
[$key->direction?->value, $key->conflict?->value, $key->autoincrement] // => ['ASC', 'FAIL', true]Properties§
public SortDirection|null $direction = nullpublic ConflictResolution|null $conflict = nullpublic bool $autoincrement = falseMethods§
public function __construct(
public SortDirection|null $direction = null,
public ConflictResolution|null $conflict = null,
public bool $autoincrement = false,
)Parameters
$direction | SortDirection|null | The written sort order |
$conflict | ConflictResolution|null | The written ON CONFLICT resolution |
$autoincrement | bool | Whether AUTOINCREMENT is written |
public function deriveConstraint(Derivation $derivation, ConstraintScope $scope): voidDerives nothing: the clause has no operand that depends on a declaration.
Parameters
$derivation | Derivation | |
$scope | ConstraintScope |
public function render(Output $out): voidTest cases 5§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Relations§
Instantiated in 1
Type checks 2
- instanceof SqlSemantics\Platform\Sqlite\Rules\Definition\PrimaryKeyRule::key() packages/sql-semantics-sqlite/src/Rules/Definition/PrimaryKeyRule.php:44
- instanceof SqlSemantics\Platform\Sqlite\Statement\Schema\Column\ColumnDefinition::primaryKey() packages/sql-semantics-sqlite/src/Statement/Schema/Column/ColumnDefinition.php:80