Skip to content

Laravel Batch v3.1.0

Choose a tag to compare

@mavinoo mavinoo released this 04 Oct 17:41
· 16 commits to master since this release
03bb548

New ways to write batches, a preview mode, and much faster large updates. Everything is
additive, so upgrading from 3.0 needs no code changes:

composer update mavinoo/laravel-batch

Added

  • updateByKeys(): update rows matched on any number of key columns.
  • insertRows(): insert rows given as column => value pairs.
  • upsert(): insert or update in one query, with timestamps (created_at only on new
    rows), enums, and large batches split automatically in one transaction.
  • deleteByKeys(): delete rows matched on one or more key columns. Models using
    SoftDeletes are soft deleted unless $force is true.
  • pretend(): see the SQL and bindings a call would run, without running it or
    connecting to the database.
  • Static HasBatch methods for every operation: batchUpdateMultipleCondition(),
    batchUpdateWithTwoIndex(), batchUpdateByKeys(), batchInsertRows(),
    batchUpsert(), batchDeleteByKeys().

Faster updates

Each UPDATE ... CASE statement now holds at most 100 rows. The database checks every
row against the CASE branches one by one, so large statements slowed down quickly.

Updating 50,000 rows 3.0.0 3.1.0
MySQL 8.4 30.5 s 3.1 s
MariaDB 10.11 25.3 s 2.4 s
PostgreSQL 16 over 15 min 2.5 s
SQLite 3.45 3.7 s 3.4 s

Deprecated

  • The instance method (new Model)->updateMultipleCondition(); use the static
    Model::batchUpdateMultipleCondition(). It will be removed in 4.0.

Also

  • Clearer InvalidArgumentExceptions for rows that aren't arrays, non-string column
    names and invalid arithmetic operators.
  • PHPStan level 9 with Larastan now runs in CI.

Full changelog: https://github.com/mavinoo/laravelBatch/blob/v3.1.0/CHANGELOG.md
Pull request: #125