date

 avatar
unknown
javascript
3 years ago
1.3 kB
5
Indexable
    const params = {
      ExpressionAttributeValues: {
        ':pkValue': `TENANT#${tenantUuid}#ACADEMIC_CALENDAR_SCHOOL_DATE_RELATION`,
        ':skValue': 'ACADEMIC_CALENDAR_SCHOOL_DATE_RELATION',
        ':schoolDate': '2022-09',
        ':academicCalendarId': 10595,
      },
      KeyConditionExpression: 'pk = :pkValue AND begins_with(sk, :skValue)',
      FilterExpression: 'attribute_not_exists(deleted_at) AND academic_calendar_id = :academicCalendarId AND begins_with(school_date, :schoolDate)',
      TableName: 'date',
    };

    let dates = [];
    let lastEvaluatedKey = null;

    do {

      // Start Key To Query (Like Offset In SQL)
      if (lastEvaluatedKey) {
        params.ExclusiveStartKey = {
          'pk': lastEvaluatedKey.pk,
          'sk': lastEvaluatedKey.sk,
        };
      }

      // Get Query Result
      const result = await dynamoDB.query(params).promise();
      // console.log('lel', result);

      // If Last Evaluated Key Exists it Means There is Still Data on DynamoDB
      lastEvaluatedKey =
        typeof result.LastEvaluatedKey !== 'undefined' ? result.LastEvaluatedKey : null;

      // Merge Query Data to Questions
      dates = [...dates, ...result.Items];

    } while(lastEvaluatedKey);
Editor is loading...