Skip to content

Commit 3dc950a

Browse files
committed
all ready for v2.0.1
1 parent a76bd53 commit 3dc950a

25 files changed

+806
-1914
lines changed

README.md

Lines changed: 632 additions & 76 deletions
Large diffs are not rendered by default.

commands/NewController.php

Lines changed: 0 additions & 162 deletions
This file was deleted.

commands/PdoController.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
4+
namespace app\commands;
5+
6+
7+
use Smoren\Yii2\QueryRelationManager\Base\QueryRelationManagerException;
8+
use Smoren\Yii2\QueryRelationManager\Pdo\QueryRelationManager;
9+
use Smoren\Yii2\QueryRelationManager\Pdo\QueryWrapper;
10+
use Yii;
11+
use yii\console\Controller;
12+
13+
/**
14+
* Контроллер для демонстрации работы QueryRelationManager с PDO вместо ORM
15+
* @package app\commands
16+
* @author Smoren <ofigate@gmail.com>
17+
*/
18+
class PdoController extends Controller
19+
{
20+
/**
21+
* Выбираем адреса с городом, местами и комментариями о местах
22+
* Используем PDO вместо ORM
23+
* @throws QueryRelationManagerException
24+
*/
25+
public function actionAddress()
26+
{
27+
QueryWrapper::setDbConfig(Yii::$app->db->dsn, Yii::$app->db->username, Yii::$app->db->password);
28+
29+
$result = QueryRelationManager::select('address', 'a')
30+
->withSingle('city', 'city', 'c', 'a', ['id' => 'city_id'])
31+
->withMultiple('places', 'place', 'p', 'a', ['address_id' => 'id'])
32+
->withMultiple('comments', 'comment', 'cm', 'p', ['place_id' => 'id'])
33+
->all();
34+
35+
print_r($result);
36+
}
37+
}

commands/ProfileController.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
use app\models\Comment;
1313
use app\models\Place;
1414
use app\helpers\ProfilerHelper;
15-
use app\qrm\ActiveRecord\QueryRelationDataProvider;
16-
use app\qrm\ActiveRecord\QueryRelationManager;
17-
use app\qrm\Base\QueryRelationManagerException;
15+
use Smoren\Yii2\QueryRelationManager\ActiveRecord\QueryRelationDataProvider;
16+
use Smoren\Yii2\QueryRelationManager\ActiveRecord\QueryRelationManager;
17+
use Smoren\Yii2\QueryRelationManager\Base\QueryRelationManagerException;
1818
use Yii;
1919
use yii\console\Controller;
2020
use yii\data\ActiveDataProvider;
2121
use yii\db\Exception;
2222

2323
/**
24-
* Контроллер для демонстрации работы QueryRelationManager
24+
* Контроллер для профилирования QueryRelationManager
25+
* @package app\commands
2526
* @author Smoren <ofigate@gmail.com>
2627
*/
2728
class ProfileController extends Controller
2829
{
2930
/**
3031
* Выбираем адреса с городом, местами и комментариями о местах
32+
* Сравниваем скорость работы ActiveQuery::joinWith и QueryRelationManager
3133
* @throws QueryRelationManagerException
3234
* @throws Exception
3335
*/
@@ -56,7 +58,8 @@ public function actionAddress()
5658
}
5759

5860
/**
59-
* Выбираем адреса с городом, местами и комментариями о местах
61+
* Выбираем адреса с городом, местами и комментариями о местах, используем DataProvider для постраничной навигации
62+
* Сравниваем скорость работы ActiveQuery::joinWith и QueryRelationManager
6063
* @throws QueryRelationManagerException
6164
* @throws Exception
6265
*/
@@ -127,6 +130,7 @@ public function actionProvider()
127130
}
128131

129132
/**
133+
* Генерирует миллион адресов
130134
* @throws Exception
131135
*/
132136
protected function genAddresses()
@@ -143,6 +147,7 @@ protected function genAddresses()
143147
}
144148

145149
/**
150+
* Удаляет сгенерированные адреса
146151
* @throws Exception
147152
*/
148153
protected function delAddresses()
@@ -153,10 +158,11 @@ protected function delAddresses()
153158
}
154159

155160
/**
156-
* @param string $who
157-
* @param float $time
158-
* @param int $foundCount
159-
* @param int|null $totalCount
161+
* Выводит данные профилирования в консоль
162+
* @param string $who предмет замера
163+
* @param float $time время работы
164+
* @param int|null $foundCount найдено записей
165+
* @param int|null $totalCount запрошено записей
160166
*/
161167
protected function log(string $who, float $time, ?int $foundCount = null, ?int $totalCount = null)
162168
{

commands/ProviderController.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
4+
namespace app\commands;
5+
6+
7+
use app\models\Address;
8+
use app\models\City;
9+
use Smoren\Yii2\QueryRelationManager\ActiveRecord\QueryRelationDataProvider;
10+
use Smoren\Yii2\QueryRelationManager\ActiveRecord\QueryRelationManager;
11+
use Smoren\Yii2\QueryRelationManager\Base\QueryRelationManagerException;
12+
use Yii;
13+
use yii\console\Controller;
14+
15+
/**
16+
* Контроллер для демонстрации работы QueryRelationManager с использованием DataProvider
17+
* @package app\commands
18+
* @author Smoren <ofigate@gmail.com>
19+
*/
20+
class ProviderController extends Controller
21+
{
22+
/**
23+
* Выбираем города с адресами, используем DataProvider для постраничной навигации
24+
* @throws QueryRelationManagerException
25+
*/
26+
public function actionCity()
27+
{
28+
$qrm = QueryRelationManager::select(City::class, 'c')
29+
->withMultiple('addresses', Address::class, 'a', 'c', ['city_id' => 'id']);
30+
31+
$dataProvider = new QueryRelationDataProvider([
32+
'queryRelationManager' => $qrm,
33+
'db' => Yii::$app->db,
34+
'pagination' => [
35+
'pageSize' => 2,
36+
'page' => 0,
37+
],
38+
]);
39+
40+
print_r($dataProvider->getModels());
41+
}
42+
}

0 commit comments

Comments
 (0)