Улучшение логики запросов

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2021-04-11 02:39:51 +10:00
parent 7a6e6fbada
commit bb7b1b8f8e
3 changed files with 25 additions and 17 deletions

View File

@ -103,9 +103,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface
public function all($db = null)
{
$statement = $this->createCommand($db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
$cursor = $statement->execute();

View File

@ -23,7 +23,7 @@ abstract class Migration extends Component implements MigrationInterface
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::class;
$this->db = Instance::ensure($this->db, Connection::class);
}
public function execute($aql, $bindValues = [], $params = [])

View File

@ -819,16 +819,16 @@ class Query extends Component implements QueryInterface
protected function genQuery($query = null, array $params = [])
{
// Инициализация
isset($query) ? $query : $query = $this;
$this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция'));
$query ?? $query = $this;
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->for ?? $this->for = $this->in;
$this->collection ?? $this->collection = $this->in;
$this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for;
$params = array_merge($params, $query->params);
$clauses = [
static::genFor($query->for ?? $query->collection),
static::genIn($query->in ?? $query->collection, $query->traversals),
static::genFor($query->for),
static::genIn($query->in, $query->traversals),
static::genLet($query->lets),
$this->genForeach($query->foreach),
$this->genWhere($query->where, $params),
@ -874,9 +874,11 @@ class Query extends Component implements QueryInterface
public function all($db = null)
{
$statement = $this->createCommand($db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
$cursor = $statement->execute();
@ -885,6 +887,7 @@ class Query extends Component implements QueryInterface
Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::query');
throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
}
return $this->prepareResult($cursor->getAll());
}
@ -894,10 +897,13 @@ class Query extends Component implements QueryInterface
public function one($db = null)
{
$this->limit(1);
$statement = $this->createCommand($db);
$token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
$cursor = $statement->execute();
@ -923,7 +929,7 @@ class Query extends Component implements QueryInterface
{
// Инициализация
$this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция'));
$this->collection ?? $this->collection = $this->in;
$this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for;
$data = Serializer::encode($columns);
@ -968,15 +974,15 @@ class Query extends Component implements QueryInterface
public function update($columns, $params = [], $db = null)
{
// Инициализация
$this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция'));
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->for ?? $this->for = $this->in;
$this->collection ?? $this->collection = $this->in;
$this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for;
$clauses = [
static::genFor($this->for ?? $this->collection),
static::genIn($this->in ?? $this->collection, $this->traversals),
static::genFor($this->for),
static::genIn($this->in, $this->traversals),
$this->genWhere($this->where, $params),
$this->genUpdate($this->collection, $columns),
$this->genUpdate($this->in, $columns),
$this->genOptions(),
];
@ -1020,15 +1026,15 @@ class Query extends Component implements QueryInterface
public function remove($params = [], $db = null)
{
// Инициализация
$this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция'));
$this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция');
$this->for ?? $this->for = $this->in;
$this->collection ?? $this->collection = $this->in;
$this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for;
$clauses = [
static::genFor($this->for ?? $this->collection),
static::genIn($this->in ?? $this->collection, $this->traversals),
static::genFor($this->for),
static::genIn($this->in, $this->traversals),
$this->genWhere($this->where, $params),
$this->genRemove($this->in ?? $this->collection),
$this->genRemove($this->in),
$this->genOptions(),
];