• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fogfish / dynamo / 11990190580

23 Nov 2024 08:27PM UTC coverage: 83.45% (-0.3%) from 83.747%
11990190580

push

github

web-flow
Use fogfish/opts library to declare options (#105)

60 of 68 new or added lines in 14 files covered. (88.24%)

2 existing lines in 2 files now uncovered.

1311 of 1571 relevant lines covered (83.45%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.48
/service/ddb/opGet.go
1
//
2
// Copyright (C) 2022 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/fogfish/dynamo
7
//
8

9
package ddb
10

11
import (
12
        "context"
13

14
        "github.com/aws/aws-sdk-go-v2/aws"
15
        "github.com/aws/aws-sdk-go-v2/service/dynamodb"
16
        "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
17
)
18

19
// Get item from storage
20
func (db *Storage[T]) Get(ctx context.Context, key T, opts ...interface{ GetterOpt(T) }) (T, error) {
1✔
21
        gen, err := db.codec.EncodeKey(key)
1✔
22
        if err != nil {
1✔
23
                return db.undefined, errInvalidKey.New(err)
×
24
        }
×
25

26
        req := &dynamodb.GetItemInput{
1✔
27
                Key:                      gen,
1✔
28
                TableName:                aws.String(db.table),
1✔
29
                ProjectionExpression:     db.schema.Projection,
1✔
30
                ExpressionAttributeNames: db.schema.ExpectedAttributeNames,
1✔
31
        }
1✔
32

1✔
33
        val, err := db.service.GetItem(ctx, req)
1✔
34
        if err != nil {
2✔
35
                return db.undefined, errServiceIO.New(err)
1✔
36
        }
1✔
37

38
        if val.Item == nil {
2✔
39
                return db.undefined, errNotFound(nil, key)
1✔
40
        }
1✔
41

42
        obj, err := db.codec.Decode(val.Item)
1✔
43
        if err != nil {
1✔
44
                return db.undefined, errInvalidEntity.New(err)
×
45
        }
×
46

47
        return obj, nil
1✔
48
}
49

50
func (db *Storage[T]) BatchGet(ctx context.Context, keys []T, opts ...interface{ GetterOpt(T) }) ([]T, error) {
×
51
        seq := make([]map[string]types.AttributeValue, len(keys))
×
52
        for i := 0; i < len(keys); i++ {
×
53
                gen, err := db.codec.EncodeKey(keys[i])
×
54
                if err != nil {
×
55
                        return nil, errInvalidKey.New(err)
×
56
                }
×
57
                seq[i] = gen
×
58
        }
59

60
        req := &dynamodb.BatchGetItemInput{
×
61
                RequestItems: map[string]types.KeysAndAttributes{
×
NEW
62
                        db.table: {
×
63
                                Keys:                     seq,
×
64
                                ProjectionExpression:     db.schema.Projection,
×
65
                                ExpressionAttributeNames: db.schema.ExpectedAttributeNames,
×
66
                        },
×
67
                },
×
68
        }
×
69

×
70
        val, err := db.service.BatchGetItem(ctx, req)
×
71
        if err != nil {
×
72
                return nil, errServiceIO.New(err)
×
73
        }
×
74

NEW
75
        rsp, exists := val.Responses[db.table]
×
76
        if !exists {
×
77
                return make([]T, 0), nil
×
78
        }
×
79

80
        items := make([]T, len(rsp))
×
81
        for i := 0; i < len(rsp); i++ {
×
82
                obj, err := db.codec.Decode(rsp[i])
×
83
                if err != nil {
×
84
                        return nil, errInvalidEntity.New(err)
×
85
                }
×
86
                items[i] = obj
×
87
        }
88

89
        return items, nil
×
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc