packages/sql-semantics-sqlite/resources/models/Value/OneselectWithSelectDistinctSelcollistFromWhereOptGroupbyOptHavingOptWindowClauseOrderbyO_9a3dd714.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\Sqlite\Value;
6
7/**
8 * The oneselect 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\Sqlite\Value\OneselectWithSelectDistinctSelcollistFromWhereOptGroupbyOptHavingOptWindowClauseOrderbyO_9a3dd714 $value): string => \SqlSemantics\Statement\Writer::render($value);
13 *     $write instanceof \Closure // => true
14 */
15final class OneselectWithSelectDistinctSelcollistFromWhereOptGroupbyOptHavingOptWindowClauseOrderbyO_9a3dd714 implements \SqlSemantics\Statement\Model\Sqlite\Role\CmdForm, \SqlSemantics\Statement\Model\Sqlite\Role\CmdxForm, \SqlSemantics\Statement\Model\Sqlite\Role\OneselectForm, \SqlSemantics\Statement\Model\Sqlite\Role\SelectForm, \SqlSemantics\Statement\Model\Sqlite\Role\SelectnowithForm, \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\Sqlite\Role\DistinctForm $distinct,
24        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\SelcollistForm $projections,
25        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\FromForm $from,
26        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\WhereOptForm $where,
27        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\GroupbyOptForm $groupBy,
28        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\HavingOptForm $having,
29        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\WindowClauseForm $windowClause,
30        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\OrderbyOptForm $orderBy,
31        public readonly \SqlSemantics\Statement\Model\Sqlite\Role\LimitOptForm $pagination,
32        public readonly \SqlSemantics\Statement\Comments $comments = new \SqlSemantics\Statement\Comments(),
33    ) {
34        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($distinct), 'The distinct must be a generated immutable SQL value.');
35        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($projections), 'The projections must be a generated immutable SQL value.');
36        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($from), 'The from must be a generated immutable SQL value.');
37        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($where), 'The where must be a generated immutable SQL value.');
38        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($groupBy), 'The groupBy must be a generated immutable SQL value.');
39        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($having), 'The having must be a generated immutable SQL value.');
40        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($windowClause), 'The windowClause must be a generated immutable SQL value.');
41        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($orderBy), 'The orderBy must be a generated immutable SQL value.');
42        $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($pagination), 'The pagination must be a generated immutable SQL value.');
43    }
44
45    /**
46     * Writes SQL entirely from this value's fields.
47     */
48    public function write(\SqlSemantics\Statement\Writer $writer): void
49    {
50        $writer->comments($this->comments, 0);
51        $writer->append('SELECT');
52        $writer->comments($this->comments, 1);
53        $this->distinct->write($writer);
54        $writer->comments($this->comments, 2);
55        $this->projections->write($writer);
56        $writer->comments($this->comments, 3);
57        $this->from->write($writer);
58        $writer->comments($this->comments, 4);
59        $this->where->write($writer);
60        $writer->comments($this->comments, 5);
61        $this->groupBy->write($writer);
62        $writer->comments($this->comments, 6);
63        $this->having->write($writer);
64        $writer->comments($this->comments, 7);
65        $this->windowClause->write($writer);
66        $writer->comments($this->comments, 8);
67        $this->orderBy->write($writer);
68        $writer->comments($this->comments, 9);
69        $this->pagination->write($writer);
70    }
71
72    /**
73     * Returns a copy with a new distinct, preserving every other field.
74     */
75    public function withDistinct(\SqlSemantics\Statement\Model\Sqlite\Role\DistinctForm $distinct): self
76    {
77        return new self($distinct, $this->projections, $this->from, $this->where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
78    }
79
80    /**
81     * Returns a copy with a new projections, preserving every other field.
82     */
83    public function withProjections(\SqlSemantics\Statement\Model\Sqlite\Role\SelcollistForm $projections): self
84    {
85        return new self($this->distinct, $projections, $this->from, $this->where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
86    }
87
88    /**
89     * Returns a copy with a new from, preserving every other field.
90     */
91    public function withFrom(\SqlSemantics\Statement\Model\Sqlite\Role\FromForm $from): self
92    {
93        return new self($this->distinct, $this->projections, $from, $this->where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
94    }
95
96    /**
97     * Returns a copy with a new where, preserving every other field.
98     */
99    public function withWhere(\SqlSemantics\Statement\Model\Sqlite\Role\WhereOptForm $where): self
100    {
101        return new self($this->distinct, $this->projections, $this->from, $where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
102    }
103
104    /**
105     * Returns a copy with a new groupBy, preserving every other field.
106     */
107    public function withGroupBy(\SqlSemantics\Statement\Model\Sqlite\Role\GroupbyOptForm $groupBy): self
108    {
109        return new self($this->distinct, $this->projections, $this->from, $this->where, $groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
110    }
111
112    /**
113     * Returns a copy with a new having, preserving every other field.
114     */
115    public function withHaving(\SqlSemantics\Statement\Model\Sqlite\Role\HavingOptForm $having): self
116    {
117        return new self($this->distinct, $this->projections, $this->from, $this->where, $this->groupBy, $having, $this->windowClause, $this->orderBy, $this->pagination, $this->comments);
118    }
119
120    /**
121     * Returns a copy with a new windowClause, preserving every other field.
122     */
123    public function withWindowClause(\SqlSemantics\Statement\Model\Sqlite\Role\WindowClauseForm $windowClause): self
124    {
125        return new self($this->distinct, $this->projections, $this->from, $this->where, $this->groupBy, $this->having, $windowClause, $this->orderBy, $this->pagination, $this->comments);
126    }
127
128    /**
129     * Returns a copy with a new orderBy, preserving every other field.
130     */
131    public function withOrderBy(\SqlSemantics\Statement\Model\Sqlite\Role\OrderbyOptForm $orderBy): self
132    {
133        return new self($this->distinct, $this->projections, $this->from, $this->where, $this->groupBy, $this->having, $this->windowClause, $orderBy, $this->pagination, $this->comments);
134    }
135
136    /**
137     * Returns a copy with a new pagination, preserving every other field.
138     */
139    public function withPagination(\SqlSemantics\Statement\Model\Sqlite\Role\LimitOptForm $pagination): self
140    {
141        return new self($this->distinct, $this->projections, $this->from, $this->where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $pagination, $this->comments);
142    }
143
144    /**
145     * Returns a copy with a new comments, preserving every other field.
146     */
147    public function withComments(\SqlSemantics\Statement\Comments $comments): self
148    {
149        return new self($this->distinct, $this->projections, $this->from, $this->where, $this->groupBy, $this->having, $this->windowClause, $this->orderBy, $this->pagination, $comments);
150    }
151}
152