You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Notice that you can have multiple tables in the DDB schema. Nested attributes are supported too.
77
78
@@ -196,6 +197,7 @@ await tsynamoClient
196
197
.execute();
197
198
```
198
199
200
+
> [!NOTE]
199
201
> This would compile as the following FilterExpression:
200
202
> `NOT eventType = "LOG_IN"`, i.e. return all events whose types is not "LOG_IN"
201
203
@@ -282,6 +284,85 @@ await tsynamoClient
282
284
.execute();
283
285
```
284
286
287
+
### Transactions
288
+
289
+
One can also utilise [DynamoDB Transaction](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html) features using Tsynamo. You can perform operations to multiple tables in a single transaction command.
290
+
291
+
#### Write transaction
292
+
293
+
DynamoDB enables you to do multiple `Put`, `Update` and `Delete` in a single `WriteTransaction` command. One can also provide an optional `ClientRequestToken` to the transaction to ensure idempotency.
> When passing the items into the transaction using the tsynamoClient, do not execute the individual calls! Instead just pass in the query builder as the item.
323
+
324
+
> [!WARNING]
325
+
> DynamoDB also supports doing `ConditionCheck` operations in the transaction, but Tsynamo does not yet support those.
326
+
327
+
#### Read transaction
328
+
329
+
Since the read transaction output can affect multiple tables, the resulting output is an array of tuples where the first item is the name of the table and the second item is the item itself (or `undefined` if the item was not found). This can be used as a discriminated union to determine the resulting item's type.
330
+
331
+
```ts
332
+
const trx =tsynamoClient.createReadTransaction();
333
+
334
+
trx.addItem({
335
+
Get: tsynamoClient.getItem("myTable").keys({
336
+
userId: "123",
337
+
dataTimestamp: 222,
338
+
}),
339
+
});
340
+
341
+
trx.addItem({
342
+
Get: tsynamoClient.getItem("myOtherTable").keys({
343
+
userId: "321",
344
+
stringTimestamp: "222",
345
+
}),
346
+
});
347
+
348
+
const result =awaittrx.execute();
349
+
```
350
+
351
+
Then, one can loop through the result items as so:
352
+
353
+
```ts
354
+
// note that the items can be undefined if they were not found from DynamoDB
exports[`WriteTransactionBuilder > handles a transaction with a client request token 1`] =`[IdempotentParameterMismatchException: UnknownError]`;
4
+
5
+
exports[`WriteTransactionBuilder > handles a transaction with failing conditions 1`] =`[TransactionCanceledException: Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]]`;
6
+
7
+
exports[`WriteTransactionBuilder > handles a transaction with puts 1`] =`
8
+
[
9
+
{
10
+
"dataTimestamp": 1,
11
+
"userId": "9999",
12
+
},
13
+
{
14
+
"dataTimestamp": 2,
15
+
"userId": "9999",
16
+
},
17
+
]
18
+
`;
19
+
20
+
exports[`WriteTransactionBuilder > handles a transaction with updates 1`] =`
0 commit comments