Skip to content

Commit 92117ad

Browse files
committed
add transactions to readme
1 parent ecdcecc commit 92117ad

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
![dynamodb-toolbox](https://user-images.githubusercontent.com/2053544/69847647-b7910780-1245-11ea-8403-a35a0158f3aa.png)
99

1010

11-
### **NOTE:** This version is a work in progress. Please submit [issues/feedback](https://github.com/jeremydaly/dynamodb-toolbox/issues) or feel free to contact me on Twitter [@jeremy_daly](https://twitter.com/jeremy_daly).
11+
**NOTE:** This version is a work in progress. Please submit [issues/feedback](https://github.com/jeremydaly/dynamodb-toolbox/issues) or feel free to contact me on Twitter [@jeremy_daly](https://twitter.com/jeremy_daly).
1212

1313
## Single Table Designs have never been this easy!
1414

@@ -146,12 +146,12 @@ If you like working with ORMs, that's great, and you should definitely give thes
146146
- **Projection Builder:** Specify which attributes and paths should be returned for each entity type, and automatically filter the results.
147147
- **Secondary Index Support:** Map your secondary indexes (GSIs and LSIs) to your table, and dynamically link your entity attributes.
148148
- **Batch Operations:** Full support for batch operations with a simpler interface to work with multiple entities and tables.
149+
- **Transactions:** Full support for transaction with a simpler interface to work with multiple entities and tables.
149150
- **Default Value Dependency Graphs:** Create dynamic attribute defaults by chaining other dynamic attribute defaults together.
150151

151152
## Table of Contents
152153

153154
- [DynamoDB Toolbox - v0.3 (WIP: TypeScript Conversion)](#dynamodb-toolbox---v03-wip-typescript-conversion)
154-
- [**NOTE:** This version is a work in progress. Please submit issues/feedback or feel free to contact me on Twitter [@jeremy_daly](https://twitter.com/jeremy_daly).](#note-this-version-is-a-work-in-progress-please-submit-issuesfeedback-or-feel-free-to-contact-me-on-twitter-jeremy_daly)
155155
- [Single Table Designs have never been this easy!](#single-table-designs-have-never-been-this-easy)
156156
- [Installation and Basic Usage](#installation-and-basic-usage)
157157
- [This is *NOT* an ORM (at least it's not trying to be)](#this-is-not-an-orm-at-least-its-not-trying-to-be)
@@ -184,6 +184,11 @@ If you like working with ORMs, that's great, and you should definitely give thes
184184
- [Return Data](#return-data-2)
185185
- [batchWrite(items [,options] [,parameters])](#batchwriteitems-options-parameters)
186186
- [Return Data](#return-data-3)
187+
- [transactGet(items [,options] [,parameters])](#transactgetitems-options-parameters)
188+
- [Accessing items from multiple tables](#accessing-items-from-multiple-tables)
189+
- [Return Data](#return-data-4)
190+
- [transactWrite(items [,options] [,parameters])](#transactwriteitems-options-parameters)
191+
- [Return Data](#return-data-5)
187192
- [parse(entity, input [,include])](#parseentity-input-include)
188193
- [get(entity, key [,options] [,parameters])](#getentity-key-options-parameters)
189194
- [delete(entity, key [,options] [,parameters])](#deleteentity-key-options-parameters)
@@ -689,6 +694,82 @@ If you prefer to specify your own parameters, the optional third argument allows
689694
#### Return Data
690695
The data is returned with the same response syntax as the [DynamoDB BatchWriteItem API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html). If `autoExecute` and `autoParse` are enabled, a `.next()` method will be available on the returned object. Calling this function will call the `batchWrite` method again using the same options and passing any `UnprocessedItems` in as the `RequestItems`. This is a convenience method for retrying unprocessed keys.
691696

697+
698+
699+
700+
701+
### transactGet(items [,options] [,parameters])
702+
703+
> TransactGetItems is a synchronous operation that atomically retrieves multiple items from one or more tables (but not from indexes) in a single account and Region.
704+
705+
The `transactGet` method is a wrapper for the [DynamoDB TransactGetItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html). The DynamoDB Toolbox `transactGet` method supports all **TransactGetItem** API operations. The `transactGet` method returns a `Promise` and you must use `await` or `.then()` to retrieve the results. An alternative, synchronous method named `transactGetParams` can be used, but will only retrieve the generated parameters.
706+
707+
The `transacthGet` method accepts three arguments. The first is an `array` of item keys to get. The DynamoDB Toolbox provides the `getTransaction` method on your entities to help you generate the proper key configuration. You can specify different entity types as well as entities from different tables, and this library will handle the proper payload construction.
708+
709+
The optional second argument accepts an `options` object. The following options are all optional (corresponding TransactGetItems API references in parentheses):
710+
711+
| Option | Type | Description |
712+
| -------- | :--: | ----------- |
713+
| capacity | `string` | Return the amount of consumed capacity. One of either `none`, `total`, or `indexes` (ReturnConsumedCapacity) |
714+
| execute | `boolean` | Enables/disables automatic execution of the DocumentClient method (default: *inherited from Table*) |
715+
| parse | `boolean` | Enables/disables automatic parsing of returned data when `autoExecute` evaluates to `true` (default: *inherited from Table*) |
716+
717+
#### Accessing items from multiple tables
718+
Transaction items are atomic, so each `Get` contains the table name and key necessary to retrieve the item. The library will automatically handle adding the necessary information and will parse each entity automatically for you.
719+
720+
```javascript
721+
const results = await MyTable.transactGet(
722+
[
723+
User.getTransaction({ family: 'Brady', name: 'Mike' }),
724+
User.getTransaction({ family: 'Brady', name: 'Carol' }),
725+
Pet.getTransaction({ family: 'Brady', name: 'Tiger' })
726+
],
727+
{ capacity: 'total' }
728+
)
729+
```
730+
731+
If you prefer to specify your own parameters, the optional third argument allows you to add custom parameters. [See Adding custom parameters and clauses](#adding-custom-parameters-and-clauses) for more information.
732+
733+
#### Return Data
734+
The data is returned with the same response syntax as the [DynamoDB TransactGetItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html). If `autoExecute` and `autoParse` are enabled, any `Responses` data returned will be parsed into its corresponding Entity's aliases. Otherwise, the DocumentClient will return the unmarshalled data.
735+
736+
### transactWrite(items [,options] [,parameters])
737+
738+
> TransactWriteItems is a synchronous write operation that groups up to 25 action requests. The actions are completed atomically so that either all of them succeed, or all of them fail.
739+
740+
The `transactWrite` method is a wrapper for the [DynamoDB TransactWriteItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html). The DynamoDB Toolbox `transactWrite` method supports all **TransactWriteItems** API operations. The `transactWrite` method returns a `Promise` and you must use `await` or `.then()` to retrieve the results. An alternative, synchronous method named `transactWriteParams` can be used, but will only retrieve the generated parameters.
741+
742+
The `transactWrite` method accepts three arguments. The first is an `array` of item keys to either `put`, `delete`, `update` or `conditionCheck`. The DynamoDB Toolbox provides `putTransaction`,`deleteTransaction`, `updateTransaction`, and `conditionCheck` methods on your entities to help you generate the proper configuration for each item. You can specify different entity types as well as entities from different tables, and this library will handle the proper payload construction.
743+
744+
The optional second argument accepts an `options` object. The following options are all optional (corresponding TransactWriteItems API references in parentheses):
745+
746+
| Option | Type | Description |
747+
| -------- | :--: | ----------- |
748+
| capacity | `string` | Return the amount of consumed capacity. One of either `none`, `total`, or `indexes` (ReturnConsumedCapacity) |
749+
| metrics | `string` | Return item collection metrics. If set to `size`, the response includes statistics about item collections, if any, that were modified during the operation are returned in the response. One of either `none` or `size` (ReturnItemCollectionMetrics) |
750+
| token | `string` | Optional token to make the call idempotent, meaning that multiple identical calls have the same effect as one single call. (ClientRequestToken) |
751+
| execute | `boolean` | Enables/disables automatic execution of the DocumentClient method (default: *inherited from Entity*) |
752+
| parse | `boolean` | Enables/disables automatic parsing of returned data when `autoExecute` evaluates to `true` (default: *inherited from Entity*) |
753+
754+
```javascript
755+
const result = await Default.transactWrite(
756+
[
757+
Pet.conditionCheck({ family: 'Brady', name: 'Tiger' }, { conditions: { attr: 'alive', eq: false } },
758+
Pet.deleteTransaction({ family: 'Brady', name: 'Tiger' }),
759+
User.putTransaction({ family: 'Brady', name: 'Carol', age: 40, roles: ['mother','wife'] }),
760+
User.putTransaction({ family: 'Brady', name: 'Mike', age: 42, roles: ['father','husband'] })
761+
],{
762+
capacity: 'total',
763+
metrics: 'size',
764+
}
765+
)
766+
```
767+
768+
If you prefer to specify your own parameters, the optional third argument allows you to add custom parameters. [See Adding custom parameters and clauses](#adding-custom-parameters-and-clauses) for more information.
769+
770+
#### Return Data
771+
The data is returned with the same response syntax as the [DynamoDB TransactWriteItems API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html).
772+
692773
### parse(entity, input [,include])
693774
694775
Executes the `parse` method of the supplied `entity`. The `entity` must be a `string` that references the name of an Entity associated with the table. See the [Entity `parse` method](#parseinput-include) for additional parameters and behavior.

0 commit comments

Comments
 (0)