packages/sql-semantics-postgres/src/Statement/Catalog/Extension/ExtensionSchema.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Catalog\Extension;
6
7use SqlSemantics\Platform\PostgreSql\Model\Contract\NameUse;
8use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
9use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
10use SqlSemantics\Platform\PostgreSql\Model\Statement\Snapshot;
11
12/**
13 * The SCHEMA option of CREATE EXTENSION: the schema the objects of the extension go into.
14 *
15 * Source: https://www.postgresql.org/docs/17/sql-createextension.html.
16 *
17 * @visibility public
18 * @example Reading the target schema
19 * (new \SqlSemantics\Platform\PostgreSql\Statement\Catalog\Extension\ExtensionSchema(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('ext')))->schema->value // => 'ext'
20 */
21final class ExtensionSchema implements ExtensionOption
22{
23 use Snapshot;
24
25 /**
26 * @param Name $schema The schema name
27 */
28 public function __construct(public readonly Name $schema)
29 {
30 }
31
32 /**
33 * Answers the option name the server receives.
34 */
35 public function option(): string
36 {
37 return 'schema';
38 }
39
40 /**
41 * Writes SCHEMA and the name.
42 */
43 public function render(Output $out): void
44 {
45 $out->keyword('SCHEMA')->name($this->schema, NameUse::Column);
46 }
47}
48