Skip to content

Instantly share code, notes, and snippets.

@rclark
Last active January 12, 2016 22:15
Show Gist options
  • Save rclark/c652191b855f3bba3a30 to your computer and use it in GitHub Desktop.
Save rclark/c652191b855f3bba3a30 to your computer and use it in GitHub Desktop.
var live = process.argv[2] === 'live';
var table = {
AttributeDefinitions: [
{ AttributeName: "collection", AttributeType: "S" },
{ AttributeName: "created", AttributeType: "N" },
{ AttributeName: "id", AttributeType: "S" }
],
GlobalSecondaryIndexes: [
{
IndexName: "id-index",
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { WriteCapacityUnits: 5, ReadCapacityUnits: 5 },
KeySchema: [{ KeyType: "HASH", AttributeName: "id" }]
},
{
IndexName: "created-index",
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { WriteCapacityUnits: 5, ReadCapacityUnits: 5 },
KeySchema: [
{ KeyType: "HASH", AttributeName: "collection" },
{ KeyType: "RANGE", AttributeName: "created" }
]
}
],
ProvisionedThroughput: { WriteCapacityUnits: 5, ReadCapacityUnits: 5 },
KeySchema: [
{ KeyType: "HASH", AttributeName: "collection" },
{ KeyType: "RANGE", AttributeName: "id" }
]
};
var dynamodb = require('dynamodb-test')(require('tape'), 'overlap-test', table, live ? 'us-east-1' : undefined);
var fixtures = [];
var rightnow = Date.now();
for (var i = 0; i < 100; i++) fixtures.push({
collection: 'my-things',
id: i.toString(),
created: rightnow
});
// create the table
dynamodb.start();
// empty the table, load fixtures, then run the callback function
dynamodb.test('paginatificate', fixtures, function(assert) {
var items = 0;
(function list(start) {
var params = {
TableName: dynamodb.tableName,
KeyConditions: {
collection: {
ComparisonOperator: 'EQ',
AttributeValueList: ['my-things']
}
},
IndexName: 'created-index',
Limit: 10
};
if (start) params.ExclusiveStartKey = start;
dynamodb.dyno.query(params, function(err, data) {
assert.ifError(err, 'fetched a page');
items += data.Items.length;
if (data.LastEvaluatedKey) return list(data.LastEvaluatedKey);
assert.equal(items, 100, 'found 100 items');
assert.end();
});
})();
});
// cleanup
dynamodb.delete();
if (!live) dynamodb.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment