PHPackages                             patrick-hanna/database-crud-buffer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. patrick-hanna/database-crud-buffer

ActiveLibrary[Database &amp; ORM](/categories/database)

patrick-hanna/database-crud-buffer
==================================

Buffer and batch Laravel database inserts, upserts, updates, and deletes into a minimal set of merged SQL statements.

v1.0.0(1mo ago)0188↓58.3%MITPHPPHP ^8.2

Since Jul 9Pushed 1mo agoCompare

[ Source](https://github.com/patrickjames242/database-crud-buffer)[ Packagist](https://packagist.org/packages/patrick-hanna/database-crud-buffer)[ RSS](/packages/patrick-hanna-database-crud-buffer/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Database CRUD Buffer
====================

[](#database-crud-buffer)

Buffer Laravel database writes — inserts, upserts, updates, and deletes — and flush them as a minimal set of merged SQL statements. Rows for the same table collapse into single multi-row statements, repeated writes to the same key merge, and compatible deletes fold into `where … in (…)` clauses.

Built on Laravel's query builder (`illuminate/database`) and the `DB` facade.

Installation
------------

[](#installation)

```
composer require patrick-hanna/database-crud-buffer
```

Requires PHP 8.2+ and Laravel 11 or 12. The [`php-ds`](https://www.php.net/manual/en/book.ds.php)polyfill is pulled in automatically; installing the `ds` PHP extension improves performance but is optional.

Usage
-----

[](#usage)

```
use PatrickHanna\DatabaseCrudBuffer\DatabaseCrudBuffer;

$buffer = new DatabaseCrudBuffer();

$buffer->insert('accounts', ['id' => '1', 'legal_name' => 'Acme']);
$buffer->insert(Account::class, ['id' => '2', 'legal_name' => 'Globex']);

$buffer->flush();
```

Every write target accepts either a literal table name or an Eloquent model class — the model's table name is resolved automatically.

By default the buffer auto-flushes once ~50,000 buffered items accumulate, inside a database transaction. Both are configurable:

```
$buffer = new DatabaseCrudBuffer(
    maxSize: 10000,        // null to disable auto-flush
    useTransaction: false, // flush without opening a transaction
);
```

### Insert

[](#insert)

```
$buffer->insert('accounts', ['id' => '1', 'name' => 'Acme']);
```

Rows are buffered per table and emitted as one multi-row insert at flush time. Column sets are normalized (missing columns become `null`) and rows that normalize to the same shape are deduplicated.

### Upsert

[](#upsert)

```
$buffer->upsert(
    tableOrModelClass: 'accounts',
    uniqueBy: ['id'],
    row: ['id' => '1', 'name' => 'New'],
    updateColumns: ['name'],          // optional; defaults to the buffered columns
    originalValues: ['id' => '1', 'name' => 'Old', 'email' => 'old@example.com'],
);
```

Writes bucket by table, unique key, and update-column list. Repeated writes to the same unique row merge before flush. `originalValues` supplies fallback data to build a complete insert row without widening the on-conflict update set.

### Update

[](#update)

```
$buffer->update('accounts', 'id', 'account-1', ['name' => 'Acme']);
$buffer->update('accounts', ['status', 'active'], ['email' => 'a@example.com']);
$buffer->update('accounts', [['status', 'active'], ['id', 'a']], ['name' => 'Acme']);
$buffer->update('accounts', ['id', 'in', ['a', 'b']], ['status' => 'active']);
```

Updates sharing a normalized filter set merge into a single statement, regardless of the order the filters were supplied.

### Delete

[](#delete)

```
$buffer->delete('accounts', 'id', 'account-1');
$buffer->delete('accounts', [['status', 'active'], ['id', 'a']]);
$buffer->delete('accounts', ['id', 'in', ['a', 'b']]);
```

Deletes that differ in exactly one `=`/`in` filter fold into a single `where … in (…)` statement at flush time.

### Flushing

[](#flushing)

```
$buffer->flush();                   // wraps the work in DB::transaction(...)
$buffer->flushWithoutTransaction(); // caller owns the transaction boundary
```

Flush order is always inserts → upserts → updates → deletes. On success the buffer is cleared and its size counter resets.

Testing
-------

[](#testing)

```
composer install
composer test
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

47d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34404152?v=4)[Patrick Hanna](/maintainers/patrickjames242)[@patrickjames242](https://github.com/patrickjames242)

---

Top Contributors

[![patrickjames242](https://avatars.githubusercontent.com/u/34404152?v=4)](https://github.com/patrickjames242 "patrickjames242 (1 commits)")

---

Tags

laraveldatabasebatchBufferinsertbulkupsert

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/patrick-hanna-database-crud-buffer/health.svg)

```
[![Health](https://phpackages.com/badges/patrick-hanna-database-crud-buffer/health.svg)](https://phpackages.com/packages/patrick-hanna-database-crud-buffer)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M113](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
