5
5
namespace Dynatello . Builders ;
6
6
7
7
/// <summary>
8
- /// A record based builder for creating <see cref="PutItemRequest"/> that can be configured via the `with` syntax.
8
+ /// A record based builder for creating <see cref="PutItemRequest" /> that can be configured via the `with` syntax.
9
9
/// </summary>
10
- public readonly record struct PutRequestBuilder < T , TReferences , TArgumentReferences >
11
- where TReferences : IAttributeExpressionNameTracker
12
- where TArgumentReferences : IAttributeExpressionValueTracker < T >
10
+ public readonly record struct PutRequestBuilder < T >
13
11
{
14
- private readonly Func < TReferences > _ref ;
15
- private readonly Func < TArgumentReferences > _argRef ;
12
+ private readonly Func < T , IAttributeExpression > ? _attributeExpressionSelector ;
16
13
private readonly Func < T , Dictionary < string , AttributeValue > > _marshall ;
14
+ private readonly ReturnConsumedCapacity _returnConsumedCapacity = ReturnConsumedCapacity . NONE ;
15
+ private readonly ReturnItemCollectionMetrics _returnItemCollectionMetrics = ReturnItemCollectionMetrics . NONE ;
16
+
17
+ private readonly ReturnValue _returnValues = ReturnValue . NONE ;
18
+
19
+ private readonly ReturnValuesOnConditionCheckFailure _returnValuesOnConditionCheckFailure =
20
+ ReturnValuesOnConditionCheckFailure . NONE ;
21
+
22
+ private readonly string _tableName ;
23
+
24
+
25
+ internal PutRequestBuilder (
26
+ Func < T , IAttributeExpression > ? attributeExpressionSelector ,
27
+ Func < T , Dictionary < string , AttributeValue > > marshall ,
28
+ string tableName
29
+ )
30
+ {
31
+ _attributeExpressionSelector = attributeExpressionSelector ;
32
+ _marshall = marshall ;
33
+ _tableName = tableName ;
34
+ }
17
35
18
36
/// <summary>
19
- ///
20
37
/// </summary>
21
38
public string TableName
22
39
{
23
40
get => _tableName ;
24
41
init => _tableName = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
25
42
}
26
43
27
- private readonly ReturnValue _returnValues = ReturnValue . NONE ;
28
- private readonly ReturnConsumedCapacity _returnConsumedCapacity = ReturnConsumedCapacity . NONE ;
29
- private readonly ReturnItemCollectionMetrics _returnItemCollectionMetrics = ReturnItemCollectionMetrics . NONE ;
30
-
31
- private readonly ReturnValuesOnConditionCheckFailure _returnValuesOnConditionCheckFailure =
32
- ReturnValuesOnConditionCheckFailure . NONE ;
33
-
34
- private readonly string _tableName ;
35
-
36
- /// <inheritdoc cref="PutItemRequest.ReturnValues"/>
44
+ /// <inheritdoc cref="PutItemRequest.ReturnValues" />
37
45
public ReturnValue ReturnValues
38
46
{
39
47
get => _returnValues ;
40
48
init => _returnValues = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
41
49
}
42
50
43
- /// <inheritdoc cref="PutItemRequest.ReturnConsumedCapacity"/>
51
+ /// <inheritdoc cref="PutItemRequest.ReturnConsumedCapacity" />
44
52
public ReturnConsumedCapacity ReturnConsumedCapacity
45
53
{
46
54
get => _returnConsumedCapacity ;
47
55
init => _returnConsumedCapacity = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
48
56
}
49
57
50
- /// <inheritdoc cref="PutItemRequest.ReturnItemCollectionMetrics"/>
58
+ /// <inheritdoc cref="PutItemRequest.ReturnItemCollectionMetrics" />
51
59
public ReturnItemCollectionMetrics ReturnItemCollectionMetrics
52
60
{
53
61
get => _returnItemCollectionMetrics ;
54
62
init => _returnItemCollectionMetrics = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
55
63
}
56
64
57
- /// <inheritdoc cref="PutItemRequest.ReturnValuesOnConditionCheckFailure"/>
65
+ /// <inheritdoc cref="PutItemRequest.ReturnValuesOnConditionCheckFailure" />
58
66
public ReturnValuesOnConditionCheckFailure ReturnValuesOnConditionCheckFailure
59
67
{
60
68
get => _returnValuesOnConditionCheckFailure ;
61
69
init => _returnValuesOnConditionCheckFailure = value ?? throw new ArgumentNullException ( nameof ( value ) ) ;
62
70
}
63
71
64
- /// <summary>
65
- /// A optional function to perform string interpolation in order to create the <see cref="UpdateItemRequest.ConditionExpression"/>.
66
- /// </summary>
67
- public Func < TReferences , TArgumentReferences , string > ? Condition { get ; init ; }
68
-
69
- public PutRequestBuilder (
70
- Func < TReferences > @ref ,
71
- Func < TArgumentReferences > argRef ,
72
- Func < T , Dictionary < string , AttributeValue > > marshall ,
73
- string tableName
74
- )
75
- {
76
- _ref = @ref ;
77
- _argRef = argRef ;
78
- _marshall = marshall ;
79
- _tableName = tableName ;
80
- Condition = null ;
81
- }
82
-
83
72
84
73
public PutItemRequest Build ( T element )
85
74
{
@@ -98,12 +87,9 @@ public PutItemRequest Build(T element)
98
87
ExpressionAttributeValues = null
99
88
} ;
100
89
101
- if ( Condition is null ) return request ;
102
-
90
+ if ( _attributeExpressionSelector is null ) return request ;
91
+ var attributeExpression = _attributeExpressionSelector ( element ) ;
103
92
104
- var attributeExpression =
105
- DynamoDBGenerator . Extensions . DynamoDBMarshallerExtensions . ToAttributeExpression ( _ref , _argRef , element ,
106
- Condition ) ;
107
93
request . ExpressionAttributeNames = attributeExpression . Names ;
108
94
request . ExpressionAttributeValues = attributeExpression . Values ;
109
95
request . ConditionExpression = attributeExpression . Expressions [ 0 ] ;
0 commit comments