packages/sql-semantics-postgres/resources/models/Value/RuleStmtWithCreateOptOrReplaceRuleNameAsOnEventToQualifiedNameWhereClauseDoOptInsteadRu_c6b5c1e9.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\PostgreSql\Value;
6
7/**
8 * The RuleStmt SQL value; generated by bin/build-models.php.
9 *
10 * @visibility public
11 * @example Accept a structured SQL value
12 * $write = static fn (\SqlSemantics\Statement\Model\PostgreSql\Value\RuleStmtWithCreateOptOrReplaceRuleNameAsOnEventToQualifiedNameWhereClauseDoOptInsteadRu_c6b5c1e9 $value): string => \SqlSemantics\Statement\Writer::render($value);
13 * $write instanceof \Closure // => true
14 */
15final class RuleStmtWithCreateOptOrReplaceRuleNameAsOnEventToQualifiedNameWhereClauseDoOptInsteadRu_c6b5c1e9 implements \SqlSemantics\Statement\Model\PostgreSql\Role\RuleStmtForm, \SqlSemantics\Statement\Model\PostgreSql\Role\ParseToplevelForm, \SqlSemantics\Statement\Model\PostgreSql\Role\RoutineBodyStmtForm, \SqlSemantics\Statement\Model\PostgreSql\Role\StmtForm, \SqlSemantics\Statement\Model\PostgreSql\Role\StmtmultiForm, \SqlSemantics\Statement\Model\PostgreSql\Role\ToplevelStmtForm, \SqlSemantics\Statement\Command
16{
17 use \SqlSemantics\Statement\Assertion;
18
19 /**
20 * Supplies the SQL values of this form; comments are kept by the position of the symbol each precedes.
21 */
22 public function __construct(
23 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\OptOrReplaceForm $optOrReplace,
24 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\NameForm $name,
25 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\EventForm $event,
26 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\QualifiedNameForm $qualifiedName,
27 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\WhereClauseForm $where,
28 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\OptInsteadForm $optInstead,
29 public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\RuleActionListForm $ruleActionList,
30 public readonly \SqlSemantics\Statement\Comments $comments = new \SqlSemantics\Statement\Comments(),
31 ) {
32 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($optOrReplace), 'The optOrReplace must be a generated immutable SQL value.');
33 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($name), 'The name must be a generated immutable SQL value.');
34 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($event), 'The event must be a generated immutable SQL value.');
35 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($qualifiedName), 'The qualifiedName must be a generated immutable SQL value.');
36 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($where), 'The where must be a generated immutable SQL value.');
37 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($optInstead), 'The optInstead must be a generated immutable SQL value.');
38 $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($ruleActionList), 'The ruleActionList must be a generated immutable SQL value.');
39 }
40
41 /**
42 * Writes SQL entirely from this value's fields.
43 */
44 public function write(\SqlSemantics\Statement\Writer $writer): void
45 {
46 $writer->comments($this->comments, 0);
47 $writer->append('CREATE');
48 $writer->comments($this->comments, 1);
49 $this->optOrReplace->write($writer);
50 $writer->comments($this->comments, 2);
51 $writer->append('RULE');
52 $writer->comments($this->comments, 3);
53 $this->name->write($writer);
54 $writer->comments($this->comments, 4);
55 $writer->append('AS');
56 $writer->comments($this->comments, 5);
57 $writer->append('ON');
58 $writer->comments($this->comments, 6);
59 $this->event->write($writer);
60 $writer->comments($this->comments, 7);
61 $writer->append('TO');
62 $writer->comments($this->comments, 8);
63 $this->qualifiedName->write($writer);
64 $writer->comments($this->comments, 9);
65 $this->where->write($writer);
66 $writer->comments($this->comments, 10);
67 $writer->append('DO');
68 $writer->comments($this->comments, 11);
69 $this->optInstead->write($writer);
70 $writer->comments($this->comments, 12);
71 $this->ruleActionList->write($writer);
72 }
73
74 /**
75 * Returns a copy with a new optOrReplace, preserving every other field.
76 */
77 public function withOptOrReplace(\SqlSemantics\Statement\Model\PostgreSql\Role\OptOrReplaceForm $optOrReplace): self
78 {
79 return new self($optOrReplace, $this->name, $this->event, $this->qualifiedName, $this->where, $this->optInstead, $this->ruleActionList, $this->comments);
80 }
81
82 /**
83 * Returns a copy with a new name, preserving every other field.
84 */
85 public function withName(\SqlSemantics\Statement\Model\PostgreSql\Role\NameForm $name): self
86 {
87 return new self($this->optOrReplace, $name, $this->event, $this->qualifiedName, $this->where, $this->optInstead, $this->ruleActionList, $this->comments);
88 }
89
90 /**
91 * Returns a copy with a new event, preserving every other field.
92 */
93 public function withEvent(\SqlSemantics\Statement\Model\PostgreSql\Role\EventForm $event): self
94 {
95 return new self($this->optOrReplace, $this->name, $event, $this->qualifiedName, $this->where, $this->optInstead, $this->ruleActionList, $this->comments);
96 }
97
98 /**
99 * Returns a copy with a new qualifiedName, preserving every other field.
100 */
101 public function withQualifiedName(\SqlSemantics\Statement\Model\PostgreSql\Role\QualifiedNameForm $qualifiedName): self
102 {
103 return new self($this->optOrReplace, $this->name, $this->event, $qualifiedName, $this->where, $this->optInstead, $this->ruleActionList, $this->comments);
104 }
105
106 /**
107 * Returns a copy with a new where, preserving every other field.
108 */
109 public function withWhere(\SqlSemantics\Statement\Model\PostgreSql\Role\WhereClauseForm $where): self
110 {
111 return new self($this->optOrReplace, $this->name, $this->event, $this->qualifiedName, $where, $this->optInstead, $this->ruleActionList, $this->comments);
112 }
113
114 /**
115 * Returns a copy with a new optInstead, preserving every other field.
116 */
117 public function withOptInstead(\SqlSemantics\Statement\Model\PostgreSql\Role\OptInsteadForm $optInstead): self
118 {
119 return new self($this->optOrReplace, $this->name, $this->event, $this->qualifiedName, $this->where, $optInstead, $this->ruleActionList, $this->comments);
120 }
121
122 /**
123 * Returns a copy with a new ruleActionList, preserving every other field.
124 */
125 public function withRuleActionList(\SqlSemantics\Statement\Model\PostgreSql\Role\RuleActionListForm $ruleActionList): self
126 {
127 return new self($this->optOrReplace, $this->name, $this->event, $this->qualifiedName, $this->where, $this->optInstead, $ruleActionList, $this->comments);
128 }
129
130 /**
131 * Returns a copy with a new comments, preserving every other field.
132 */
133 public function withComments(\SqlSemantics\Statement\Comments $comments): self
134 {
135 return new self($this->optOrReplace, $this->name, $this->event, $this->qualifiedName, $this->where, $this->optInstead, $this->ruleActionList, $comments);
136 }
137}
138