do6po/laravel-cursor-chunk

An easy way to get chunked data from database by cursor functional.

dev-main 2021-11-13 13:18 UTC

This package is auto-updated.

Last update: 2024-08-30 01:32:23 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.