/
githubmirror
/
ydb-php-sdk
Обзор
Документация
Войти
/
githubmirror
/
ydb-php-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Types/OptionalType.php
86 строк
2 KB
Ilya Kharev
Added OptionalType
22 июн 2023, 14:04
22 июн 2023, 14:04
af0e221
Код
Авторство
О чём код?
<?php namespace YdbPlatform\Ydb\Types; use Ydb\Type; class OptionalType extends AbstractType { /** * @var string */ protected $itemType; /** * @inherit */ protected function normalizeValue($value) { return $this->typeValue($value, $this->itemType)->normalizeValue($value); } /** * @param string $type * @return $this */ public function itemType($type) { $this->itemType = $type; return $this; } /** * @inherit */ public function toYdbValue() { return $this->typeValue($this->value, $this->itemType)->toYdbValue(); } /** * @inherit */ public function getYdbType() { $type_id = $this->convertType($this->itemType); if ($type_id) { return new Type([ 'optional_type' => new \Ydb\OptionalType([ 'item' => new Type([ 'type_id' => $type_id, ]), ]), ]); } else { $value = $this->typeValue('', $this->itemType); return new Type([ 'optional_type' => new \Ydb\OptionalType([ 'item' => $value->getYdbType(), ]), ]); } } /** * @inherit */ public function toYdbType() { return $this->getYdbType(); } /** * @inherit */ protected function getYqlString() { $value = $this->typeValue($this->value, $this->itemType)->toYqlString(); return '(' . $value . ')'; } }