定制 nomensa/bulk-inserter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nomensa/bulk-inserter

Composer 安装命令:

composer require nomensa/bulk-inserter

包简介

README 文档

README

Note: This helper library is currently specific to the Laravel framework running with a MySQL database.

If you are stress-testing your new application to see how it will behave with a realistic future amount of data then you are probably writing a seeder which inserts thousands of rows.

Using many individual queries in PHP to insert rows one-by-one may be slow and hampering development or even breaching prepared statement limits.

This package utilises MySQLs native dump import so you can prepare the data inside your loop and then plonk the whole lot in the database with 1 speedy operation which is way quicker than doing lots of individual inserts!

Install

$ composer require --dev -- nomensa/bulk-inserter

Note: Please install as a dev requirement only.

Example

The following example will insert a thousand users in a couple of seconds:

use Nomensa\BulkInserter\BulkInserter;

class ExampleSeeder
{

    public function run()
    {
        $bulkInserter = new BulkInserter('users',['name','email']);
        
        for ($i = 0; $i < 1000; $i++) {
            $bulkInserter->addRow( '("User ' . $i . '","user' . $i . '@example.com")' );
        }
        
        $bulkInserter->insert();
    }

}

If the above task was written using the Eloquent model's '::create()' method it could take ~20 seconds.

Multiply this delay across all your model's tables, factor in how many times you will tweak and re-run your seeder during test writing and the time savings add. Using this package makes for a much happier developer experience.

Friendly reminder about exposing vulnerabilities!

This package executes raw MySQL code in your database. DO NOT use this package in a production environment and certainly NEVER populate the content of the rows via inputs from a request.

This package is for use during development and testing, not everyday application logic.

统计信息

  • 总下载量: 1.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固