robotusers/cakephp-chunk

Robotusers CakePHP Chunk plugin

Installs: 2 297

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 3

Open Issues: 0

Type:cakephp-plugin

0.3.0 2024-12-12 08:41 UTC

This package is auto-updated.

Last update: 2024-12-12 08:41:51 UTC


README

Software License Build Status codecov

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]);