| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package dynamodb |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | |||
| 6 | "github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
||
| 7 | ) |
||
| 8 | |||
| 9 | // DeleteTableFromName deletes a table of `name`. |
||
| 10 | func (svc *DynamoDB) DeleteTableFromName(ctx context.Context, name string) error { |
||
| 11 | _, err := svc.DeleteTable(ctx, DeleteTableRequest{ |
||
| 12 | TableName: name, |
||
| 13 | }) |
||
| 14 | return err |
||
| 15 | } |
||
| 16 | |||
| 17 | // ExistTable checks if the table already exists or not. |
||
| 18 | func (svc *DynamoDB) ExistTable(ctx context.Context, name string) (bool, error) { |
||
| 19 | _, err := svc.DescribeTable(ctx, DescribeTableRequest{ |
||
| 20 | TableName: name, |
||
| 21 | }) |
||
| 22 | if err == nil { |
||
| 23 | return true, nil |
||
| 24 | } |
||
| 25 | |||
| 26 | if e, ok := err.(errors.ErrorData); ok { |
||
| 27 | if e.GetAWSErrCode() == "ResourceNotFoundException" { |
||
| 28 | return false, nil |
||
| 29 | } |
||
| 30 | } |
||
| 31 | return false, err |
||
| 32 | } |
||
| 33 |