コード例 #1
0
        public async Task UpdateItemAsync <T>(DynamoUpdateItem update, CancellationToken token = default)
        {
            var request = ToUpdateItemRequest <T>(update);

            await ExecAsync(async() =>
                            await DynamoDb.UpdateItemAsync(request, token).ConfigAwait()).ConfigAwait();
        }
コード例 #2
0
        public void UpdateItem <T>(DynamoUpdateItem update)
        {
            var table   = DynamoMetadata.GetTable <T>();
            var request = new UpdateItemRequest
            {
                TableName        = table.Name,
                Key              = Converters.ToAttributeKeyValue(this, table, update.Hash, update.Range),
                AttributeUpdates = new Dictionary <string, AttributeValueUpdate>(),
                ReturnValues     = ReturnValue.NONE,
            };

            if (update.Put != null)
            {
                foreach (var entry in update.Put)
                {
                    var field = table.GetField(entry.Key);
                    if (field == null)
                    {
                        continue;
                    }

                    request.AttributeUpdates[field.Name] = new AttributeValueUpdate(
                        Converters.ToAttributeValue(this, field.Type, field.DbType, entry.Value), DynamoAttributeAction.Put);
                }
            }

            if (update.Add != null)
            {
                foreach (var entry in update.Add)
                {
                    var field = table.GetField(entry.Key);
                    if (field == null)
                    {
                        continue;
                    }

                    request.AttributeUpdates[field.Name] = new AttributeValueUpdate(
                        Converters.ToAttributeValue(this, field.Type, field.DbType, entry.Value), DynamoAttributeAction.Add);
                }
            }

            if (update.Delete != null)
            {
                foreach (var key in update.Delete)
                {
                    var field = table.GetField(key);
                    if (field == null)
                    {
                        continue;
                    }

                    request.AttributeUpdates[field.Name] = new AttributeValueUpdate(null, DynamoAttributeAction.Delete);
                }
            }

            Exec(() => DynamoDb.UpdateItem(request));
        }