packages/sql-semantics-mysql/resources/models/Value/InsertWithInsertInsertLockOptionOptIgnoreInsert2InsertFieldSpecOptInsertUpdate_d0b84c1a.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\MySql\Value;
6
7/**
8 * The insert 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\MySql\Value\InsertWithInsertInsertLockOptionOptIgnoreInsert2InsertFieldSpecOptInsertUpdate_d0b84c1a $value): string => \SqlSemantics\Statement\Writer::render($value);
13 * $write instanceof \Closure // => true
14 */
15final class InsertWithInsertInsertLockOptionOptIgnoreInsert2InsertFieldSpecOptInsertUpdate_d0b84c1a implements \SqlSemantics\Statement\Model\MySql\Role\EvSqlStmtForm, \SqlSemantics\Statement\Model\MySql\Role\EvSqlStmtInnerForm, \SqlSemantics\Statement\Model\MySql\Role\ExplanableCommandForm, \SqlSemantics\Statement\Model\MySql\Role\InsertForm, \SqlSemantics\Statement\Model\MySql\Role\SpProcStmtForm, \SqlSemantics\Statement\Model\MySql\Role\SpProcStmtStatementForm, \SqlSemantics\Statement\Model\MySql\Role\StatementForm, \SqlSemantics\Statement\Model\MySql\Role\StoredRoutineBodyForm, \SqlSemantics\Statement\Model\MySql\Role\VerbClauseForm
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\MySql\Role\InsertLockOptionForm $insertLockOption,
24 public readonly \SqlSemantics\Statement\Model\MySql\Role\OptIgnoreForm $optIgnore,
25 public readonly \SqlSemantics\Statement\Model\MySql\Role\Insert2Form $insert2,
26 public readonly \SqlSemantics\Statement\Model\MySql\Role\InsertFieldSpecForm $insertFieldSpec,
27 public readonly \SqlSemantics\Statement\Model\MySql\Role\OptInsertUpdateForm $optInsertUpdate,
28 public readonly \SqlSemantics\Statement\Comments $comments = new \SqlSemantics\Statement\Comments(),
29 ) {
30 $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($insertLockOption), 'The insertLockOption must be a generated immutable SQL value.');
31 $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($optIgnore), 'The optIgnore must be a generated immutable SQL value.');
32 $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($insert2), 'The insert2 must be a generated immutable SQL value.');
33 $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($insertFieldSpec), 'The insertFieldSpec must be a generated immutable SQL value.');
34 $this->assert(\SqlSemantics\Statement\Model\MySql\Contract\Contracts::contains($optInsertUpdate), 'The optInsertUpdate must be a generated immutable SQL value.');
35 }
36
37 /**
38 * Writes SQL entirely from this value's fields.
39 */
40 public function write(\SqlSemantics\Statement\Writer $writer): void
41 {
42 $writer->comments($this->comments, 0);
43 $writer->append('INSERT');
44 $writer->comments($this->comments, 1);
45 $this->insertLockOption->write($writer);
46 $writer->comments($this->comments, 2);
47 $this->optIgnore->write($writer);
48 $writer->comments($this->comments, 3);
49 $this->insert2->write($writer);
50 $writer->comments($this->comments, 4);
51 $this->insertFieldSpec->write($writer);
52 $writer->comments($this->comments, 5);
53 $this->optInsertUpdate->write($writer);
54 }
55
56 /**
57 * Returns a copy with a new insertLockOption, preserving every other field.
58 */
59 public function withInsertLockOption(\SqlSemantics\Statement\Model\MySql\Role\InsertLockOptionForm $insertLockOption): self
60 {
61 return new self($insertLockOption, $this->optIgnore, $this->insert2, $this->insertFieldSpec, $this->optInsertUpdate, $this->comments);
62 }
63
64 /**
65 * Returns a copy with a new optIgnore, preserving every other field.
66 */
67 public function withOptIgnore(\SqlSemantics\Statement\Model\MySql\Role\OptIgnoreForm $optIgnore): self
68 {
69 return new self($this->insertLockOption, $optIgnore, $this->insert2, $this->insertFieldSpec, $this->optInsertUpdate, $this->comments);
70 }
71
72 /**
73 * Returns a copy with a new insert2, preserving every other field.
74 */
75 public function withInsert2(\SqlSemantics\Statement\Model\MySql\Role\Insert2Form $insert2): self
76 {
77 return new self($this->insertLockOption, $this->optIgnore, $insert2, $this->insertFieldSpec, $this->optInsertUpdate, $this->comments);
78 }
79
80 /**
81 * Returns a copy with a new insertFieldSpec, preserving every other field.
82 */
83 public function withInsertFieldSpec(\SqlSemantics\Statement\Model\MySql\Role\InsertFieldSpecForm $insertFieldSpec): self
84 {
85 return new self($this->insertLockOption, $this->optIgnore, $this->insert2, $insertFieldSpec, $this->optInsertUpdate, $this->comments);
86 }
87
88 /**
89 * Returns a copy with a new optInsertUpdate, preserving every other field.
90 */
91 public function withOptInsertUpdate(\SqlSemantics\Statement\Model\MySql\Role\OptInsertUpdateForm $optInsertUpdate): self
92 {
93 return new self($this->insertLockOption, $this->optIgnore, $this->insert2, $this->insertFieldSpec, $optInsertUpdate, $this->comments);
94 }
95
96 /**
97 * Returns a copy with a new comments, preserving every other field.
98 */
99 public function withComments(\SqlSemantics\Statement\Comments $comments): self
100 {
101 return new self($this->insertLockOption, $this->optIgnore, $this->insert2, $this->insertFieldSpec, $this->optInsertUpdate, $comments);
102 }
103}
104