delete
Introduction
delete
method performs delete request using aws-sdk DeleteItemCommand.
execute
batchDelete
takes 2 arguments:
- (required) item identifier
- item
primaryIndex
- or an object which includes item
primaryIndex
(+sortKey
for HASH and RANGE tables) and optionnally Condition expression
- item
- (optionnal) options
simple delete request on a HASH table
const res = await User.delete("user-1", { ReturnConsumedCapacity: "TOTAL" } )
simple delete request on a HASH and RANGE table
const res = await User.delete(
{
groupId: "group-1", // Schema primaryIndex
userId: "user-1", // Schema sortKey
},
{ ReturnConsumedCapacity: "TOTAL" }
);
delete request with conditions
const res = await User.delete(
{
id: "user-1", // Schema primaryIndex
age: {
$gt: 25 // deletes item if id = "user-1" and age is greater than 25
}
},
{ ReturnConsumedCapacity: "TOTAL" }
);
options
options
is an object which accepts DeleteItemCommandInput
options and DynamoQL specific options.
exec
exec
boolean directive to execute or not the actual request.
When false
delete will return DeleteItemCommandInput
object.
import type { DeleteItemCommandInput } from "@aws-sdk/client-dynamodb";
const cmd: DeleteItemCommandInput = await User.delete(
"user-1",
{ exec: false }
);