承接 quangpv/fast-bulk-update 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

quangpv/fast-bulk-update

最新稳定版本:v1.0.1

Composer 安装命令:

composer require quangpv/fast-bulk-update

包简介

fast bulk update in laravel

README 文档

README

This package currently supports bulk updates in MySQL, MariaDB, and PostgreSQL, and it is compatible with Laravel version 8 and above


✔️ supports MySql
✔️ supports MariaDB
✔️ supports PostgreSQL

Laravel fast bulk update

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Install

composer require quangpv/fast-bulk-update

Example Usage

use App\Models\User;

$model = App::make(User::class);

// If you wish to modify the database connection, you can set it on your model.
$model->setConnection('mariadb');
$model->setConnection('mysql');
$model->setConnection('pgsql');

$values = [
     [
         'id' => 1,
         'code' => 'UC01',
         'nickname' => 'quangpv'
     ] ,
     [
         'id' => 2,
         'code' => 'UC02',
         'nickname' => 'haiza'
     ] ,
];

// We will find the records by their IDs and update them.
$indexes = ['id']; // primary key
// $indexes = ['code', 'id']; // composite primary key

$updateFields = ['nickname']; // only update the field `nickname`
// $updateFields = []; // update all fields

$affectedRows = \BatchUpdate::execute($model, $values, $indexes, $updateFields);

Warning

Ensure that the indexes match the primary key in your table, because the MySQL database driver always uses the "primary" and "unique" indexes of the table to detect existing records.

Other option


If you wanna update on fields that are not primary or unique indexes, you can refer to my approach here
https://github.com/quanggpv/laravel-upsert-improved.

My idea


The basic update queries will use the 'INSERT...ON DUPLICATE KEY UPDATE...' statement in MYSQL.

I took inspiration from Laravel's 'upsert' function, but removed the 'insert' functionality. I believe the built-in function of MySQL has an excellent data structure for updating


Important

If this package has been helpful to you, please give me a star. Thank you! :D

References


https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

https://laravel.com/docs/10.x/eloquent#upserts

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固