-
Notifications
You must be signed in to change notification settings - Fork 869
Features/dynamo db update behavior attribute #4049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"services": [ | ||
{ | ||
"serviceName": "DynamoDBv2", | ||
"type": "minor", | ||
"changeLogMessages": [ | ||
"Add support for DynamoDbUpdateBehavior for operations." | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
@@ -375,31 +375,35 @@ public IMultiTableTransactWrite CreateMultiTableTransactWrite(params ITransactWr | |
|
||
Document updateDocument; | ||
Expression versionExpression = null; | ||
|
||
var returnValues=counterConditionExpression == null ? ReturnValues.None : ReturnValues.AllNewAttributes; | ||
|
||
if ((flatConfig.SkipVersionCheck.HasValue && flatConfig.SkipVersionCheck.Value) || !storage.Config.HasVersion) | ||
var updateIfNotExistsAttributeName = GetUpdateIfNotExistsAttributeNames(storage); | ||
|
||
var returnValues = counterConditionExpression == null && !updateIfNotExistsAttributeName.Any() | ||
? ReturnValues.None | ||
: ReturnValues.AllNewAttributes; | ||
Comment on lines
+381
to
+383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value logic now includes Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
var updateItemOperationConfig = new UpdateItemOperationConfig | ||
{ | ||
updateDocument = table.UpdateHelper(storage.Document, table.MakeKey(storage.Document), new UpdateItemOperationConfig() | ||
{ | ||
ReturnValues = returnValues | ||
}, counterConditionExpression); | ||
} | ||
else | ||
ReturnValues = returnValues | ||
}; | ||
|
||
if (!(flatConfig.SkipVersionCheck.HasValue && flatConfig.SkipVersionCheck.Value) && storage.Config.HasVersion) | ||
{ | ||
var conversionConfig = new DynamoDBEntry.AttributeConversionConfig(table.Conversion, table.IsEmptyStringValueEnabled); | ||
var conversionConfig = new DynamoDBEntry.AttributeConversionConfig(table.Conversion, table.IsEmptyStringValueEnabled); | ||
versionExpression = CreateConditionExpressionForVersion(storage, conversionConfig); | ||
SetNewVersion(storage); | ||
|
||
var updateItemOperationConfig = new UpdateItemOperationConfig | ||
{ | ||
ReturnValues = returnValues, | ||
ConditionalExpression = versionExpression, | ||
}; | ||
updateDocument = table.UpdateHelper(storage.Document, table.MakeKey(storage.Document), updateItemOperationConfig, counterConditionExpression); | ||
updateItemOperationConfig.ConditionalExpression = versionExpression; | ||
} | ||
|
||
if (counterConditionExpression == null && versionExpression == null) return; | ||
updateDocument = table.UpdateHelper( | ||
storage.Document, | ||
table.MakeKey(storage.Document), | ||
updateItemOperationConfig, | ||
counterConditionExpression, | ||
updateIfNotExistsAttributeName | ||
); | ||
|
||
if (counterConditionExpression == null && versionExpression == null && !updateIfNotExistsAttributeName.Any()) return; | ||
|
||
if (returnValues == ReturnValues.AllNewAttributes) | ||
{ | ||
|
@@ -428,36 +432,36 @@ private async Task SaveHelperAsync([DynamicallyAccessedMembers(InternalConstants | |
Document updateDocument; | ||
Expression versionExpression = null; | ||
|
||
var returnValues = counterConditionExpression == null ? ReturnValues.None : ReturnValues.AllNewAttributes; | ||
var updateIfNotExistsAttributeName = GetUpdateIfNotExistsAttributeNames(storage); | ||
|
||
var returnValues = counterConditionExpression == null && !updateIfNotExistsAttributeName.Any() | ||
? ReturnValues.None | ||
: ReturnValues.AllNewAttributes; | ||
|
||
if ( | ||
(flatConfig.SkipVersionCheck.HasValue && flatConfig.SkipVersionCheck.Value) | ||
|| !storage.Config.HasVersion) | ||
var updateItemOperationConfig = new UpdateItemOperationConfig | ||
{ | ||
updateDocument = await table.UpdateHelperAsync(storage.Document, table.MakeKey(storage.Document), new UpdateItemOperationConfig | ||
{ | ||
ReturnValues = returnValues | ||
}, counterConditionExpression, cancellationToken).ConfigureAwait(false); | ||
} | ||
else | ||
ReturnValues = returnValues | ||
}; | ||
|
||
if (!(flatConfig.SkipVersionCheck.HasValue && flatConfig.SkipVersionCheck.Value) && storage.Config.HasVersion) | ||
{ | ||
var conversionConfig = new DynamoDBEntry.AttributeConversionConfig(table.Conversion, table.IsEmptyStringValueEnabled); | ||
var conversionConfig = new DynamoDBEntry.AttributeConversionConfig(table.Conversion, table.IsEmptyStringValueEnabled); | ||
versionExpression = CreateConditionExpressionForVersion(storage, conversionConfig); | ||
SetNewVersion(storage); | ||
|
||
updateDocument = await table.UpdateHelperAsync( | ||
storage.Document, | ||
table.MakeKey(storage.Document), | ||
new UpdateItemOperationConfig | ||
{ | ||
ReturnValues = returnValues, | ||
ConditionalExpression = versionExpression | ||
}, counterConditionExpression, | ||
cancellationToken) | ||
.ConfigureAwait(false); | ||
updateItemOperationConfig.ConditionalExpression = versionExpression; | ||
} | ||
|
||
if (counterConditionExpression == null && versionExpression == null && !storage.Config.HasAutogeneratedProperties) return; | ||
updateDocument = await table.UpdateHelperAsync( | ||
storage.Document, | ||
table.MakeKey(storage.Document), | ||
updateItemOperationConfig, | ||
counterConditionExpression, | ||
cancellationToken, | ||
updateIfNotExistsAttributeName | ||
).ConfigureAwait(false); | ||
|
||
|
||
if (counterConditionExpression == null && versionExpression == null && !updateIfNotExistsAttributeName.Any()) return; | ||
|
||
if (returnValues == ReturnValues.AllNewAttributes) | ||
{ | ||
|
@@ -698,4 +702,4 @@ private async Task SaveHelperAsync([DynamicallyAccessedMembers(InternalConstants | |
|
||
#endregion | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation is incomplete and incorrect. It states 'only updated if not null' but the actual behavior is 'only set if the attribute does not exist in DynamoDB'. Update to: 'This attribute can be used to control whether a property is always updated or only set when the item is created (if the attribute does not exist).'
Copilot uses AI. Check for mistakes.