(ctx context.Context, key dynamodbKey, isPrefix bool)
| 138 | } |
| 139 | |
| 140 | func (kv dynamodbKV) Query(ctx context.Context, key dynamodbKey, isPrefix bool) (map[string]dynamodbItem, float64, error) { |
| 141 | keys := make(map[string]dynamodbItem) |
| 142 | var totalCapacity float64 |
| 143 | |
| 144 | co := types.ComparisonOperatorEq |
| 145 | if isPrefix { |
| 146 | co = types.ComparisonOperatorBeginsWith |
| 147 | } |
| 148 | |
| 149 | input := &dynamodb.QueryInput{ |
| 150 | TableName: kv.tableName, |
| 151 | ReturnConsumedCapacity: types.ReturnConsumedCapacityTotal, |
| 152 | KeyConditions: map[string]types.Condition{ |
| 153 | primaryKey: { |
| 154 | ComparisonOperator: co, |
| 155 | AttributeValueList: []types.AttributeValue{ |
| 156 | &types.AttributeValueMemberS{Value: key.primaryKey}, |
| 157 | }, |
| 158 | }, |
| 159 | }, |
| 160 | } |
| 161 | |
| 162 | paginator := dynamodb.NewQueryPaginator(kv.ddbClient, input) |
| 163 | |
| 164 | for paginator.HasMorePages() { |
| 165 | page, err := paginator.NextPage(ctx) |
| 166 | if err != nil { |
| 167 | return nil, totalCapacity, err |
| 168 | } |
| 169 | totalCapacity += getCapacityUnits(page.ConsumedCapacity) |
| 170 | |
| 171 | for _, item := range page.Items { |
| 172 | itemVersion := int64(0) |
| 173 | if v, ok := item[version].(*types.AttributeValueMemberN); ok { |
| 174 | parsedVersion, err := strconv.ParseInt(v.Value, 10, 0) |
| 175 | if err != nil { |
| 176 | kv.logger.Log("msg", "failed to parse item version", "version", v.Value, "err", err) |
| 177 | } else { |
| 178 | itemVersion = parsedVersion |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if d, ok := item[contentData].(*types.AttributeValueMemberB); ok { |
| 183 | if s, ok := item[sortKey].(*types.AttributeValueMemberS); ok { |
| 184 | keys[s.Value] = dynamodbItem{ |
| 185 | data: d.Value, |
| 186 | version: itemVersion, |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return keys, totalCapacity, nil |
| 194 | } |
| 195 | |
| 196 | func (kv dynamodbKV) Delete(ctx context.Context, key dynamodbKey) (float64, error) { |
| 197 | input := &dynamodb.DeleteItemInput{ |
nothing calls this directly
no test coverage detected