Work with AWS DynamoDB and Single-Table-Designed tables in your apps.
Requires aws/aws-sdk-php
with 3.*
version.
composer require dynamite/dynamite
See docs/bring-your-own-id.md
for more information.
v1.0.0
ItemRepository
SingleTableService
DynamiteRegistry
to work with more than one table@DuplicateTo
annotation - duplicate some attributes to additional items while putting them to DynamoDBItem duplication requires dynamodb:BatchWriteItem
enabled.
When you need to duplicate an object to many items at once, you can use @DuplicateTo
annotation:
/**
* @Dynamite\Item(objectType="USER")
* @Dynamite\PartitionKeyFormat("USER#{id}")
* @Dynamite\SortKeyFormat("USER")
* @Dynamite\DuplicateTo(pk="UDATA#{email}", sk="UDATA", props={"id", "username"})
* @Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"})
*/
class User {
//...props
}
$user = new User('123', '[email protected]', 'mickey')
In this case, There will be 3 items sent to DynamoDB:
USER#123
SK:USER
with all attributes defined in item;UDATA#user@example
SK: UDATA
with id
and username
props;UDATA#mickey
SK: UDATA
with id
and email
props.You can add a transform
param to annotation to fill Primary key pair with lowercased/uppercased params:
//In this case PK: UDATA#MICKEY
@Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"}, transform="UPPER")
//In this case PK: UDATA#mickey
@Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"}, transform="LOWER")
By default params are passed as-is. transform
works only for params injected to key, key template remains untouched.
@TODO
Dynamite uses doctrine/annotation
under the hood to parse all item annotations to provide doctrine/orm
-like mapping configuration.
Allows you to define the format of primary key pair of Item stored in table.
When Partition Key or Sort Key will be passed to build Partition Key or Sort Key, Dynamite will break.
/**
* Use class properties from your object wrapped with {} as a placeholders for values.
* Warning: {itemType} will be taken from @ItemType annotation.
* @Item(objectType="USER")
* @PartitionKeyFormat('{itemType}#{username}')
* @SortKeyFormat('{itemType}')
*/
class User {
public $email;
public $username;
}
$user = new User();
$user->username = 'tonystark';
//In this example, object will be stored with "USER#tonystark" PK and "USER" Sort key
Nested item is... an item nested in another item. It cannot have a Partition Key as it would be taken from parent (or first non-nested item when multiple nested) object.
Nested item cannot have both @Item
and @NestedItem
annotation.
NestedValueObjectAttribute#type should not be required when property is defined
MIT