Queue-SQL is a Laravel package that solves the problem of long-running mass database writes by splitting large UPDATE, DELETE, and INSERT statements into parallel queued jobs. It works by calculating the min/max primary key range, slicing it into chunks, and dispatching an Illuminate\Bus\Batch to process each slice independently. Key features include a query builder macro with a queue() method, safe SQL compilation to avoid closure serialization issues, flexible batch sizing via chunk or maxJobs, native Laravel Batch support with callbacks, Artisan CLI commands for monitoring and cancellation, and Horizon tagging. A dryRun() method previews the batching plan without dispatching. Compared to Laravel's built-in Prunable trait, Queue-SQL runs concurrently and supports arbitrary updates and bulk inserts. Requires PHP 8.1+, Laravel 10–13, and an integer primary key for range-based chunking.
Table of contents
# Queueing a Write Query# Previewing the Plan# Tracking a Batch from the CLI# Installation & Considerations94.3K Impressions3 Comments