packages/sql-semantics-postgres/src/Statement/Object/Attribute/Choice/StorageStrategy.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Object\Attribute\Choice;
6
7/**
8 * The `storage` attribute of a base type: how values of a variable-length type are stored.
9 *
10 * `DefineType` compares the text without regard to case.
11 * Source: https://www.postgresql.org/docs/17/sql-createtype.html, `DefineType` in `src/backend/commands/typecmds.c` of PostgreSQL 17.
12 *
13 * @visibility public
14 * @example Reading a storage strategy
15 * \SqlSemantics\Platform\PostgreSql\Statement\Object\Attribute\Choice\StorageStrategy::read('EXTENDED')?->name // => 'Extended'
16 */
17enum StorageStrategy: string implements Choice
18{
19 case Plain = 'plain';
20 case External = 'external';
21 case Extended = 'extended';
22 case Main = 'main';
23
24 /**
25 * Answers the strategy the text names without regard to case, or null.
26 */
27 public static function read(string $text): ?self
28 {
29 return self::tryFrom(strtolower($text));
30 }
31}
32