Skip to content

Commit fc6c71f

Browse files
committed
DeleteItemDocumentOperationRequest implementation
wip wip implement sync update method and unit tests PutItemOperationRequest integration tests
1 parent 643e85d commit fc6c71f

File tree

11 files changed

+1572
-217
lines changed

11 files changed

+1572
-217
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "DynamoDBv2",
5+
"type": "minor",
6+
"changeLogMessages": [
7+
"Add Request Object Pattern and Expression-Based for DynamoDB Document Model "
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/DynamoDBv2/Custom/DataModel/DocumentOperationRequest.cs

Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System.Collections.Generic;
2+
3+
namespace Amazon.DynamoDBv2.DocumentModel
4+
{
5+
/// <summary>
6+
/// Base class for requests that perform operations on a document in DynamoDB.
7+
/// </summary>
8+
public abstract class DocumentOperationRequest
9+
{
10+
}
11+
12+
/// <summary>
13+
/// Represents a request to update an item in a DynamoDB table using the Document Model.
14+
/// </summary>
15+
public class UpdateItemDocumentOperationRequest : DocumentOperationRequest
16+
{
17+
/// <summary>
18+
/// Gets or sets the key identifying the item in the table.
19+
/// </summary>
20+
public IDictionary<string, DynamoDBEntry> Key { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the attributes to be updated in the item.
24+
/// </summary>
25+
public Document Document { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the update expression specifying how attributes should be updated.
29+
/// </summary>
30+
public Expression UpdateExpression { get; set; }
31+
32+
/// <summary>
33+
/// The expression that is evaluated before the update is performed. If the expression evaluates to false the update
34+
/// will fail and a ConditionalCheckFailedException exception will be thrown.
35+
/// </summary>
36+
public Expression ConditionalExpression { get; set; }
37+
38+
/// <summary>
39+
/// Flag specifying what values should be returned.
40+
/// </summary>
41+
public ReturnValues ReturnValues { get; set; }
42+
}
43+
44+
/// <summary>
45+
/// Represents a request to delete an item from a DynamoDB table using the Document Model.
46+
/// </summary>
47+
public class DeleteItemDocumentOperationRequest : DocumentOperationRequest
48+
{
49+
/// <summary>
50+
/// Gets or sets the key identifying the item in the table.
51+
/// </summary>
52+
public IDictionary<string, DynamoDBEntry> Key { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the conditional expression specifying when the item should be deleted.
56+
/// </summary>
57+
public Expression ConditionalExpression { get; set; }
58+
59+
/// <summary>
60+
/// Flag specifying what values should be returned.
61+
/// </summary>
62+
public ReturnValues ReturnValues { get; set; }
63+
64+
}
65+
66+
/// <summary>
67+
/// Represents a request to put (create or replace) an item in a DynamoDB table using the Document Model.
68+
/// </summary>
69+
public class PutItemDocumentOperationRequest : DocumentOperationRequest
70+
{
71+
/// <summary>
72+
/// Gets or sets the document to be put in the table.
73+
/// </summary>
74+
public Document Document { get; set; }
75+
76+
/// <summary>
77+
/// Gets or sets the conditional expression specifying when the item should be put.
78+
/// </summary>
79+
public Expression ConditionalExpression { get; set; }
80+
81+
/// <summary>
82+
/// Flag specifying what values should be returned.
83+
/// </summary>
84+
public ReturnValues ReturnValues { get; set; }
85+
}
86+
87+
}

sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Expression.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,41 @@ internal void ApplyExpression(UpdateItemRequest request, Table table)
127127
}
128128
}
129129

130+
internal void ApplyConditionalExpression(UpdateItemRequest request, Table table)
131+
{
132+
request.ConditionExpression = this.ExpressionStatement;
133+
MergeAttributes(request, table);
134+
}
135+
136+
internal void ApplyUpdateExpression(UpdateItemRequest request, Table table)
137+
{
138+
request.UpdateExpression = this.ExpressionStatement;
139+
MergeAttributes(request, table);
140+
}
141+
142+
private void MergeAttributes(UpdateItemRequest request, Table table)
143+
{
144+
var convertToAttributeValues = ConvertToAttributeValues(this.ExpressionAttributeValues, table);
145+
request.ExpressionAttributeValues ??= new Dictionary<string, AttributeValue>(StringComparer.Ordinal);
146+
foreach (var kvp in convertToAttributeValues)
147+
{
148+
request.ExpressionAttributeValues[kvp.Key] = kvp.Value;
149+
}
150+
151+
152+
if (this.ExpressionAttributeNames?.Count > 0)
153+
{
154+
request.ExpressionAttributeNames ??= new Dictionary<string, string>(StringComparer.Ordinal);
155+
foreach (var kvp in this.ExpressionAttributeNames)
156+
{
157+
if (!request.ExpressionAttributeNames.ContainsKey(kvp.Key))
158+
{
159+
request.ExpressionAttributeNames[kvp.Key] = kvp.Value;
160+
}
161+
}
162+
}
163+
}
164+
130165
internal void ApplyExpression(Get request, Table table)
131166
{
132167
request.ProjectionExpression = ExpressionStatement;

0 commit comments

Comments
 (0)