Skip to content

Commit f5cb779

Browse files
committed
feat: Key parameters transforming docs
1 parent 901d20e commit f5cb779

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
### Added:
9+
- Changing case of params injected to keys in `@DuplicateTo`
10+
711
## [0.0.2] - 2021-01-30
812
### Added
913
- Support for collection of objects passed to `NestedValueObjectAttribute`

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,47 @@ There are some proposals you can use:
5353

5454
## Documentation
5555

56+
### Item Duplication
57+
58+
**Item duplication requires `dynamodb:BatchWriteItem` enabled.**
59+
60+
When you need to duplicate an object to many items at once, you can use ``@DuplicateTo`` annotation:
61+
62+
````
63+
/**
64+
* @Dynamite\Item(objectType="USER")
65+
* @Dynamite\PartitionKeyFormat("USER#{id}")
66+
* @Dynamite\SortKeyFormat("USER")
67+
* @Dynamite\DuplicateTo(pk="UDATA#{email}", sk="UDATA", props={"id", "username"})
68+
* @Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"})
69+
*/
70+
class User {
71+
//...props
72+
}
73+
74+
$user = new User('123', '[email protected]', 'mickey')
75+
````
76+
77+
In this case, There will be 3 items sent to DynamoDB:
78+
- PK: `USER#123` SK:`USER` with **all** attributes defined in item;
79+
- PK: `UDATA#user@example` SK: `UDATA` with `id` and `username` props;
80+
- PK: `UDATA#mickey` SK: `UDATA` with `id` and `email` props.
81+
82+
83+
You can add a `transform` param to annotation to fill Primary key pair with lowercased/uppercased params:
84+
85+
86+
````
87+
88+
//In this case PK: UDATA#MICKEY
89+
@Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"}, transform="UPPER")
90+
91+
//In this case PK: UDATA#mickey
92+
@Dynamite\DuplicateTo(pk="UDATA#{username}", sk="UDATA", props={"id", "email"}, transform="LOWER")
93+
````
94+
95+
By default params are passed as-is. `transform` works only for params injected to key, key template remains untouched.
96+
5697

5798
### Creating an Item
5899

0 commit comments

Comments
 (0)