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

0.1.2 2020-08-21 06:52 UTC

This package is auto-updated.

Last update: 2024-10-21 18:59:14 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]);