PHPackages                             battlecook/datacooker - 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. battlecook/datacooker

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

battlecook/datacooker
=====================

It's project for different kinds of data store. It provides an interface by abstracting individual libraries (\\ pdo, \\ Redis, \\ Memcached, etc.) that access data stores.

616PHPCI failing

Since Feb 24Pushed 6y agoCompare

[ Source](https://github.com/battlecook/DataCooker)[ Packagist](https://packagist.org/packages/battlecook/datacooker)[ RSS](/packages/battlecook-datacooker/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

DataCooker
==========

[](#datacooker)

What is it ?
------------

[](#what-is-it-)

It's project for different kinds of data store.

It provides an interface by abstracting individual libraries (\\ pdo, \\ Redis, \\ Memcached, etc.) that access data stores.

Supported DataStore

Relation Database : Pdo-managed database

KeyValue Store : memcached, redis, apcu

Read this in other languages : [korean](README.ko.md)

How to install
--------------

[](#how-to-install)

```
composer require battlecook/datacooker:dev-master

```

How to use
----------

[](#how-to-use)

data base schema

```
create table Item
(
	id1 int auto_increment,
	id2 int not null,
	id3 int not null,
	attr1 int not null,
	attr2 int not null,
	attr3 int not null,
	constraint Item_pk
		primary key (id1)
);

```

class defined

```
final class Item
{
    /**
     * @dataCookerAutoIncrement
     * @dataCookerIdentifier
     */
    public $id1;

    /**
     * @dataCookerIdentifier
     */
    public $id2;

    /**
     * @dataCookerIdentifier
     */
    public $id3;

    /**
     * @dataCookerAttribute
     */
    public $attr1;

    /**
     * @dataCookerAttribute
     */
    public $attr2;

    /**
     * @dataCookerAttribute
     */
    public $attr3;
}
```

you can use as bellows.

annotation in class represent data attribute.

There are three attribution to represent.

- @dataCookerIdentifier : required. represent complex unique id (have to declare more than once.)
- @dataCookerAttribute : required. represent attribution (have to declare more than once.)
- @dataCookerAutoIncrement : optional. represent auto increment value.

DataStore provides six interface (get, search, set, add, remove, commit)

```
$store = new RelationDatabase([
            'store' => null,
            'hosts' => [
                [
                    'ip' => 'localhost',
                    'port' => 3306,
                    'dbname' => 'DataCooker',
                    'user' => 'root',
                    'password' => 'password'
                ]
            ]
        ]);

$object = new Item();
$object->id1 = 1;
$object->id2 = 1;
$object->id3 = 1;
$object->attr1 = 1;
$object->attr2 = 1;
$object->attr3 = 1;

$ret = $store->get($object);
$ret = $store->search($object): array;
$ret = $store->set($object);
$ret = $store->add($object);
$ret = $store->remove($object);
$ret = $store->commit($data = null);
```

complex DataStore example ( Memcached and RelationDatabase )

##### before

[](#before)

```
status in database

+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+

status in memcached

                        value

            id1        id2        id3   attribute
key => array(1 => array(1 => array(1 => array(1,1,1))))

```

##### progress

[](#progress)

```
$store =  new Memcached(['store' => new RelationDatabase(['store' => null,
                                                          'hosts' => [['ip' => 'localhost', 'port' => 3306, 'dbname' => 'DataCooker', 'user' => 'root', 'password' => 'password']]]),
                         'hosts' => [['ip' => 'localhost', 'port' => 11211]]])

$object = new Item();
$object->id1 = 1;
$object->id2 = 1;
$object->id3 = 2;
$object->attr1 = 1;
$object->attr2 = 1;
$object->attr3 = 1;

$ret = $store->add($object);
```

##### after

[](#after)

```
status in database

+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  2  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+

status in memcached

                        value

            id1        id2        id3   attribute
key => array(1 => array(1 => array(1 => array(1,1,1)
                                   2 => array(1,1,1))))

```

Buffered DataStore :

BufferedDataStore basically store in Php memory.

If you use multiple DataStore with BufferedDataStore, It is different to operate a little.

When BufferedDataStore operate function (get set add remove), The first time, it get data from another repository and load it into php memory.

After that, it only work in php Memory until called commit() function.

Therefore, if you want to be applied from another DataStore, you must call the commit function.

If you are using a BufferedDataStore and @dataCookerAutoIncrement is defined in your class,

The add function is performed first to get the autoIncrement value incremented.

If it is not defined, it is postprocessed like any other function.

When you use Buffered DataStore, you can perform like transaction with multiple data store.

##### before

[](#before-1)

```
before status in database

+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+

```

##### progress1

[](#progress1)

```
$store =  new Buffered(['store' => new RelationDatabase(['store' => null,
                        'hosts' => [['ip' => 'localhost', 'port' => 3306, 'dbname' => 'DataCooker', 'user' => 'root', 'password' => 'password']]]),
                         );
$object = new Item();
$object->id1 = 1;
$object->id2 = 1;
$object->id3 = 1;
$object->attr1 = 2;
$object->attr2 = 2;
$object->attr3 = 2;

$ret = $store->set($object);
```

##### after1

[](#after1)

```
after status in database

+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+

```

##### progress2

[](#progress2)

```
$store->commitAll();
```

##### after2

[](#after2)

```
after status in database

+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   2   |   2   |   2   |
+-----+-----+-----+-------+-------+-------+

```

License
-------

[](#license)

DataCooker is licensed under MIT

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e3d037e24a10d9c2648bb0ddde0fecc7640e97a3da4d5dfd293ea3a28421512?d=identicon)[battlecook](/maintainers/battlecook)

---

Top Contributors

[![battlecook](https://avatars.githubusercontent.com/u/9781396?v=4)](https://github.com/battlecook "battlecook (156 commits)")

### Embed Badge

![Health badge](/badges/battlecook-datacooker/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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