File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff line change 1
- # cakephp-chunk
1
+ # CakePHP Chunk plugin
2
+
3
+ [ ![ Software License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg )] ( LICENSE )
4
+ [ ![ Build Status] ( https://travis-ci.org/robotusers/cakephp-chunk.svg?branch=master )] ( https://travis-ci.org/robotusers/cakephp-chunk )
5
+ [ ![ codecov] ( https://codecov.io/gh/robotusers/cakephp-chunk/branch/master/graph/badge.svg )] ( https://codecov.io/gh/robotusers/cakephp-chunk )
6
+
7
+ This plugin allows to chunk results retrieved from a database in order to save memory.
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ composer require robotusers/cakephp-chunk
13
+ bin/cake plugin load Robotusers/Chunk
14
+ ```
15
+
16
+ ## Using the plugin
17
+
18
+ The plugin provides a custom ` ResultSet ` class which accepts ` Cake\ORM\Query ` instance.
19
+
20
+ Example:
21
+ ``` php
22
+ $query = $table->find();
23
+ $results = new \Robotusers\Chunk\Model\ResultSet($query);
24
+
25
+ foreach ($results as $result) {
26
+ // do stuff
27
+ }
28
+ ```
29
+
30
+ You can control how many elements are in one "chunk" (1000 by default):
31
+
32
+ ``` php
33
+ $query = $table->find();
34
+ $results = new \Robotusers\Chunk\Model\ResultSet($query, ['size' => 100]);
35
+ ```
36
+
37
+ The plugin provides also a behavior with ` chunk() ` method:
38
+
39
+ ``` php
40
+ $table->addBehavior('Robotusers/Chunk.Chunk');
41
+ $query = $table->find();
42
+ $results = $table->chunk($query, ['size' => 100]);
43
+ ```
You can’t perform that action at this time.
0 commit comments