// ToBatchWriteItem will attempt to convert a BatchWriteItemJSON to BatchWriteItem
func (bwij *BatchWriteItemJSON) ToBatchWriteItem() (*BatchWriteItem, error) {
	if bwij == nil {
		return nil, errors.New("batch_write_item.ToBatchWriteItem: receiver is nil")
	}
	b := NewBatchWriteItem()
	for tn, ris := range bwij.RequestItems {
		l := len(ris)
		b.RequestItems[tn] = make([]RequestInstance, l)
		for i, ri := range ris {
			if ri.DeleteRequest != nil {
				b.RequestItems[tn][i].DeleteRequest = ri.DeleteRequest
				b.RequestItems[tn][i].PutRequest = nil
			} else if ri.PutRequest != nil {
				a, cerr := attributevalue.InterfaceToAttributeValueMap(ri.PutRequest.Item)
				if cerr != nil {
					return nil, cerr
				}
				b.RequestItems[tn][i].PutRequest = &PutRequest{Item: item.Item(a)}
				b.RequestItems[tn][i].DeleteRequest = nil
			} else {
				return nil, errors.New("no Put or Delete request found")
			}
		}
	}
	b.ReturnConsumedCapacity = bwij.ReturnConsumedCapacity
	b.ReturnItemCollectionMetrics = bwij.ReturnItemCollectionMetrics
	return b, nil
}
Beispiel #2
0
// ToPutItem will attempt to convert a PutItemJSON to PutItem
func (put_item_json *PutItemJSON) ToPutItem() (*PutItem, error) {
	if put_item_json == nil {
		return nil, errors.New("receiver is nil")
	}
	a, cerr := attributevalue.InterfaceToAttributeValueMap(put_item_json.Item)
	if cerr != nil {
		return nil, cerr
	}
	p := NewPutItem()
	p.ConditionExpression = put_item_json.ConditionExpression
	p.ConditionalOperator = put_item_json.ConditionalOperator
	p.Expected = put_item_json.Expected
	p.ExpressionAttributeNames = put_item_json.ExpressionAttributeNames
	p.ExpressionAttributeValues = put_item_json.ExpressionAttributeValues
	p.Item = item.Item(a)
	p.ReturnConsumedCapacity = put_item_json.ReturnConsumedCapacity
	p.ReturnItemCollectionMetrics = put_item_json.ReturnItemCollectionMetrics
	p.ReturnValues = put_item_json.ReturnValues
	p.TableName = put_item_json.TableName
	return p, nil
}