Skip to content

Commit d14fbc4

Browse files
committed
Add readme
1 parent d40b46c commit d14fbc4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,32 @@ const { total } = await myDocumentDao.decr(
137137
);
138138
```
139139

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+
140166
## Developing
141167

142168
The test setup requires that [docker-compose]() be installed. To run the tests,

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ export default class DynamoDbDao<DataModel, KeySchema> {
742742
.batchWrite({
743743
RequestItems: {
744744
[this.tableName]: operations.map((operation) => {
745-
// TODO: optionally add the opt lock here
746745
if (isBatchPutOperation(operation)) {
747746
return {
748747
PutRequest: {

0 commit comments

Comments
 (0)