packages/ztd-query-core/src/Schema/Partition/TablePartitionKey.php

1<?php
2
3declare(strict_types=1);
4
5namespace ZtdQuery\Schema\Partition;
6
7use ZtdQuery\Exception\InvalidDefinitionException;
8
9/**
10 * What a table's division into partitions is by.
11 *
12 * A key may be columns or expressions over them, and which partition a row
13 * belongs in is decided by evaluating it.
14 */
15final class TablePartitionKey
16{
17    /**
18     * @param non-empty-list<string> $expressions
19     *
20     * @throws InvalidDefinitionException When an expression the division is by is empty
21     */
22    public function __construct(
23        public readonly TablePartitionStrategy $strategy,
24        public readonly array $expressions,
25    ) {
26        foreach ($expressions as $expression) {
27            if (trim($expression) === '') {
28                throw new InvalidDefinitionException('Partition key expressions must not be empty.');
29            }
30        }
31    }
32}
33