akunbeben/eloquent-file

Read SQL file fluently just like a real Database using Eloquent ORM or Query Builder

Maintainers

Package info

github.com/akunbeben/eloquent-file

pkg:composer/akunbeben/eloquent-file

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-07-24 03:58 UTC

This package is auto-updated.

Last update: 2026-07-24 05:39:36 UTC


README

Eloquent File

Packagist PHP from Packagist Laravel versions GitHub Workflow Status (main) Total Downloads

Query a MySQL or MariaDB SQL dump with Laravel's Query Builder and Eloquent, without restoring it to a database server. The dump is loaded into a read-only, in-memory SQLite connection.

Installation

You can install the package via Composer:

composer require akunbeben/eloquent-file

The PHP PDO SQLite extension must be enabled. Laravel discovers the package automatically.

Usage

Open a dump, then query it with the package facade:

use EloquentFile\EloquentFile\Facades\EloquentFile;

EloquentFile::open(storage_path('backups/backup.sql'));

$activeUsers = EloquentFile::table('users')
    ->where('status', 'Active')
    ->orderBy('name')
    ->get();

The loaded connection is registered as eloquent-file, so it can be used by an Eloquent model:

use Illuminate\Database\Eloquent\Model;

class ArchivedUser extends Model
{
    protected $connection = 'eloquent-file';

    protected $table = 'users';
}

EloquentFile::open(storage_path('backups/backup.sql'));

$user = ArchivedUser::find(1);

For dependency injection, use the underlying service directly. A custom connection name may be passed as the second argument:

use EloquentFile\EloquentFile\EloquentFile;

$dump = app(EloquentFile::class)->open(
    storage_path('backups/backup.sql'),
    'archive',
);

$total = $dump->table('invoices')->sum('total');

Write operations throw an Illuminate\Database\QueryException. Opening another dump with the same connection name replaces the previous in-memory connection.

Supported Dumps

The reader supports standard MySQL and MariaDB table dumps containing backtick-quoted CREATE TABLE and INSERT INTO ... VALUES statements, including extended inserts and MySQL string escapes. Input is streamed while the resulting database is held in memory.

MySQL-specific indexes, constraints, generated expressions, procedures, triggers, and views are not recreated. Queries use SQLite semantics, so raw MySQL-only SQL is not portable. Read-only mode prevents application writes; it is not a security sandbox for untrusted PHP code.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Eloquent File! Please review our contributing guide to get started.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Eloquent File is open-sourced software licensed under the MIT license.