PHP code example of revenuewire / dynamodb-orm

1. Go to this page and download the library: Download revenuewire/dynamodb-orm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

revenuewire / dynamodb-orm example snippets



if (APPLICATION_ENV == "local" || APPLICATION_ENV == "qa") {
    Model::configure(["region" => NETWORK_REGION, "endpoint" => 'http://dynamodb:8000']);
} else {
   Model::configure(["region" => NETWORK_REGION]);
}


use RW\DynamoDb\Model;

class User extends Model
{
    public static $tableName = 'user';
    /**
     * DynamoDB Schema Definition
     */
    public static $schema = [
        "TableName" => "user",
        "AttributeDefinitions" => [
            [
                'AttributeName' => 'id',
                'AttributeType' => 'S',
            ]
        ],
        'KeySchema' => [
            [
                'AttributeName' => 'id',
                'KeyType' => 'HASH',
            ]
        ],
        'ProvisionedThroughput' => [
            'ReadCapacityUnits' => 5,
            'WriteCapacityUnits' => 5,
        ],
    ];
}


l::configure(["region" => NETWORK_REGION]);

$schemas = [
    \Models\User::$schema,
];

echo "Install DBs...";
foreach ($schemas as $schema) {
    try {
        Model::$client->deleteTable([
            "TableName" => $schema['TableName']
        ]);
    } catch (Exception $e) {}
    Model::$client->createTable($schema);
}
echo "done\n";


$user = new User();
$user->id = "my-id";
$user->firstName = "hello";
$user->lastName = "world";
$user->save();


$user = User::getById('my-id');
$user->lastName = "wood";
$user->save();