1. Go to this page and download the library: Download bf-dsf/php-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/ */
bf-dsf / php-dynamodb-odm example snippets
use BF\Mlib\ODM\Dynamodb\ItemManager;
$awsConfig = [
"profile" => "oasis-minhao",
"region" => "ap-northeast-1"
];
$tablePrefix = "odm-";
$cacheDir = __DIR__ . "/ut/cache";
$isDev = true;
$itemNamespace = 'BF\Mlib\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(
$awsConfig,
$tablePrefix,
$cacheDir,
$isDev
);
$im->addNamespace(
$itemNamespace,
$itemSrcDir
);
use BF\Mlib\ODM\Dynamodb\Console\ConsoleHelper;
// replace with file to your own project bootstrap
new ConsoleHelper($itemManager);
use BF\Mlib\ODM\Dynamodb\Annotations\Field;
use BF\Mlib\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;
}
/** @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
);