chojnicki/laravel-seeder-extended
Composer 安装命令:
composer require chojnicki/laravel-seeder-extended
包简介
Extend functionality of Seeder with helpful methods and debug info.
README 文档
README
Extend default Seeder with extra funcionality.
NOTE: This library mixes my laravel-seeder-debugger with extra methods. If you do not wanna use any methods listed below and just need debugger, you can just use chojnicki/laravel-seeder-debugger instead.
Requirements
- Laravel / Lumen 5.5 or higher (written on 5.8, not tested on lower than 5.5 but should work on 5.*)
Instalation with Composer
composer require chojnicki/laravel-seeder-extended
Usage
In DatabaseSeeder.php simply replace:
use Illuminate\Database\Seeder;
with:
use Chojnicki\LaravelSeederExtended\Seeder;
Available methods
insertMultiple($collection, $chunkSize = 1000, $sorted = true)
If you use Factory to create for example 10,000 posts then saving them will cause 10,000 queries to database (what will be slow). You can insert multiple items to database with single query passing collection of models to insertMultiple().
Be default 1000 models will be inserted in single query. For models with long data you can decrease this, and for very small models increase. Try to find sweet spot that will be fastest for you ;)
Records will be inserted sorted from the oldest to newest. You can disable this at third parameter and use custom sorting instead.
$this->insertMultiple($posts);
setRandomDate($model, $max = 15552000)
Short way to generate random date (for created_at and updated_at at once) on model. De default range is 6 months and you can change this in second parameter (in seconds). Method will return Carbon date if you need to use it somewhere else.
$this->setRandomDate($post);
Any ideas for more? Feedback and pull requests are welcome :)
Debug
After finished seeding console will debug info like this:
Database seeding completed successfully.
Seeding execution time: 8.6s.
Database queries executed: 329.
Current RAM usage is 18.7MB with peak during execution 59.1MB.
Thanks to this info you can try to write more efficient seeders :)
More info -> chojnicki/laravel-seeder-debugger
Note
This debugger simply extends original Seeder library (it's not a fork) so all functionality is preserved and there should not be conflicts with already written seeders.
chojnicki/laravel-seeder-extended 适用场景与选型建议
chojnicki/laravel-seeder-extended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 144 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 chojnicki/laravel-seeder-extended 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chojnicki/laravel-seeder-extended 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 144
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-14