本文整理汇总了TypeScript中aws-sdk.DynamoDB.DocumentClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript DynamoDB.DocumentClient类的具体用法?TypeScript DynamoDB.DocumentClient怎么用?TypeScript DynamoDB.DocumentClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DynamoDB.DocumentClient类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: putData
async function putData(data : WakatimeDynamoData) {
const dynamo = new DynamoDB.DocumentClient({
region: 'ap-southeast-2',
})
const res = await dynamo
.put({
Item: data,
TableName: 'Zacher.com.au',
})
.promise()
if (res.$response.error) {
console.error(res.$response.error)
throw new Error('Unable to update wakatime data')
}
console.info('Updated Wakatime data in DynamoDB')
}
示例2: getWakatimeData
async function getWakatimeData() {
const dynamo = new DynamoDB.DocumentClient({
region: 'ap-southeast-2',
})
const item = await dynamo
.get({
Key: {
CacheKey: 'WakatimeStats',
},
TableName: 'Zacher.com.au',
})
.promise()
if (!item.Item) {
console.error(item.$response.error)
throw new Error('Unable to get stored wakatime data')
}
const itemData = item.Item as WakatimeDynamoData
console.info('Fetched old Wakatime data updated on', itemData.LastReadEnd)
return item.Item as WakatimeDynamoData
}
示例3: Date
module.exports.create = (event, context, callback) => {
const timestamp = new Date().getTime()
const data = JSON.parse(event.body)
if (typeof data.text !== 'string') {
console.error('Validation Failed')
callback(new Error('Couldn\'t create the todo item.'))
return
}
const params = {
TableName: process.env.DYNAMODB_TABLE,
Item: {
id: uuid.v1(),
text: data.text,
checked: false,
createdAt: timestamp,
updatedAt: timestamp
}
}
// write the todo to the database
dynamoDb.put(params, (error, result) => {
// handle potential errors
if (error) {
console.error(error)
callback(new Error('Couldn\'t create the todo item.'))
return
}
// create a response
const response = {
statusCode: 200,
body: JSON.stringify(result.Item)
}
callback(null, response)
})
}