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