Amazon DynamoDB
Delete
6 samples, from the least code that works to complete workflows.
What a delete does
| Rule | On DynamoDB |
|---|---|
| Which item | By its full key: the id (an entity whose key is its id), the id with the key's other attributes, or ArxMatch.Columns/ArxMatch.Key naming the key's attributes |
| Other columns | When they give a partition key, of the table or an index: one query finds the items (at most 100), then they are deleted by their keys, all or nothing, each conditioned on still matching; none found is 0 (ARX2002 with RequireSingleRow), several with RequireSingleRow ARX2003 |
| No partition | ARX8001: a write never scans |
| Nothing found | DeleteAsync(name, id) returns false; DeleteAsync(entity) returns 0: deleting twice isn't an error |
| In a transaction | The items are read now (so the count is known), and deleted with the transaction's other writes at the commit |
| Names | Placeholders only; expression or SQL syntax in a match name is ARX1017, checked before the match itself |
| Rows by a condition | Delete finds rows by equal values: the id, a declared key, or columns you give values for (ArxMatch.Columns). To delete every row that meets a condition (amount > 100), call DeleteMultipleAsync(table, filter) (the filter must give a partition key; at most 100 items): one call, all or nothing, from 0.1.0-preview.5 (DeleteMultiple, Basics). Before that version: read the rows with RetrieveMultipleAsync and pass them to DeleteMultipleAsync. |
The samples
Basics
The least code that works.
1Delete one recordProgressiveThe smallest delete, in two scenarios: by the id Create returned, and an id no item has.
How a delete finds its items in DynamoDB, in four scenarios: an order by its id and its customer, several orders by their keys, the rest of a customer's orders through a query, and a match no partition answers.
Real cases
What an application does: a small CRM and product catalogue.
1Catch an injection attemptProgressiveA "remove my order" endpoint attacked two ways: a match column named with expression syntax, and a value written to widen the delete to every order; then the honest request.
Advanced cases
Dependency injection, transactions, batch scopes and setting the service up.
1Replace a record in a transactionAdvancedReplace an order in one ARX transaction: delete the old one, create the new one, commit, in two scenarios: the replacement, and a replacement that fails and leaves the old order in place.
A security check around deletes (SecurityGuard), in three scenarios: a normal delete, an attack in the match that is logged, and repeated attacks that block the user.
The service set up from DynamoDB's description of the lead table, in two scenarios: preload at startup in the KeysOnly mode, then delete by the preloaded key.