PHPackages                             tobento/service-database-storage - 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. tobento/service-database-storage

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

tobento/service-database-storage
================================

Database implementation for storages.

2.0.1(5mo ago)0160↓50%2MITPHPPHP &gt;=8.4

Since Mar 6Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/service-database-storage)[ Packagist](https://packagist.org/packages/tobento/service-database-storage)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-service-database-storage/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (7)Used By (2)

Database Storage Service
========================

[](#database-storage-service)

Database implementation for storages.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting started](#getting-started)
    - [Requirements](#requirements)
    - [Highlights](#highlights)
- [Documentation](#documentation)
    - [Storage Database](#storage-database)
    - [Storage Database Factory](#storage-database)
    - [Storage Database Processor](#storage-database-processor)
- [Credits](#credits)

---

Getting started
===============

[](#getting-started)

Add the latest version of the database storage service running this command.

```
composer require tobento/service-database-storage

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Highlights
----------

[](#highlights)

- Framework-agnostic, will work with any project
- Decoupled design

Documentation
=============

[](#documentation)

Storage Database
----------------

[](#storage-database)

```
use Tobento\Service\Database\DatabaseInterface;
use Tobento\Service\Database\Storage\StorageDatabaseInterface;
use Tobento\Service\Database\Storage\StorageDatabase;
use Tobento\Service\Storage\StorageInterface;
use Tobento\Service\Storage\InMemoryStorage;

$database = new StorageDatabase(
    storage: new InMemoryStorage([]),
    name: 'inmemory',
);

var_dump($database instanceof DatabaseInterface);
// bool(true)

var_dump($database instanceof StorageDatabaseInterface);
// bool(true)

var_dump($database->storage() instanceof StorageInterface);
// bool(true)
```

Check out the [Database Service](https://github.com/tobento-ch/service-database) to learn more about it.

Check out the [Storage Service](https://github.com/tobento-ch/service-storage) to learn more about it.

Storage Database Factory
------------------------

[](#storage-database-factory)

```
use Tobento\Service\Database\DatabaseFactoryInterface;
use Tobento\Service\Database\DatabaseInterface;
use Tobento\Service\Database\Databases;
use Tobento\Service\Database\Storage\StorageDatabaseFactory;
use Tobento\Service\Database\Storage\StorageDatabaseInterface;
use Tobento\Service\Storage\StorageInterface;
use Tobento\Service\Storage\JsonFileStorage;

$factory = new StorageDatabaseFactory(
    databases: new Databases(),
);

var_dump($factory instanceof DatabaseFactoryInterface);
// bool(true)

// create json file storage:
$database = $factory->createDatabase(
    name: 'file',
    config: [
        'storage' => JsonFileStorage::class,
        'dir' => __DIR__.'/json-file/',
    ],
);

var_dump($database instanceof DatabaseInterface);
// bool(true)

var_dump($database instanceof StorageDatabaseInterface);
// bool(true)

var_dump($database->storage() instanceof StorageInterface);
// bool(true)
```

**PdoMySqlStorage or PdoMariaDbStorage**

```
use Tobento\Service\Database\DatabaseInterface;
use Tobento\Service\Database\Databases;
use Tobento\Service\Database\PdoDatabase;
use Tobento\Service\Database\PdoDatabaseInterface;
use Tobento\Service\Database\Storage\StorageDatabaseFactory;
use Tobento\Service\Storage\PdoMySqlStorage;
use Tobento\Service\Storage\PdoMariaDbStorage;

$factory = new StorageDatabaseFactory(
    databases: new Databases(
        new PdoDatabase(
            pdo: new \PDO('sqlite::memory:'),
            name: 'mysql'
        ),
    ),
);

$database = $factory->createDatabase(
    name: 'storage',
    config: [
        'storage' => PdoMySqlStorage::class,
        //'storage' => PdoMariaDbStorage::class,

        // must be a PdoDatabaseInterface database with mysql driver
        'database' => 'mysql',
    ],
);

// Will throw an exception as
// PdoMySqlStorage::class only supports mysql driver
```

**PdoSqliteStorage**

```
use Tobento\Service\Database\DatabaseInterface;
use Tobento\Service\Database\Databases;
use Tobento\Service\Database\PdoDatabase;
use Tobento\Service\Database\PdoDatabaseInterface;
use Tobento\Service\Database\Storage\StorageDatabaseFactory;
use Tobento\Service\Storage\PdoSqliteStorage;

$factory = new StorageDatabaseFactory(
    databases: new Databases(
        new PdoDatabase(
            pdo: new \PDO('sqlite::memory:'),
            name: 'sqlite'
        ),
    ),
);

$database = $factory->createDatabase(
    name: 'storage',
    config: [
        'storage' => PdoSqliteStorage::class,
        'database' => 'sqlite',
    ],
);
```

**InMemoryStorage**

```
use Tobento\Service\Database\DatabaseInterface;
use Tobento\Service\Database\Databases;
use Tobento\Service\Database\Storage\StorageDatabaseFactory;
use Tobento\Service\Storage\InMemoryStorage;

$factory = new StorageDatabaseFactory(
    databases: new Databases(),
);

$database = $factory->createDatabase(
    name: 'inmemory',
    config: [
        'storage' => InMemoryStorage::class,
    ],
);

var_dump($database instanceof DatabaseInterface);
// bool(true)
```

Storage Database Processor
--------------------------

[](#storage-database-processor)

```
use Tobento\Service\Database\Processor\ProcessorInterface;
use Tobento\Service\Database\Storage\StorageDatabase;
use Tobento\Service\Database\Storage\StorageDatabaseProcessor;
use Tobento\Service\Database\Schema\Table;
use Tobento\Service\Storage\InMemoryStorage;
use Tobento\Service\Storage\Tables\Tables;

// Create table to be processed:
$table = new Table(name: 'users');
$table->primary('id');
$table->string('name');
$table->items(iterable: [
    ['name' => 'John'],
    ['name' => 'Mia'],
]);

// Create the database to be processed on:
$database = new StorageDatabase(
    storage: new InMemoryStorage(
        items: [],
        tables: (new Tables())->add('users', ['id', 'name'], 'id'),
    )
);

// Create the database processor supporting storages:
$processor = new StorageDatabaseProcessor();

var_dump($processor instanceof ProcessorInterface);
// bool(true)

// Process:
$processor->process(table: $table, database: $database);

// The items were successfully inserted
// into the storage by the processor:
$names = $database->storage()->table('users')->column('name')->all();
var_dump($names);
// { [0]=> string(4) "John" [1]=> string(3) "Mia" }
```

You may check out the [Database Service - Processors](https://github.com/tobento-ch/service-database#processors) to learn more about database processors in general.

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance70

Regular maintenance activity

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~166 days

Recently: every ~142 days

Total

7

Last Release

171d ago

Major Versions

1.x-dev → 2.02025-09-26

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (12 commits)")

---

Tags

packagedatabasestoragetobento

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-service-database-storage/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-service-database-storage/health.svg)](https://phpackages.com/packages/tobento-service-database-storage)
```

###  Alternatives

[awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

10923.2k](/packages/awssat-laravel-sync-migration)[nitecon/zf2-db-session

Zend Framework 2 database session storage

204.8k](/packages/nitecon-zf2-db-session)

PHPackages © 2026

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