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

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) public function all($db = null)
{ {
$statement = $this->createCommand($db); $statement = $this->createCommand($db);
$token = $this->getRawAql($statement); $token = $this->getRawAql($statement);
Yii::info($token, 'mirzaev\yii2\arangodb\Query::query'); Yii::info($token, 'mirzaev\yii2\arangodb\Query::query');
try { try {
Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query'); Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query');
$cursor = $statement->execute(); $cursor = $statement->execute();

View File

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