2017 © Pedro Peláez
 

library bulk-inserter

image

nomensa/bulk-inserter

  • Monday, April 9, 2018
  • by nomensa
  • Repository
  • 3 Watchers
  • 0 Stars
  • 267 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1680 % Grown

The README.md

Bulk Inserter

Note: This helper library is currently specific to the Laravel framework running with a MySQL database., (*1)

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., (*2)

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

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!, (*4)

Install

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

Note: Please install as a dev requirement only., (*5)

Example

The following example will insert a thousand users in a couple of seconds:, (*6)

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., (*7)

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., (*8)

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., (*9)

This package is for use during development and testing, not everyday application logic., (*10)

The Versions

09/04 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php >=7.1.3

 

The Development Requires

06/04 2018

v0.3.0

0.3.0.0

  Sources   Download

MIT

The Requires

  • php >=7.1.3

 

The Development Requires

06/04 2018

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

  • php >=7.1.3

 

The Development Requires

26/03 2018

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

  • php >=7.1.3

 

The Development Requires