packages/sql-semantics-mysql/src/Statement/Routine/Trigger/TriggerOrder.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\MySql\Statement\Routine\Trigger;
6
7use SqlSemantics\Platform\MySql\Model\Contract\NameUse;
8use SqlSemantics\Platform\MySql\Model\Rendering\Output;
9use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
10use SqlSemantics\Platform\MySql\Model\Statement\Node;
11use SqlSemantics\Platform\MySql\Model\Statement\Snapshot;
12
13/**
14 * The FOLLOWS or PRECEDES clause of CREATE TRIGGER (MySQL 5.7 and later).
15 *
16 * Source: https://dev.mysql.com/doc/refman/8.4/en/create-trigger.html.
17 *
18 * @visibility public
19 * @example Reading the order of a trigger
20 * $create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TRIGGER tr BEFORE INSERT ON t FOR EACH ROW PRECEDES other SET @a = 1');
21 * [$create->statement->order->placement->value, $create->statement->order->other->value] // => ['PRECEDES', 'other']
22 */
23final class TriggerOrder implements Node
24{
25 use Snapshot;
26
27 /**
28 * @param OrderPlacement $placement Whether the trigger runs after or before the other
29 * @param Name $other The name of the other trigger
30 */
31 public function __construct(public readonly OrderPlacement $placement, public readonly Name $other)
32 {
33 }
34
35 /**
36 * Writes the keyword and the other trigger name.
37 */
38 public function render(Output $out): void
39 {
40 $out->keyword($this->placement->value)->name($this->other, NameUse::Identifier);
41 }
42}
43