do6po / laravel-cursor-chunk
An easy way to get chunked data from database by cursor functional.
dev-main
2021-11-13 13:18 UTC
Requires
- php: ^7.4|^8.0
- illuminate/database: ^7|^8
- illuminate/support: ^7|^8
Requires (Dev)
- fakerphp/faker: ^1.9.1
- laravel/framework: ^7|^8
- mockery/mockery: ^1.0
- orchestra/testbench: ^4|^5
- phpunit/phpunit: ^8|^9
This package is auto-updated.
Last update: 2024-10-30 01:48:27 UTC
README
An easy way to get chunked data from database by cursor functional.
Installation
The package can be installed via composer:
composer require do6po/laravel-cursor-chunk
If you are using Laravel version <= 5.4
or the package discovery
is disabled, add the following providers in config/app.php
:
'providers' => [ Do6po\LaravelCursorChunk\Providers\CursorChunkServiceProvider::class, ]
Using
$builder = User::query(); //... some code with builder foreach ($builder->cursorChunk() as $users) { //some action with $users }
use Illuminate\Database\Eloquent\Collection; $builder = User::query(); //... some code with builder $action = fn(Collection $users, User $user) => $users->put($user->getKey(), $user); foreach ($builder->cursorChunk(1000, $action) as $users) { //some action with $users, chunked by 1000 models and key by id }
License
The MIT License (MIT). Please see License File for more information.