DEV Community

Edisson Ballesteros Aguilar
Edisson Ballesteros Aguilar

Posted on • Edited on

Get Paginated Data DynamoDB

function getLogsNovedades() {

  const getAllData = async (params) => {
    const _getAllData = async (params, startKey) => {
      if (startKey) {
        params.ExclusiveStartKey = startKey
      }
      return dynamodb.query(params).promise();
    }
    let lastEvaluatedKey = null
    let rows = []
    do {
      const result = await _getAllData(params, lastEvaluatedKey)
      rows = rows.concat(result.Items)
      lastEvaluatedKey = result.LastEvaluatedKey
    } while (lastEvaluatedKey)
    return rows
  }

  var params = {
    TableName: tableName,
    ProjectionExpression: "Id, #Type, #Data, IDPV, #Name, #Timestamp",
    IndexName: 'Type-index',
    KeyConditionExpression: '#Type = :tp',
    ExpressionAttributeNames: {
      '#Type': 'Type',
      '#Data': 'Data',
      '#Name': 'Name',
      '#Timestamp': 'Timestamp'
    },
    ExpressionAttributeValues: {
      ':tp': 'NOVEDAD',
    },
    Limit: 100
  };

  return new Promise(async (resolve, reject) => {
    try {
      let Items = await getAllData(params);
      resolve(Items);
    } catch (err) {
      reject(err);
    }
  });
}
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay