Interface Yiisoft\Db\Query\BatchQueryResultInterface
| Extends | Iterator |
|---|---|
| Implemented by | Yiisoft\Db\Query\BatchQueryResult |
This interface represents a batch query from which you can retrieve data in batches.
You usually don't instantiate BatchQueryResult directly.
Instead, you obtain it by calling {@see \Yiisoft\Db\Query\Query::batch()}.
Because BatchQueryResult implements the {@see \Iterator} interface, you can iterate it to obtain a batch of data in each iteration.
For example,
$query = (new Query)->from('user');
foreach ($query->batch() as $i => $users) {
// $users represents the rows in the $i-th batch
}
Public Methods
| Method | Description | Defined By |
|---|---|---|
| batchSize() | Yiisoft\Db\Query\BatchQueryResultInterface | |
| current() | Returns the current dataset. | Yiisoft\Db\Query\BatchQueryResultInterface |
| getBatchSize() | Yiisoft\Db\Query\BatchQueryResultInterface | |
| getQuery() | Yiisoft\Db\Query\BatchQueryResultInterface | |
| indexBy() | Yiisoft\Db\Query\BatchQueryResultInterface | |
| key() | Returns the index of the current dataset. | Yiisoft\Db\Query\BatchQueryResultInterface |
| next() | Moves the internal pointer to the next dataset. | Yiisoft\Db\Query\BatchQueryResultInterface |
| resultCallback() | Sets a callback function to be called for the result of the query. | Yiisoft\Db\Query\BatchQueryResultInterface |
| rewind() | Resets the iterator to the initial state. | Yiisoft\Db\Query\BatchQueryResultInterface |
| valid() | Returns whether there is a valid dataset at the current position. | Yiisoft\Db\Query\BatchQueryResultInterface |
Method Details
| public abstract Yiisoft\Db\Query\BatchQueryResultInterface batchSize ( integer $value ) | ||
| $value | integer |
The number of rows to return in each batch. |
public function batchSize(int $value): static;
Returns the current dataset.
This method is required by the interface {@see \Iterator}.
| public abstract array current ( ) | ||
| return | array |
The current dataset. |
|---|---|---|
public function current(): array;
| public abstract Yiisoft\Db\Query\QueryInterface getQuery ( ) |
public function getQuery(): QueryInterface;
| public abstract Yiisoft\Db\Query\BatchQueryResultInterface indexBy ( Closure|string|null $indexBy ) | ||
| $indexBy | Closure|string|null | |
public function indexBy(Closure|string|null $indexBy): static;
Returns the index of the current dataset.
This method is required by the interface {@see \Iterator}.
| public abstract integer key ( ) | ||
| return | integer |
The index of the current row. |
|---|---|---|
public function key(): int;
Moves the internal pointer to the next dataset.
This method is required by the interface {@see \Iterator}.
| public abstract void next ( ) | ||
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function next(): void;
Sets a callback function to be called for the result of the query.
| public abstract Yiisoft\Db\Query\BatchQueryResultInterface resultCallback ( Closure|null $callback ) | ||
| $callback | Closure|null | |
public function resultCallback(?Closure $callback): static;
Resets the iterator to the initial state.
This method is required by the interface {@see \Iterator}.
| public abstract void rewind ( ) | ||
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Throwable | |
public function rewind(): void;
Signup or Login in order to comment.