do6po/laravel-cursor-chunk

通过游标功能轻松从数据库中获取分块数据。

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

This package is auto-updated.

Last update: 2024-09-30 01:41:04 UTC


README

通过游标功能轻松从数据库中获取分块数据。

安装

该包可以通过 composer 安装。

composer require do6po/laravel-cursor-chunk

如果您使用的是 Laravel 版本 <= 5.4 或者禁用了 包发现,请在 config/app.php 中添加以下提供者:

'providers' => [
    Do6po\LaravelCursorChunk\Providers\CursorChunkServiceProvider::class,
]

使用

    $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 
    }

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件