Exemple #1
0
        public async Task AddAsync <TKey, TValue>(TKey key, TValue value)
        {
            var request = new PutItemRequest
            {
                TableName = _tableName,
                Item      = SetKeyItems(key, new Dictionary <string, AttributeValue>
                {
                    { "Value", AttributeValueTypeAccessor <TValue> .CreateValue(value, _settings.Serializer) },
                }),
                Expected = new Dictionary <string, ExpectedAttributeValue>
                {
                    { "Dictionary", new ExpectedAttributeValue(false) },
                    { "Key", new ExpectedAttributeValue(false) },
                }
            };

            try
            {
                var response = await _dynamoDBClient.PutItemAsync(request).ConfigureAwait(false);
            }
            catch (ConditionalCheckFailedException ex)
            {
                throw new ArgumentException("An item with the same key has already been added.", ex);
            }
        }
Exemple #2
0
        public async Task AddOrUpdateAsync <TKey, TValue>(TKey key, TValue value)
        {
            var request = new PutItemRequest
            {
                TableName = _tableName,
                Item      = SetKeyItems(key, new Dictionary <string, AttributeValue>
                {
                    { "Value", AttributeValueTypeAccessor <TValue> .CreateValue(value, _settings.Serializer) },
                }),
            };

            var response = await _dynamoDBClient.PutItemAsync(request).ConfigureAwait(false);
        }
Exemple #3
0
 private TValue GetValue <TValue>(Dictionary <string, AttributeValue> item)
 {
     return(AttributeValueTypeAccessor <TValue> .GetValue(item["Value"], _settings.Serializer));
 }