1. Go to this page and download the library: Download mcn-healthcare/dynamodb-odm 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/ */
mcn-healthcare / dynamodb-odm example snippets
use McnHealthcare\ODM\Dynamodb\ItemManager;
$client = new \Aws\DynamoDb\DynamoDbClient(
[
'version' => 'latest',
'region' => 'us-west-2',
'endpoint' => 'http://localhost:8000',
'credentials' => [
'key' => 'my-access-key-id',
'secret' => 'my-secret-access-key',
]
]
);
$tablePrefix = "odm-";
$itemNamespace = 'McnHealthcare\ODM\Dynamodb\Ut'; // in practice, this usually looks like: My\Root\Namespace\Items
$itemSrcDir = __DIR__ . "/ut"; // in practice, this usually points to src/Items directory
$im = new ItemManager(
$client,
$tablePrefix,
$reader,
$logger
);
$im->addNamespace(
$itemNamespace,
$itemSrcDir
);
use McnHealthcare\ODM\Dynamodb\Console\ConsoleHelper;
// replace with file to your own project bootstrap
onsoleHelper($itemManager);
use McnHealthcare\ODM\Dynamodb\Annotations\Field;
use McnHealthcare\ODM\Dynamodb\Annotations\Item;
/**
* @Item(
* table="users",
* primaryIndex={"id"}
* )
*/
class User
{
/**
* @var int
* @Field(type="number")
*/
protected $id;
/**
* @var string
* @Field(type="string")
*/
protected $name;
/**
* Last updated is set to unix timestamp on every update
*
* @var int
* @Field(type="int", cas="timestamp")
*/
protected $lastUpdated;
}
/** @var ItemManger $im */
/** @var User $user */
$im->detach($user);
$user->setName('Mr.Left');
$im->flush(); // changes to $user will not be synchronized
/** @var ItemManager $im */
/** @var ItemRepository $userRepo */
$userRepo = $im->getRepository(User::class);
/** @var Users[] $users */
$users = $userRepo->multiQueryAndRun(
function ($item) {
// each item returned can be accessed here in the callback
},
"classPartition", // PartitionedHashKey field name
"A", // value expected in the base field (not the partition field)
"#age >= :minAge", // only range conditions here
[
":minAge" => 25,
],
"class-partition-age-index" // index for PartitionedHashKey
);