PHPackages                             waad/truffle - 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. waad/truffle

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

waad/truffle
============

Laravel package for in-memory driver database Eloquent model connections

v1.3.0(3mo ago)45290MITPHPPHP &gt;=7.4CI passing

Since Aug 5Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/waadmawlood/truffle)[ Packagist](https://packagist.org/packages/waad/truffle)[ RSS](/packages/waad-truffle/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (11)Versions (8)Used By (0)

[![Laravel Truffle](truffle.jpg)](truffle.jpg)

Waad/Truffle
============

[](#waadtruffle)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6945d0cb2065294272a492a3a2760d10728bce275b0137cd1a9d57bacbcbe385/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776161642f74727566666c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/waad/truffle)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2edc8c246ebb8b85b28ae86a4bc7c37cbb47d185aeb33d9dc8b271cd2334feb6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f776161642f74727566666c652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/waad/truffle/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/2719370f1b323c21593039ff7c3895681b99e32c0da1a9b44e9c39391375b543/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776161642f74727566666c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/waad/truffle)

Eloquent models backed by in-memory SQLite. Perfect for static data, reference tables, and config that doesn't belong in your database.

**Zero config** • **Full Eloquent API** • **CSV / JSON / XML support** • **Per-model caching** • **Optional file-based SQLite**

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

[](#installation)

```
composer require waad/truffle
```

Quick Start
-----------

[](#quick-start)

```
use Illuminate\Database\Eloquent\Model;
use Waad\Truffle\Truffle;

class Product extends Model
{
    use Truffle;

    protected $fillable = ['name', 'price', 'category'];
    protected $casts = ['price' => 'float'];

    protected $records = [
        ['id' => 1, 'name' => 'Laptop', 'price' => 999.99, 'category' => 'Electronics'],
        ['id' => 2, 'name' => 'Coffee Mug', 'price' => 12.50, 'category' => 'Kitchen'],
    ];
}

Product::all();
Product::where('category', 'Electronics')->first();
Product::avg('price');
```

Schema
------

[](#schema)

Define column types explicitly with `DataType`. If omitted, types are inferred from your data.

```
use Waad\Truffle\Enums\DataType;

protected $schema = [
    'id'    => DataType::Id,
    'name'  => DataType::String,
    'price' => DataType::Decimal,
    'active'=> DataType::Boolean,
];
```

All DataType valuesDataTypeDB Type`Id`INTEGER (PK, auto-increment)`String`VARCHAR(255)`Text`TEXT`Integer`INTEGER`BigInteger`BIGINT`UnsignedBigInteger`UNSIGNED BIGINT`Float`FLOAT`Double`DOUBLE`Decimal`DECIMAL`Boolean`BOOLEAN`Json` / `Jsonb`TEXT`Date`DATE`DateTime`DATETIME`Time`TIME`Timestamp`TIMESTAMP`Uuid`CHAR(36)`Ulid`CHAR(26)Dynamic Records
---------------

[](#dynamic-records)

Override `getRecords()` to generate data at runtime:

```
public function getRecords(): array
{
    return collect(range(1, 100))->map(fn ($i) => [
        'id' => $i,
        'name' => "User {$i}",
    ])->toArray();
}
```

File-Based Records
------------------

[](#file-based-records)

Load records from CSV, JSON, or XML files. Format is auto-detected from the extension.

```
// Via property (auto-detected)
protected $truffleFile = __DIR__ . '/../data/countries.csv';

// Or via getRecords()
public function getRecords(): array
{
    return $this->fromCsvFile(__DIR__ . '/../data/countries.csv');
    // return $this->fromJsonFile(__DIR__ . '/../data/products.json');
    // return $this->fromXmlFile(__DIR__ . '/../data/categories.xml', 'category');
}
```

CSV custom delimiters are supported via `$truffleFileDelimiter`, `$truffleFileEnclosure`, and `$truffleFileEscape` properties.

> See full examples: [`CsvModel.php`](examples/CsvModel.php), [`JsonModel.php`](examples/JsonModel.php), [`XmlModel.php`](examples/XmlModel.php)

Caching
-------

[](#caching)

Enable per-model caching to avoid rebuilding the SQLite table on every request:

```
protected $truffleCache = true;
protected $truffleCacheTtl = 3600;        // seconds (null = forever)
// protected $truffleCacheDriver = 'redis';
// protected $truffleCachePrefix = 'app_';
```

```
Model::clearTruffleCache();    // clear cached records
Model::refreshTruffleCache();  // clear + rebuild
```

> See full example: [`CachedModel.php`](examples/CachedModel.php)

SQLite File Storage
-------------------

[](#sqlite-file-storage)

Persist to a SQLite file instead of in-memory. Ideal for large datasets:

```
protected static $truffleSqliteFile = '/path/to/database.sqlite';
```

```
Model::deleteTruffleSqliteFile();    // delete the file
Model::refreshTruffleSqliteFile();   // delete + rebuild
```

> See full example: [`SqliteFileModel.php`](examples/SqliteFileModel.php)

Performance Tuning
------------------

[](#performance-tuning)

```
protected $insertChunkRecords = 500;       // batch insert size
protected $foreignKeyConstraints = true;   // enable FK constraints

protected function thenMigration(Blueprint $table)
{
    $table->index('name');
}
```

Validation
----------

[](#validation)

Works with Laravel's `exists` rule:

```
'category_id' => ['required', Rule::exists(Category::class, 'id')],
```

Examples
--------

[](#examples)

See the [`examples/`](examples/) directory for complete, runnable models:

ExampleDescription[`BasicModel.php`](examples/BasicModel.php)Inline records with scopes[`CountryModel.php`](examples/CountryModel.php)Non-incrementing string primary key[`DynamicRecordsModel.php`](examples/DynamicRecordsModel.php)Generated records via `getRecords()`[`CachedModel.php`](examples/CachedModel.php)Caching with TTL and custom driver[`SqliteFileModel.php`](examples/SqliteFileModel.php)File-based SQLite persistence[`CsvModel.php`](examples/CsvModel.php)Load data from CSV[`JsonModel.php`](examples/JsonModel.php)Load data from JSON[`XmlModel.php`](examples/XmlModel.php)Load data from XML[`TruffleExample.php`](examples/TruffleExample.php)Full-featured model with all optionsTesting
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Add tests and make your changes
4. Run tests: `composer test`
5. Submit a Pull Request

Roadmap
-------

[](#roadmap)

- Eloquent integration
- SQLite in-memory support
- SQLite file support
- Caching support
- Support for CSV/JSON/XML files
- Multi-tenancy support

Credits
-------

[](#credits)

Built with love for the Laravel community by [Waad Mawlood](https://github.com/waadmawlood)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance81

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

Every ~38 days

Recently: every ~0 days

Total

7

Last Release

99d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44348636?v=4)[Waad Mawlood](/maintainers/waadmawlood)[@waadmawlood](https://github.com/waadmawlood)

---

Top Contributors

[![waadmawlood](https://avatars.githubusercontent.com/u/44348636?v=4)](https://github.com/waadmawlood "waadmawlood (22 commits)")

---

Tags

drivereloquentlaravelmemorymissing-drivermodelstatic-data

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/waad-truffle/health.svg)

```
[![Health](https://phpackages.com/badges/waad-truffle/health.svg)](https://phpackages.com/packages/waad-truffle)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

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