php-vivace/db

View on GitHub
docs/4.FETCHING.md

Summary

Maintainability
Test Coverage
## Fetching data from storage


__vivace\db\Storage::fetch()__ return a instance of object, which implements __vivace\db\Reader__ interface.
__vivace\db\Reader__ is iterable object with additional methods.
Below example demonstrate how work with __vivace\db\Reader__.
 
#### Fetch iterator for all rows
The iterator is useful in cases where it is expected to work with a large number of rows, 
because the iterator extracts the rows on request.
```php
 $iterator = $storage->fetch();
 foreach ($iterator as $row){
    // $row is assoc array
 }
```
#### Fetch iterator with condition
Below example demonstrated how to fetch data that are suitable for the condition.
```php
 $iterator = $storage->filter(['is_processed' => false])->fetch();
 foreach ($iterator as $row){
    // $row is assoc array
 }
```

### Fetch one row
```php
$row = $storage->fetch()->one();
```

### Fetch all rows
Fetching all rows in one array.
```php
$rows = $storage->fetch()->all();

```