File tree 2 files changed +26
-1
lines changed 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,32 @@ const { total } = await myDocumentDao.decr(
137
137
);
138
138
```
139
139
140
+ ** Optimistic Locking with Version Numbers**
141
+
142
+ For callers who wish to enable an optimistic locking strategy there are two
143
+ available toggles:
144
+
145
+ 1 . Provide the attribute you wish to be used to store the version number. This
146
+ will enable optimistic locking on the following operations: ` put ` , ` update ` ,
147
+ and ` delete ` .
148
+
149
+ Writes for documents that do not have a version number attribute will
150
+ initialize the version number to 1. All subsequent writes will need to
151
+ provide the current version number. If an out-of-date version number is
152
+ supplied, an error will be thrown.
153
+
154
+ 2 . If you wish to ignore optimistic locking for a save operation, specify
155
+ ` ignoreOptimisticLocking: true ` on your ` put ` , ` update ` , or ` delete ` .
156
+
157
+ NOTE: Optimistic locking is NOT supported for ` batchWrite ` or ` batchPut `
158
+ operations. Consuming those APIs for data models that do have optimistic locking
159
+ enabled may clobber your version data and could produce undesirable effects for
160
+ other callers.
161
+
162
+ This was modeled after the
163
+ [ Java Dynamo client] ( https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptimisticLocking.html )
164
+ implementation.
165
+
140
166
## Developing
141
167
142
168
The test setup requires that [ docker-compose] ( ) be installed. To run the tests,
Original file line number Diff line number Diff line change @@ -742,7 +742,6 @@ export default class DynamoDbDao<DataModel, KeySchema> {
742
742
. batchWrite ( {
743
743
RequestItems : {
744
744
[ this . tableName ] : operations . map ( ( operation ) => {
745
- // TODO: optionally add the opt lock here
746
745
if ( isBatchPutOperation ( operation ) ) {
747
746
return {
748
747
PutRequest : {
You can’t perform that action at this time.
0 commit comments