GithubHelp home page GithubHelp logo

battlecook / datacooker Goto Github PK

View Code? Open in Web Editor NEW
6.0 0.0 0.0 387 KB

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

PHP 99.40% TSQL 0.60%

datacooker's Introduction

DataCooker

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

How to install

composer require battlecook/datacooker:dev-master

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
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
$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
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 status in database
  
+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+
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
after status in database
  
+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   1   |   1   |   1   |
+-----+-----+-----+-------+-------+-------+
progress2
$store->commitAll();
after2
after status in database
  
+-----+-----+-----+-------+-------+-------+
| id1 | id2 | id3 | attr1 | attr2 | attr3 |
+-----+-----+-----+-------+-------+-------+
|  1  |  1  |  1  |   2   |   2   |   2   |
+-----+-----+-----+-------+-------+-------+

License

DataCooker is licensed under MIT

datacooker's People

Contributors

battlecook avatar

Stargazers

kimmayer avatar Chun-Sheng, Li avatar  avatar 최진우 avatar Jeong Kwang-Ho avatar HeungYeol Kim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.