Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing dynamo db queryresponse to object

I'm using 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);

The ExclusiveStartKey and Keyconditions are predefined

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

like image 768
Rukia Kuchiki Avatar asked Nov 27 '22 11:11

Rukia Kuchiki


2 Answers

I ended up using something like:

using System.Linq;

...

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

var items = result.Items.FirstOrDefault();

var doc = Document.FromAttributeMap(items);
   
var myModel = DynamoDBContext.FromDocument<MyModelType>(doc);
like image 90
Lee Gunn Avatar answered Dec 06 '22 19:12

Lee Gunn


What you want is some sort of ORM - a nice read is Using Amazon DynamoDB Object Persistence Framework. Also check out the API reference that also shows samples

like image 33
Chen Harel Avatar answered Dec 06 '22 20:12

Chen Harel