packages/sql-semantics-postgres/resources/models/Value/CreatePLangStmtWithCreateOptOrReplaceOptTrustedOptProceduralLanguageNameHandlerHandlerNameOptI_8ae70d23.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\PostgreSql\Value;
6
7/**
8 * The CreatePLangStmt 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\CreatePLangStmtWithCreateOptOrReplaceOptTrustedOptProceduralLanguageNameHandlerHandlerNameOptI_8ae70d23 $value): string => \SqlSemantics\Statement\Writer::render($value);
13 *     $write instanceof \Closure // => true
14 */
15final class CreatePLangStmtWithCreateOptOrReplaceOptTrustedOptProceduralLanguageNameHandlerHandlerNameOptI_8ae70d23 implements \SqlSemantics\Statement\Model\PostgreSql\Role\CreatePLangStmtForm, \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\OptTrustedForm $optTrusted,
25        public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\OptProceduralForm $optProcedural,
26        public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\NameForm $name,
27        public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\HandlerNameForm $handlerName,
28        public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\OptInlineHandlerForm $optInlineHandler,
29        public readonly \SqlSemantics\Statement\Model\PostgreSql\Role\OptValidatorForm $optValidator,
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($optTrusted), 'The optTrusted must be a generated immutable SQL value.');
34        $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($optProcedural), 'The optProcedural must be a generated immutable SQL value.');
35        $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($name), 'The name must be a generated immutable SQL value.');
36        $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($handlerName), 'The handlerName must be a generated immutable SQL value.');
37        $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($optInlineHandler), 'The optInlineHandler must be a generated immutable SQL value.');
38        $this->assert(\SqlSemantics\Statement\Model\PostgreSql\Contract\Contracts::contains($optValidator), 'The optValidator 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        $this->optTrusted->write($writer);
52        $writer->comments($this->comments, 3);
53        $this->optProcedural->write($writer);
54        $writer->comments($this->comments, 4);
55        $writer->append('LANGUAGE');
56        $writer->comments($this->comments, 5);
57        $this->name->write($writer);
58        $writer->comments($this->comments, 6);
59        $writer->append('HANDLER');
60        $writer->comments($this->comments, 7);
61        $this->handlerName->write($writer);
62        $writer->comments($this->comments, 8);
63        $this->optInlineHandler->write($writer);
64        $writer->comments($this->comments, 9);
65        $this->optValidator->write($writer);
66    }
67
68    /**
69     * Returns a copy with a new optOrReplace, preserving every other field.
70     */
71    public function withOptOrReplace(\SqlSemantics\Statement\Model\PostgreSql\Role\OptOrReplaceForm $optOrReplace): self
72    {
73        return new self($optOrReplace, $this->optTrusted, $this->optProcedural, $this->name, $this->handlerName, $this->optInlineHandler, $this->optValidator, $this->comments);
74    }
75
76    /**
77     * Returns a copy with a new optTrusted, preserving every other field.
78     */
79    public function withOptTrusted(\SqlSemantics\Statement\Model\PostgreSql\Role\OptTrustedForm $optTrusted): self
80    {
81        return new self($this->optOrReplace, $optTrusted, $this->optProcedural, $this->name, $this->handlerName, $this->optInlineHandler, $this->optValidator, $this->comments);
82    }
83
84    /**
85     * Returns a copy with a new optProcedural, preserving every other field.
86     */
87    public function withOptProcedural(\SqlSemantics\Statement\Model\PostgreSql\Role\OptProceduralForm $optProcedural): self
88    {
89        return new self($this->optOrReplace, $this->optTrusted, $optProcedural, $this->name, $this->handlerName, $this->optInlineHandler, $this->optValidator, $this->comments);
90    }
91
92    /**
93     * Returns a copy with a new name, preserving every other field.
94     */
95    public function withName(\SqlSemantics\Statement\Model\PostgreSql\Role\NameForm $name): self
96    {
97        return new self($this->optOrReplace, $this->optTrusted, $this->optProcedural, $name, $this->handlerName, $this->optInlineHandler, $this->optValidator, $this->comments);
98    }
99
100    /**
101     * Returns a copy with a new handlerName, preserving every other field.
102     */
103    public function withHandlerName(\SqlSemantics\Statement\Model\PostgreSql\Role\HandlerNameForm $handlerName): self
104    {
105        return new self($this->optOrReplace, $this->optTrusted, $this->optProcedural, $this->name, $handlerName, $this->optInlineHandler, $this->optValidator, $this->comments);
106    }
107
108    /**
109     * Returns a copy with a new optInlineHandler, preserving every other field.
110     */
111    public function withOptInlineHandler(\SqlSemantics\Statement\Model\PostgreSql\Role\OptInlineHandlerForm $optInlineHandler): self
112    {
113        return new self($this->optOrReplace, $this->optTrusted, $this->optProcedural, $this->name, $this->handlerName, $optInlineHandler, $this->optValidator, $this->comments);
114    }
115
116    /**
117     * Returns a copy with a new optValidator, preserving every other field.
118     */
119    public function withOptValidator(\SqlSemantics\Statement\Model\PostgreSql\Role\OptValidatorForm $optValidator): self
120    {
121        return new self($this->optOrReplace, $this->optTrusted, $this->optProcedural, $this->name, $this->handlerName, $this->optInlineHandler, $optValidator, $this->comments);
122    }
123
124    /**
125     * Returns a copy with a new comments, preserving every other field.
126     */
127    public function withComments(\SqlSemantics\Statement\Comments $comments): self
128    {
129        return new self($this->optOrReplace, $this->optTrusted, $this->optProcedural, $this->name, $this->handlerName, $this->optInlineHandler, $this->optValidator, $comments);
130    }
131}
132