2017 © Pedro Peláez
 

library dynamodb

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

image

quankim/dynamodb

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

  • Wednesday, January 11, 2017
  • by quanvh
  • Repository
  • 0 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 48 Forks
  • 0 Open issues
  • 18 Versions
  • 20 % Grown

The README.md

laravel-dynamodb

Fork from https://github.com/baopham/laravel-dynamodb

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Supports all key types - primary hash key and composite keys., (*2)

For advanced users only. If you're not familiar with Laravel, Laravel Eloquent and DynamoDB, then I suggest that you get familiar with those first., (*3)

Breaking Changes for v0.4 * If you're using v0.3 and below, please see here * To upgrade to v0.4, please see the migration note, (*4)

Install

  • Composer install, (*5)

    composer require baopham/dynamodb
    
  • Install service provider:, (*6)

    // config/app.php
    
    'providers' => [
        ...
        BaoPham\DynamoDb\DynamoDbServiceProvider::class,
        ...
    ];
    
  • Put DynamoDb config in config/aws.php:, (*7)

    // config/aws.php
    ...
    'credentials' => [
        'key'    => env('AWS_ACCESS_KEY_ID', ''),
        'secret' => env('AWS_SECRET_ACCESS_KEY', ''),
    ],
    'region' => env('AWS_REGION', 'us-east-1'),
    'version' => 'latest',
    'endpoint' => env('AWS_ENDPOINT', ''),
    ...
    

Usage

  • Extends your model with BaoPham\DynamoDb\DynamoDbModel, then you can use Eloquent methods that are supported. The idea here is that you can switch back to Eloquent without changing your queries.

Supported methods:, (*8)

// find and delete
$model->find(<id>);
$model->delete();

// Using getIterator(). If 'key' is the primary key or a global/local index and the condition is EQ, will use 'Query', otherwise 'Scan'.
$model->where('key', 'key value')->get();

// See BaoPham\DynamoDb\ComparisonOperator
$model->where(['key' => 'key value']);
// Chainable for 'AND'. 'OR' is not supported.
$model->where('foo', 'bar')
    ->where('foo2', '!=' 'bar2')
    ->get();

// Using scan operator, not too reliable since DynamoDb will only give 1MB total of data.
$model->all();

// Basically a scan but with limit of 1 item.
$model->first();

// update
$model->update($attributes);

$model = new Model();
// Define fillable attributes in your Model class.
$model->fillableAttr1 = 'foo';
$model->fillableAttr2 = 'foo';
// DynamoDb doesn't support incremented Id, so you need to use UUID for the primary key.
$model->id = 'de305d54-75b4-431b-adb2-eb6b9e546014'
$model->save();

// chunk
$model->chunk(10, function ($records) {
    foreach ($records as $record) {

    }
});
  • Or if you want to sync your DB table with a DynamoDb table, use trait BaoPham\DynamoDb\ModelTrait, it will call a PutItem after the model is saved.

Indexes

If your table has indexes, make sure to declare them in your model class like so, (*9)

/**
 * Indexes.
 * [
 *     'simple_index_name' => [
 *          'hash' => 'index_key'
 *     ],
 *     'composite_index_name' => [
 *          'hash' => 'index_hash_key',
 *          'range' => 'index_range_key'
 *     ],
 * ].
 *
 * @var array
 */
protected $dynamoDbIndexKeys = [
    'count_index' => [
        'hash' => 'count'
    ],
];

Note that order of index matters when a key exists in multiple indexes.
For example, we have this, (*10)

$this->where('user_id', 123)->where('count', '>', 10)->get();

with, (*11)

protected $dynamoDbIndexKeys = [
    'count_index' => [
        'hash' => 'user_id',
        'range' => 'count'
    ],
    'user_index' => [
        'hash' => 'user_id',
    ],
];

will use count_index., (*12)

protected $dynamoDbIndexKeys = [
    'user_index' => [
        'hash' => 'user_id',
    ],
    'count_index' => [
        'hash' => 'user_id',
        'range' => 'count'
    ]
];

will use user_index., (*13)

Composite Keys

To use composite keys with your model:, (*14)

  • Set $compositeKey to an array of the attributes names comprising the key, e.g.
protected $primaryKey = ['customer_id'];
protected $compositeKey = ['customer_id', 'agent_id'];
  • To find a record with a composite key
$model->find(['id1' => 'value1', 'id2' => 'value2']);

Test

Run:, (*15)

$ java -Djava.library.path=./DynamoDBLocal_lib -jar dynamodb_local/DynamoDBLocal.jar --port 3000
$ ./vendor/bin/phpunit
  • DynamoDb local version: 2016-01-07_1.0, (*16)

  • DynamoDb local schema for tests created by the DynamoDb local shell is located here, (*17)

Requirements

Laravel ^5.1, (*18)

TODO

  • [ ] Upgrade a few legacy attributes: AttributesToGet, ScanFilter, ...

License

MIT, (*19)

Author and Contributors

The Versions

11/01 2017

dev-master

9999999-dev

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

11/01 2017

0.7

0.7.0.0

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

11/01 2017

0.79

0.79.0.0

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

11/01 2017

0.69

0.69.0.0

DynamoDb wrapper for your Laravel model and helpers => fork from https://github.com/baopham/laravel-dynamodb

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

26/12 2016

0.4.0

0.4.0.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

25/11 2016

dev-test-circleci

dev-test-circleci

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

24/11 2016

dev-test-travis

dev-test-travis

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

24/11 2016

0.3.2

0.3.2.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

28/09 2016

0.3.1

0.3.1.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

25/05 2016

0.3.0

0.3.0.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

06/05 2016

0.2.3

0.2.3.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

06/05 2016

dev-query-builder

dev-query-builder

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

09/04 2016

0.2.2

0.2.2.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

09/04 2016

0.2.1

0.2.1.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

27/02 2016

0.2.0

0.2.0.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

05/01 2016

0.1.2

0.1.2.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

22/11 2015

0.1.1

0.1.1.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel aws dynamodb

04/08 2015

0.1.0

0.1.0.0

DynamoDb wrapper for your Laravel model and helpers

  Sources   Download

MIT

The Requires

 

The Development Requires