internal static Dictionary <string, AttributeValue> ConvertToAttributeValues( Dictionary <string, DynamoDBEntry> valueMap, Table table) { var convertedValues = new Dictionary <string, AttributeValue>(); if (valueMap != null) { foreach (var kvp in valueMap) { var attributeName = kvp.Key; var entry = kvp.Value; if (entry == null) { convertedValues[attributeName] = new AttributeValue { NULL = true } } ; else { if (table.StoreAsEpoch.Contains(attributeName)) { entry = Document.DateTimeToEpochSeconds(entry, attributeName); } var attributeConversionConfig = new DynamoDBEntry.AttributeConversionConfig(table.Conversion, table.IsEmptyStringValueEnabled); convertedValues[attributeName] = entry.ConvertToAttributeValue(attributeConversionConfig); } } } return(convertedValues); }
private static Primitive KeyDateTimeToEpochSeconds(Primitive key, string attributeName) { DynamoDBEntry entry = Document.DateTimeToEpochSeconds(key, attributeName); Primitive converted = entry as Primitive; return(converted); }
/// <summary> /// Converts the FilterCondition to the Amazon.DynamoDBv2.Model.Condition object. /// </summary> /// <param name="conversion"></param> /// <param name="shouldConvertToEpochSeconds"></param> /// <returns></returns> public Condition ToCondition(DynamoDBEntryConversion conversion, bool shouldConvertToEpochSeconds, string attributeName) { var attributeValues = AttributeValues; if (attributeValues == null) { attributeValues = new List <AttributeValue>(); for (int i = 0; i < DynamoDBEntries.Count; i++) { var entry = DynamoDBEntries[i]; if (shouldConvertToEpochSeconds) { entry = Document.DateTimeToEpochSeconds(entry, attributeName); } var attributeValue = entry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion)); attributeValues.Add(attributeValue); } } var condition = new Condition { ComparisonOperator = ComparisonOperator, AttributeValueList = attributeValues }; return(condition); }
internal Key MakeKey(IDictionary <string, DynamoDBEntry> doc) { Key key = new Key(); foreach (var kvp in Keys) { string keyName = kvp.Key; KeyDescription description = kvp.Value; DynamoDBEntry value; if (!doc.TryGetValue(keyName, out value)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Document does not contain value for key {0}", keyName)); } value = value.ToConvertedEntry(Conversion); if (StoreAsEpoch.Contains(keyName)) { value = Document.DateTimeToEpochSeconds(value, keyName); } Primitive primitive = value.AsPrimitive(); if (primitive == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Key attribute {0} must be a Primitive type", keyName)); } if (primitive.Type != description.Type) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Key attribute {0} must be of type {1}", keyName, description.Type)); } key[keyName] = primitive.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(Conversion)); } return(key); }
private Dictionary <string, ExpectedAttributeValue> ToExpectedAttributeMap(DynamoDBEntryConversion conversion, IEnumerable <string> epochAttributes, bool isEmptyStringValueEnabled) { Dictionary <string, ExpectedAttributeValue> ret = new Dictionary <string, ExpectedAttributeValue>(); foreach (var kvp in ExpectedValues) { string attributeName = kvp.Key; ExpectedValue expectedValue = kvp.Value; ExpectedAttributeValue eav; if (epochAttributes != null && epochAttributes.Contains(attributeName)) { var values = expectedValue.Values.Select(p => Document.DateTimeToEpochSeconds(p, attributeName)).ToList(); eav = ExpectedValue.ToExpectedAttributeValue(expectedValue.Exists, values, expectedValue.Comparison, conversion, isEmptyStringValueEnabled); } else { eav = expectedValue.ToExpectedAttributeValue(conversion, isEmptyStringValueEnabled); } ret[attributeName] = eav; } return(ret); }