當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript aws-sdk.DynamoDB.DocumentClient類代碼示例

本文整理匯總了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')
}
開發者ID:bradzacher,項目名稱:zacher-home,代碼行數:19,代碼來源:putData.ts

示例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
}
開發者ID:bradzacher,項目名稱:zacher-home,代碼行數:24,代碼來源:getDataFromDynamo.ts

示例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)
  })
}
開發者ID:byung82,項目名稱:examples,代碼行數:37,代碼來源:create.ts


注:本文中的aws-sdk.DynamoDB.DocumentClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。