rajbatch / batchquery
This will help user to execute the batch query in their laravel projects.
v1.0
2020-01-13 13:09 UTC
This package is auto-updated.
Last update: 2024-10-25 08:10:02 UTC
README
This will help user to execute the batch(bulk) query in their laravel projects.
- Easy to Install.
- Easy to execute.
- Consume very little space, so your project does not get heavy
1. Install
composer require rajbatch/batchquery
Batch(bulk) UPDATE*****
Important parameter needs to be set
1. $table = "your table name where update"; 2. $index = 'user_id'; // (NOTE: $index field must exist in the $data array. // $index performs like WHERE clause to identify // where needs to update the given value ) 3. $set = ['column1','column2]; // (column name to update) 4. $data = [ [ 'user_id'=>1, 'column1' =>'column1_value', 'column2' =>'column2_value' ], [ 'user_id'=>2, 'column1' =>'column1', 'column2' =>'column2_value' ], [ 'user_id'=>3, 'column1' =>'column1', 'column2' =>'column2_value' ], ];
2. Controller
use Rajbatch\Batchquery\Batchquery;
3. In Controller function
$batch = new Batchquery(); $table = "your table name where update"; $index = 'user_id'; $set = ['column1']; $data = [ [ 'user_id'=>1, 'column1' =>'column1_value', 'column2' =>'column2_value' ], [ 'user_id'=>2, 'column1' =>'column1', 'column2' =>'column2_value' ], [ 'user_id'=>3, 'column1' =>'column1', 'column2' =>'column2_value' ], ]; $response = $batch->batchUpdate($index,$table,$set,$data);
Batch(bulk) INSERT*****
Important parameter needs to be set
1. $table = "your table name where insert"; 2. $data = [ [ 'user_id'=>1, 'column1' =>'column1_value', 'column2' =>'column2_value' ], [ 'user_id'=>2, 'column1' =>'column1', 'column2' =>'column2_value' ], [ 'user_id'=>3, 'column1' =>'column1', 'column2' =>'column2_value' ], ];
2. Controller
use Rajbatch\Batchquery\Batchquery;
3. In Controller function
$batch = new Batchquery(); $table = "your table name where insert"; $data = [ [ 'user_id'=>1, 'column1' =>'column1_value', 'column2' =>'column2_value' ], [ 'user_id'=>2, 'column1' =>'column1', 'column2' =>'column2_value' ], [ 'user_id'=>3, 'column1' =>'column1', 'column2' =>'column2_value' ], ]; $response = $batch->batchInsert($table,$data);