-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathdynamodb.ts
104 lines (88 loc) · 2.45 KB
/
dynamodb.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import DynamoDB = require('../clients/dynamodb');
const client: DynamoDB.DocumentClient = new DynamoDB.DocumentClient({
region: 'us-west-2',
apiVersion: '2012-08-10',
signatureVersion: 'v4',
dynamoDbCrc32: false,
});
const params: DynamoDB.DocumentClient.GetItemInput = {
TableName: 'MyTable',
Key: {
'my-key': 'value'
}
};
const set: DynamoDB.DocumentClient.DynamoDbSet = client.createSet(['string']);
if (set.type === 'String') {
const string: string|undefined = set.values.pop();
} else if (set.type === 'Number') {
const number: number|undefined = set.values.pop();
} else {
const binary: DynamoDB.DocumentClient.binaryType|undefined = set.values.pop();
}
const converter: DynamoDB.Converter = DynamoDB.Converter;
const options: DynamoDB.Converter.ConverterOptions = {
convertEmptyValues: true,
};
const av: DynamoDB.AttributeValue = DynamoDB.Converter.input('string', options);
const record: DynamoDB.AttributeMap = DynamoDB.Converter.marshall(
{
string: 'foo',
list: ['fizz', 'buzz', 'pop'],
map: {
nestedMap: {
key: 'value',
},
},
number: 123,
nullValue: null,
boolValue: true,
stringSet: client.createSet(['foo', 'bar', 'baz']),
buffer: Uint8Array.from([0xde, 0xad, 0xbe, 0xef]),
},
options
);
const jsType: any = DynamoDB.Converter.output({ S: 'string' });
const jsObject: {[key: string]: any} = DynamoDB.Converter.unmarshall({
string: {S: 'foo'},
list: {L: [{S: 'fizz'}, {S: 'buzz'}, {S: 'pop'}]},
map: {
M: {
nestedMap: {
M: {
key: {S: 'value'},
},
},
},
},
number: {N: '123'},
nullValue: {NULL: true},
boolValue: {BOOL: true},
stringSet: {SS: ['foo', 'bar', 'baz']},
buffer: {B: 'base64+encoded+text'},
});
client.get(params, (err, data) => {
});
const dynamodb = new DynamoDB(<DynamoDB.ClientConfiguration>{
apiVersion: "2012-08-10"
});
const getParams: DynamoDB.GetItemInput = {
TableName: 'MyTable',
Key: {
'my-key': {
S: 'value'
}
}
};
dynamodb.getItem(getParams, (err, data) => {
});
// Still works with Types namespace as well
const getParams2: DynamoDB.Types.GetItemInput = {
TableName: 'MyTable',
Key: {
'my-key': {
S: 'value'
}
}
};
dynamodb.getItem(getParams2, (err, data) => {
});