rajbatch/batchquery

这将帮助用户在他们的Laravel项目中执行批量查询。

v1.0 2020-01-13 13:09 UTC

This package is auto-updated.

Last update: 2024-09-25 08:04:05 UTC


README

这将帮助用户在他们的Laravel项目中执行批量(批量)查询。

Latest Stable Version License Total Downloads Daily Downloads

  1. 安装简单。
  2. 执行简单。
  3. 占用空间非常小,因此您的项目不会变重

1. 安装

composer require rajbatch/batchquery

批量(批量)更新*****

需要设置重要参数

 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. 控制器

use Rajbatch\Batchquery\Batchquery;

3. 在控制器函数中

      $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);

批量(批量)插入*****

需要设置重要参数

 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. 控制器

use Rajbatch\Batchquery\Batchquery;

3. 在控制器函数中

      $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);