robotusers / cakephp-chunk
Robotusers CakePHP Chunk plugin
Installs: 2 205
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 3
Open Issues: 1
Type:cakephp-plugin
Requires
- php: >=5.6
- cakephp/orm: ^3.4
Requires (Dev)
- cakephp/cakephp: ~3.4.0
- cakephp/cakephp-codesniffer: ^3.0
- phpunit/phpunit: ^5.6|^6
This package is auto-updated.
Last update: 2024-10-21 18:59:14 UTC
README
This plugin allows to chunk results retrieved from a database in order to save memory.
Installation
composer require robotusers/cakephp-chunk
bin/cake plugin load Robotusers/Chunk
Using the plugin
The plugin provides a custom ResultSet
class which accepts Cake\ORM\Query
instance.
Example:
$query = $table->find(); $results = new \Robotusers\Chunk\ORM\ResultSet($query); foreach ($results as $result) { // do stuff }
You can control how many elements are in one "chunk" (1000 by default):
$query = $table->find(); $results = new \Robotusers\Chunk\ORM\ResultSet($query, ['size' => 100]);
The plugin provides also a behavior with chunk()
method:
$table->addBehavior('Robotusers/Chunk.Chunk'); $query = $table->find(); $results = $table->chunk($query, ['size' => 100]);