Исправление ошибок и обработка for

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2021-04-11 11:48:55 +10:00
parent eb5e18dfd6
commit 778513b3bb

View File

@ -229,7 +229,6 @@ class Query extends Component implements QueryInterface
return $this;
}
/**
* Обойти коллекцию вершин по направлению
*
@ -253,24 +252,43 @@ class Query extends Component implements QueryInterface
return $this;
}
/**
* Проверка типа и конвертация
*/
protected static function checkArrayAndConvert(string|array $text): string
{
if (is_array($text)) {
return self::convertArrayToString($text);
}
return $text;
}
/**
* Конвертация в строку
*/
protected static function convertArrayToString(array $text): string
{
// Очистка
array_walk($text, 'trim');
// Конвертация
return implode(", ", $text);
}
/**
* Генерация AQL конструкции "FOR"
*
* Примеры:
* 1. "FOR account"
* 2. "FOR account, account_edge_supply"
*
*/
protected static function genFor(string|array $for): string
{
if (is_array($for)) {
// Если передан массив, то конвертировать в строку
// Очистка элементов через trim()
array_walk($for, 'trim');
// Конвертация
$for = implode(", ", $for);
$for = self::convertArrayToString($for);
}
// Генерация
@ -822,7 +840,7 @@ class Query extends Component implements QueryInterface
$query ?? $query = $this;
$query->in ?? $query->in = $query->collection ?? throw new Exception('Не найдена коллекция');
$query->for ?? $query->for = $query->in;
$query->collection ?? $query->collection = $query->in;
$query->collection ?? $query->collection = self::checkArrayAndConvert($query->for);
$params = array_merge($params, $query->params);
@ -929,12 +947,12 @@ class Query extends Component implements QueryInterface
{
// Инициализация
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->collection ?? $this->collection = $this->in ;
$query->collection ?? $query->collection = self::checkArrayAndConvert($query->for);
$data = Serializer::encode($columns);
$clauses = [
"INSERT $data IN {$this->quoteCollectionName($this->in ?? $this->collection)}",
"INSERT $data IN {$this->quoteCollectionName($this->collection)}",
$this->genOptions(),
];
@ -976,7 +994,7 @@ class Query extends Component implements QueryInterface
// Инициализация
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->for ?? $this->for = $this->in;
$this->collection ?? $this->collection = $this->in;
$query->collection ?? $query->collection = self::checkArrayAndConvert($query->for);
$clauses = [
static::genFor($this->for),
@ -1028,7 +1046,7 @@ class Query extends Component implements QueryInterface
// Инициализация
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->for ?? $this->for = $this->in;
$this->collection ?? $this->collection = $this->in;
$query->collection ?? $query->collection = self::checkArrayAndConvert($query->for);
$clauses = [
static::genFor($this->for),