Skip to content

Laravel Batch v3.0.0

Choose a tag to compare

@mavinoo mavinoo released this 04 Oct 14:42
· 19 commits to master since this release
f09be0b

A major release that rewrites how queries are built. Every 2.x user should upgrade:
all 2.x versions build SQL by escaping values by hand, which allows SQL injection
(always on PostgreSQL, and through index values and JSON keys on every database).
3.0 sends every value as a bound parameter and lets Laravel's grammar quote every
column and table name.

composer require "mavinoo/laravel-batch:^3.0"

Requires PHP 8.1+ and Laravel 10 – 13. Upgrading from 2.x takes a few
minutes for most projects: see the upgrade guide.

Breaking changes

  • The $raw argument is removed. Wrap only the values that are SQL in DB::raw():
    ['id' => 1, 'score' => DB::raw('score * 2')]. Passing true for the old argument
    throws, so a missed call never stores SQL as text.
  • Update methods return int and insert() returns array. Empty input returns
    0 / zero counts instead of false.
  • Invalid input throws InvalidArgumentException before anything is written.
  • BatchInterface and Batch declare return types.
  • Mavinoo\Batch\Common\Common and the global str() helper are removed.

Added

  • Laravel 13 support.
  • DB::raw() in values, index values and conditions.
  • Enum values in every method.
  • Batches over the database's bound parameter limit are split automatically and
    run in one transaction on the model's connection.
  • A test suite (composer test) and GitHub Actions on PHP 8.1 – 8.5,
    Laravel 10 – 13, MySQL, MariaDB, PostgreSQL and SQLite.

Fixed

  • Quotes, backslashes, JSON, leading zeros and booleans are stored exactly as
    given (#66, #68, #70, #73, #76, #96, #101).
  • Every method works on PostgreSQL and SQLite (#116).
  • updateMultipleCondition() with string keys, on PostgreSQL, with null
    conditions, and when a condition column is updated in the same call on MySQL.
  • updated_at only changes for rows that change, on every database (#120).
  • Models with CREATED_AT or UPDATED_AT set to null (#107).
  • insert() rolls back on the model's own connection, and $insertIgnore works
    on PostgreSQL and SQLite.

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