packages/ztd-query-core/src/Shadow/Row/TableTransition.php

1<?php
2
3declare(strict_types=1);
4
5namespace ZtdQuery\Shadow\Row;
6
7use ZtdQuery\Schema\TableDefinition;
8
9/**
10 * What happened to one table, as the rows themselves rather than as a count.
11 *
12 * A referential action is decided by the values in the rows that moved, so
13 * what a statement did has to be carried around as those rows and not as the
14 * number of them.
15 *
16 * @phpstan-import-type Row from TableDefinition
17 */
18final class TableTransition
19{
20    /**
21     * @param string $table Table this happened to
22     * @param array<int, Row> $deleted Rows that are no longer there
23     * @param list<RowChange> $updated Rows that are still there, changed
24     */
25    public function __construct(
26        public readonly string $table,
27        public readonly array $deleted,
28        public readonly array $updated,
29    ) {
30    }
31
32    /**
33     * Reports whether nothing happened to the table.
34     *
35     * @return bool True when no row was deleted and none was changed
36     */
37    public function isEmpty(): bool
38    {
39        return $this->deleted === [] && $this->updated === [];
40    }
41}
42