-
Notifications
You must be signed in to change notification settings - Fork 15
/
Query.php
64 lines (58 loc) · 1.4 KB
/
Query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @copyright Copyright (c) 2017 Dmitry Bashkarev
* @license https://github.com/bashkarev/clickhouse/blob/master/LICENSE
* @link https://github.com/bashkarev/clickhouse#readme
*/
namespace bashkarev\clickhouse;
use Yii;
/**
* @author Dmitry Bashkarev <[email protected]>
*/
class Query extends \yii\db\Query
{
/**
* @inheritdoc
*/
public function each($batchSize = 100, $db = null)
{
if ($db === null) {
$db = Yii::$app->get('clickhouse');
}
foreach ($this->createCommand($db)->queryBatchInternal($batchSize) as $rows) {
foreach ($this->populate($rows) as $key => $model) {
yield $key => $model;
}
}
}
/**
* @inheritdoc
*/
public function createCommand($db = null)
{
if ($db === null) {
$db = Yii::$app->get('clickhouse');
}
return parent::createCommand($db);
}
/**
* @inheritdoc
*/
public function batch($batchSize = 100, $db = null)
{
if ($db === null) {
$db = Yii::$app->get('clickhouse');
}
foreach ($this->createCommand($db)->queryBatchInternal($batchSize) as $rows) {
yield $this->populate($rows);
}
}
/**
* @return $this
*/
public function onFinal()
{
$this->params(['_final' => true]);
return $this;
}
}