5. DynamoDB APIが便利な理由その2
アノテーションで細かな振る舞いを指定できる
[DynamoDBTable("EXAMPLE_TABLE")] // テーブル名のマッピング
public class IntegrationExample{
[DynamoDBHashKey]
public string RoomId;
[DynamoDBRangeKey]
public string Created;
[DynamoDBProperty("Message")] // カラム名のマッピング
public string TextMessage;
[DynamoDBIgnore]
public bool SomeFlag; // DinamoDBIgnore属性は無視される
private int _counter; // privateフィールドは無視される
}
6. DynamoDB APIが便利な理由その3
Global Secondary Index / Local Secondary Indexに対応
[DynamoDBTable("EXAMPLE_TABLE")] // テーブル名のマッピング
public class IntegrationExample{
[DynamoDBHashKey]
public string RoomId;
[DynamoDBRangeKey]
public string Created;
[DynamoDBProperty("Message")] // カラム名のマッピング
public string TextMessage;
[DynamoDBIgnore]
public bool SomeFlag; // DinamoDBIgnore属性は無視される
private int _counter; // privateフィールドは無視される
[DynamoDBGlobalSecondaryIndexHashKey("GSI-Key-Name")]
public string UserId;
[DynamoDBGlobalSecondaryIndexRangeKey("GSI-Key-Name")]
public string SomeRange;
}
別条件での検索と
そのページめくりに使用
7. DynamoDB APIが便利な理由その4
独自のConverterを指定できる
[DynamoDBProperty(typeof(DimensionTypeConverter))]
public DimensionType Dimensions;
public class DimensionType {
public decimal Length;
public decimal Height;
public decimal Thickness;
}
// 寸法文字列 "8.5x11x.05" を DimensionType に変換
public class DimensionTypeConverter : IPropertyConverter {
public object FromEntry(DynamoDBEntry entry) {
Primitive primitive = entry as Primitive;
string[] data = ((string)(primitive.Value)).Split(new string[] { " x " }, StringSplitOptions.None);
if (data.Length != 3) throw new ArgumentOutOfRangeException();
DimensionType complexData = new DimensionType {
Length = Convert.ToDecimal(data[0]),
Height = Convert.ToDecimal(data[1]),
Thickness = Convert.ToDecimal(data[2])
};
return complexData;
}
}
8. DynamoDB APIが便利な理由その5
複雑なオブジェクトにも対応
[DynamoDBTable("IntegrationExample")]
public class IntegrationExample{
[DynamoDBProperty(typeof(ListOfDocumentTypeConverter))]
public List<Document> Books;
[DynamoDBProperty]
public Dictionary<string,string> EJDictionary;
}
// 参照方法
Debug.Log(result.Response.Books[0]["Author"]); // Yamada Taro
Debug.Log(result.Response.EJDictionary["apple"]); // ringo
DynamoDBのカラムの例
VBのVariant型のようなもの
Dictionaryに対応
23. ②アノテーションで細かな振る舞いを指定できる
[DynamoDBTable("EXAMPLE_TABLE")] // テーブル名のマッピング
public class IntegrationExample{
[DynamoDBHashKey]
public string RoomId;
[DynamoDBRangeKey]
public string Created;
[DynamoDBProperty("Message")] // カラム名のマッピング
public string TextMessage;
[DynamoDBIgnore]
public bool SomeFlag; // DinamoDBIgnore属性は無視される
private int _counter; // privateフィールドは無視される
}
24. ③Global Secondary Index / Local Secondary Indexに対応
[DynamoDBTable("EXAMPLE_TABLE")] // テーブル名のマッピング
public class IntegrationExample{
[DynamoDBHashKey]
public string RoomId;
[DynamoDBRangeKey]
public string Created;
[DynamoDBProperty("Message")] // カラム名のマッピング
public string TextMessage;
[DynamoDBIgnore]
public bool SomeFlag; // DinamoDBIgnore属性は無視される
private int _counter; // privateフィールドは無視される
[DynamoDBGlobalSecondaryIndexHashKey("GSI-Key-Name")]
public string UserId;
[DynamoDBGlobalSecondaryIndexRangeKey("GSI-Key-Name")]
public string SomeRange;
}
別条件での検索と
そのページめくりに使用
25. ④独自のConverterを指定できる
[DynamoDBProperty(typeof(DimensionTypeConverter))]
public DimensionType Dimensions;
public class DimensionType {
public decimal Length;
public decimal Height;
public decimal Thickness;
}
// 寸法文字列 "8.5x11x.05" を DimensionType に変換
public class DimensionTypeConverter : IPropertyConverter {
public object FromEntry(DynamoDBEntry entry) {
Primitive primitive = entry as Primitive;
string[] data = ((string)(primitive.Value)).Split(new string[] { " x " }, StringSplitOptions.None);
if (data.Length != 3) throw new ArgumentOutOfRangeException();
DimensionType complexData = new DimensionType {
Length = Convert.ToDecimal(data[0]),
Height = Convert.ToDecimal(data[1]),
Thickness = Convert.ToDecimal(data[2])
};
return complexData;
}
}