2017 © Pedro Peláez
 

library dynamodb-orm

A lightweight object-dynamodb mapper for PHP

image

kettle/dynamodb-orm

A lightweight object-dynamodb mapper for PHP

  • Thursday, May 24, 2018
  • by inouet
  • Repository
  • 0 Watchers
  • 39 Stars
  • 111,110 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 27 Forks
  • 4 Open issues
  • 20 Versions
  • 10 % Grown

The README.md

Kettle

Kettle is a lightweight object-dynamodb mapper for PHP. Kettle provides a simple interface to Amazon DynamoDB., (*1)

See Some Code

<?php
use Kettle\ORM;

$user = ORM::factory('User')->findOne(10);
$user->name = 'John';
$user->save();


$tweets = ORM::factory('Tweet')->where('user_id', 10)
                 ->findMany();

foreach ($tweets as $tweet) {
    echo $tweet->text . PHP_EOL;
}

1. Installation

Package is available on Packagist, you can install it using Composer., (*2)

$ cat <<EOF > composer.json
{
    "require": {
        "kettle/dynamodb-orm": "0.2.*"
    }
}
EOF

$ composer install

2. Configuration

<?php
use Kettle\ORM;

ORM::configure("key",    'AWS_KEY');
ORM::configure("secret", 'AWS_SECRET');
ORM::configure("region", 'AWS_REGION');

// In order to use DynamoDB Local, you need to set "base_url".
// ORM::configure("base_url", 'http://localhost:8000/');

If you are using multiple aws account, use as follows., (*3)

<?php
use Kettle\ORM;

ORM::configure("key",    'AWS_KEY',    'account-2');
ORM::configure("secret", 'AWS_SECRET', 'account-2');
ORM::configure("region", 'AWS_REGION', 'account-2');

$user = ORM::factory('User', 'account-2');

3. Create Model Class

<?php

class User extends ORM {
    protected $_table_name = 'user';
    protected $_hash_key   = 'user_id';
    protected $_schema = array(
      'user_id'    => 'N',  // user_id is number
      'name'       => 'S',  // name is string
      'age'        => 'N',
      'country'    => 'S',
     );
}


If you use a generator, you can also create an class as follows., (*4)

$ php bin/kettle-skeleton.php --table-name user --region ap-northeast-1 > User.php

Table must have been created in advance. Because this generator generates a class based on the information and data collected by the "describeTable" and "scan" operation., (*5)

4. Create

<?php

$user = ORM::factory('User')->create();
$user->user_id = 1;
$user->name    = 'John';
$user->age     = 20;
$user->save();

5. Retrieve

<?php

$user = ORM::factory('User')->findOne(1);
echo $user->name. PHP_EOL;

print_r($user->asArray());

6. Update

<?php

$user = ORM::factory('User')->findOne(1);
$user->age = 21;
$user->save();

7. Delete

<?php

$user = ORM::factory('User')->findOne(1);
$user->delete();

8. Find

<?php

$tweets = ORM::factory('Tweets')
        ->where('user_id', 1)
        ->where('timestamp', '>', 1397264554)
        ->findMany();

foreach ($tweets as $tweet) {
     echo $tweet->text . PHP_EOL;
}

9. Find first record

<?php

$tweet = ORM::factory('Tweets')
        ->where('user_id', 1)
        ->where('timestamp', '>', 1397264554)
        ->findFirst();

echo $tweet->text . PHP_EOL;

10. Find by Global Secondary Index

<?php

$users = ORM::factory('User')
        ->where('country', 'Japan')
        ->where('age', '>=', 20)
        ->index('country-age-index')  // specify index name
        ->findMany();

11. Query Filtering

<?php

$tweets = ORM::factory('Tweets')
          ->where('user_id', 1)
          ->filter('is_deleted', 0) // using filter
          ->findMany();

The Versions

24/05 2018

dev-master

9999999-dev http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

24/05 2018

dev-update-readme.md

dev-update-readme.md http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

24/05 2018

dev-support-php7

dev-support-php7 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

02/01 2016

v0.2.8

0.2.8.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

02/01 2016

v0.2.7

0.2.7.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

02/01 2016

v0.2.6

0.2.6.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

16/12 2015

v0.2.5

0.2.5.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

16/12 2015

v0.2.4

0.2.4.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

03/12 2015

v0.2.3

0.2.3.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

30/11 2015

v0.2.2

0.2.2.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

25/09 2015

v0.2.1

0.2.1.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

24/09 2015

dev-feature/support-multi-account

dev-feature/support-multi-account http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

23/06 2015

dev-support-aws-sdk-3

dev-support-aws-sdk-3 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

23/06 2015

v0.2.0

0.2.0.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

21/05 2015

v0.1.4

0.1.4.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

21/03 2015

v0.1.3

0.1.3.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

20/12 2014

dev-feature/batch_get_item

dev-feature/batch_get_item http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

20/12 2014

v0.1.2

0.1.2.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

25/04 2014

v0.1.1

0.1.1.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle

14/04 2014

v0.1.0

0.1.0.0 http://github.com/inouet/

A lightweight object-dynamodb mapper for PHP5

  Sources   Download

MIT

The Requires

 

The Development Requires

orm aws dynamodb kettle