-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
39 lines (32 loc) · 978 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package dygo
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
)
const opDelete = "Delete"
// Delete deletes the item from the DynamoDB table.
// It returns an error if there was an issue with the deletion process.
func (i *Item) Delete(ctx context.Context) error {
if i.err != nil {
return i.err
}
expr, err := i.deleteItemExpression()
if err != nil {
return dynamoError().method(opDelete).message(err.Error())
}
input := dynamodb.DeleteItemInput{
TableName: aws.String(i.c.tableName),
Key: i.key,
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
ConditionExpression: expr.Condition(),
}
if _, err := i.c.client.DeleteItem(context.TODO(), &input); err != nil {
if err := getDynamoDBError(opDelete, err); err != nil {
return err
}
return dynamoError().method(opDelete).message(err.Error())
}
return nil
}