Skip to content

Instantly share code, notes, and snippets.

@thiagocaiubi
Created March 27, 2017 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagocaiubi/52cd04f67832a4371218172c17da30d3 to your computer and use it in GitHub Desktop.
Save thiagocaiubi/52cd04f67832a4371218172c17da30d3 to your computer and use it in GitHub Desktop.
const vogels = require('vogels');
const Joi = require('joi');
const Person = vogels.define('Person', {
hashKey: 'id',
rangeKey: 'birthdate',
timestamps: true,
tableName: 'sandbox-caiubi',
schema: {
id: Joi.string(),
birthdate: Joi.string()
}
});
function paginate(lastEvaluatedKey) {
const pagination = Person.scan()
.where('birthdate')
.gte('2017')
.limit(5);
if (lastEvaluatedKey) {
pagination.startKey(lastEvaluatedKey.id, lastEvaluatedKey.birthdate);
}
pagination.exec((err, data) => {
if (err) {
console.error(err);
return;
}
console.log(`Length ${data.Items.length} should be equal to ${data.Count}. Starting at ${JSON.stringify(lastEvaluatedKey)}. Scanned count: ${data.Count}`);
if (data.LastEvaluatedKey) {
paginate(data.LastEvaluatedKey);
}
});
}
paginate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment