1
+ using Amazon . DynamoDBv2 ;
1
2
using Amazon . DynamoDBv2 . Model ;
2
3
using DynamoDBGenerator ;
3
4
4
5
namespace Dynatello . Builders ;
5
6
6
- public readonly record struct QueryRequestBuilder < TArg , TReferences , TArgumentReferences >
7
- where TReferences : IAttributeExpressionNameTracker
8
- where TArgumentReferences : IAttributeExpressionValueTracker < TArg >
7
+ public readonly record struct QueryRequestBuilder < T >
9
8
{
10
- private readonly TArg _arg ;
11
- private readonly IDynamoDBKeyMarshaller _keyMarshaller ;
9
+ private readonly Func < T , IAttributeExpression > _attributeExpressionSelector ;
12
10
13
- internal QueryRequestBuilder ( IDynamoDBKeyMarshaller keyMarshaller , TArg arg )
11
+ /// <inheritdoc cref="QueryRequest.TableName"/>
12
+ public string TableName { get ; init ; }
13
+
14
+ /// <inheritdoc cref="QueryRequest.IndexName"/>
15
+ public string ? IndexName { get ; init ; }
16
+
17
+ /// <inheritdoc cref="QueryRequest.Limit"/>
18
+ public int ? Limit { get ; init ; }
19
+
20
+ /// <inheritdoc cref="QueryRequest.ConsistentRead"/>
21
+ public bool ConsistentRead { get ; init ; }
22
+
23
+ /// <inheritdoc cref="QueryRequest.ScanIndexForward"/>
24
+ public bool ScanIndexForward { get ; init ; }
25
+
26
+ /// <inheritdoc cref="QueryRequest.Select"/>
27
+ public Select Select { get ; init ; }
28
+
29
+ /// <inheritdoc cref="QueryRequest.ReturnConsumedCapacity"/>
30
+ public ReturnConsumedCapacity ReturnConsumedCapacity { get ; init ; }
31
+
32
+ public QueryRequestBuilder ( Func < T , IAttributeExpression > attributeExpressionSelector , string tableName )
14
33
{
15
- _keyMarshaller = keyMarshaller ;
16
- _arg = arg ;
34
+ _attributeExpressionSelector = attributeExpressionSelector ;
35
+ TableName = tableName ;
36
+ IndexName = null ;
37
+ Limit = null ;
38
+ ConsistentRead = false ;
39
+ Select = Select . ALL_ATTRIBUTES ;
40
+ ReturnConsumedCapacity = ReturnConsumedCapacity . NONE ;
41
+ ScanIndexForward = true ;
17
42
}
18
43
19
- internal QueryRequest Build ( )
44
+ public QueryRequest Build ( T arg )
20
45
{
21
- return new QueryRequest
46
+ var attributeExpression = _attributeExpressionSelector ( arg ) ;
47
+
48
+ var queryRequest = new QueryRequest
22
49
{
23
50
AttributesToGet = null ,
24
51
QueryFilter = null ,
25
52
ConditionalOperator = null ,
26
- KeyConditions = null
53
+ KeyConditions = null ,
54
+ KeyConditionExpression = attributeExpression . Expressions [ 0 ] ,
55
+ ExpressionAttributeValues = attributeExpression . Values ,
56
+ ExpressionAttributeNames = attributeExpression . Names ,
57
+ TableName = TableName ,
58
+ IndexName = IndexName ,
59
+ ConsistentRead = ConsistentRead ,
60
+ Select = Select ,
61
+ ReturnConsumedCapacity = ReturnConsumedCapacity ,
62
+ ScanIndexForward = ScanIndexForward ,
63
+ ProjectionExpression = null
27
64
} ;
65
+
66
+ if ( Limit is { } limit )
67
+ queryRequest . Limit = limit ;
68
+
69
+ if ( attributeExpression . Expressions . Count == 2 )
70
+ queryRequest . FilterExpression = attributeExpression . Expressions [ 1 ] ;
71
+
72
+ return queryRequest ;
28
73
}
29
74
}
0 commit comments