packages/sql-semantics-sqlite/resources/models/Value/ExprWithExprInOpLpSelectRp_a20110e2.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Statement\Model\Sqlite\Value;
6
7/**
8 * The expr 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\ExprWithExprInOpLpSelectRp_a20110e2 $value): string => \SqlSemantics\Statement\Writer::render($value);
13 * $write instanceof \Closure // => true
14 */
15final class ExprWithExprInOpLpSelectRp_a20110e2 implements \SqlSemantics\Statement\Model\Sqlite\Role\CaseOperandForm, \SqlSemantics\Statement\Model\Sqlite\Role\ExprForm, \SqlSemantics\Statement\Model\Sqlite\Role\ExprlistForm, \SqlSemantics\Statement\Model\Sqlite\Role\NexprlistForm
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\ExprForm $expr,
24 public readonly \SqlSemantics\Statement\Model\Sqlite\Role\InOpForm $inOp,
25 public readonly \SqlSemantics\Statement\Model\Sqlite\Role\SelectForm $select,
26 public readonly \SqlSemantics\Statement\Comments $comments = new \SqlSemantics\Statement\Comments(),
27 ) {
28 $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($expr), 'The expr must be a generated immutable SQL value.');
29 $this->assertOperandBindingStrength($expr, \SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::BINDING_POWERS, array ( 'sqlite-3.47.2' => 4,));
30 $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($inOp), 'The inOp must be a generated immutable SQL value.');
31 $this->assert(\SqlSemantics\Statement\Model\Sqlite\Contract\Contracts::contains($select), 'The select must be a generated immutable SQL value.');
32 }
33
34 /**
35 * Writes SQL entirely from this value's fields.
36 */
37 public function write(\SqlSemantics\Statement\Writer $writer): void
38 {
39 $writer->comments($this->comments, 0);
40 $this->expr->write($writer);
41 $writer->comments($this->comments, 1);
42 $this->inOp->write($writer);
43 $writer->comments($this->comments, 2);
44 $writer->append('(');
45 $writer->comments($this->comments, 3);
46 $this->select->write($writer);
47 $writer->comments($this->comments, 4);
48 $writer->append(')');
49 }
50
51 /**
52 * Returns a copy with a new expr, preserving every other field.
53 */
54 public function withExpr(\SqlSemantics\Statement\Model\Sqlite\Role\ExprForm $expr): self
55 {
56 return new self($expr, $this->inOp, $this->select, $this->comments);
57 }
58
59 /**
60 * Returns a copy with a new inOp, preserving every other field.
61 */
62 public function withInOp(\SqlSemantics\Statement\Model\Sqlite\Role\InOpForm $inOp): self
63 {
64 return new self($this->expr, $inOp, $this->select, $this->comments);
65 }
66
67 /**
68 * Returns a copy with a new select, preserving every other field.
69 */
70 public function withSelect(\SqlSemantics\Statement\Model\Sqlite\Role\SelectForm $select): self
71 {
72 return new self($this->expr, $this->inOp, $select, $this->comments);
73 }
74
75 /**
76 * Returns a copy with a new comments, preserving every other field.
77 */
78 public function withComments(\SqlSemantics\Statement\Comments $comments): self
79 {
80 return new self($this->expr, $this->inOp, $this->select, $comments);
81 }
82}
83