Parsing dynamo-db-request for an object

I use DynamoDB to query a table with the following commands

QueryRequest request = new QueryRequest
{
   TableName = "Events",
   ExclusiveStartKey = startKey,
   KeyConditions = keyConditions,
   IndexName = "Title-index" // Specify the index to query against
};
// Issue request
QueryResponse result = client.Query(request);

Exceptional StartKey and Keyconditions are predefined

The problem is that the result variable QueryResult is not processed by my own object, when I use DynamoDB.Context, you apply the method with the expected type, but in this case I need to parse QueryResult ... Is there any other way to do this? Or should I parse the object?

+3
source share
3 answers

Take a look at examples from Querying Tables Using the AWS SDK for .NET Low Level API Documentation

In your processing method

var response = client.Query(request);
var result = response.QueryResult;

foreach (Dictionary<string, AttributeValue> item in response.QueryResult.Items)
{
  // Process the result.
  PrintItem(item);
} 

PrintItem

private static void PrintItem(Dictionary<string, AttributeValue> attributeList)
    {
      foreach (KeyValuePair<string, AttributeValue> kvp in attributeList)
      {
        string attributeName = kvp.Key;
        AttributeValue value = kvp.Value;

        Console.WriteLine(
            attributeName + " " +
            (value.S == null ? "" : "S=[" + value.S + "]") +
            (value.N == null ? "" : "N=[" + value.N + "]") +
            (value.SS == null ? "" : "SS=[" + string.Join(",", value.SS.ToArray()) + "]") +
            (value.NS == null ? "" : "NS=[" + string.Join(",", value.NS.ToArray()) + "]")
        );
      }
      Console.WriteLine("************************************************");
    }
0
source

- :

// Issue request
QueryResponse result = AmazonDynamoDBClient.Query(request);

var items = result.Items.FirstOrDefault();

var doc = Document.FromAttributeMap(items);

var myModel = DynamoDBContext.FromDocument<MyModelType>(doc);
+13

What you want is a kind of ORM - good reading Using Amazon DynamoDB Object Persistence Framework . Also check out the API link , which also shows samples

0
source

All Articles