Reputation: 1098
I need to store some complex objects in Dynamodb in my IOS mobile application developed with Swift. AS of now What I'm doing is converting the existing object in to a Json String using a third party support, and storing it in a Dynamodb column as a string. And when I want to read it back, I read the json string from the DynamoDB column as a string, and convert it back to the object that I want.
Is this the best way to store objects in Dynamodb when using AWS-SDK-Swift? is there any other support for storing json strings in DynamoDB?
eg:-
class Mark
{
var Subject :String?
var Score :Int
}
class Student:AWSDynamoDBObjectModel ,AWSDynamoDBModeling
{
var Name :String?
var SID :Int
var Grade :Int
var Dob :String?
var Results :[Mark] =[]
......
}
is it possible to save this object directly in to the database? with having the Results array inside?
Upvotes: 1
Views: 752
Reputation:
Yes DynamoDB can store JSON like objects to the database.
From the developers guide:
Document Data Types:
DynamoDB supports List and Map data types, which can be nested to represent complex data structures.
A List type contains an ordered collection of values. A Map type contains an unordered collection of name-value pairs. Lists and maps are ideal for storing JSON documents. The List data type is similar to a JSON array, and the Map data type is similar to a JSON object. There are no restrictions on the data types that can be stored in List or Map elements, and the elements do not have to be of the same type.
The following example shows a Map that contains a String, a Number, and a nested List (which itself contains another Map).
[1]: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html
You can use a NSDictionary and it will save as a map if i remember correctly.
Upvotes: 2