0.9.7 • Published 8 years ago

repository-dynamodb v0.9.7

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

repository.dynamodb

A generic repository pattern for dynamodb written for node.js

Usage

Construct the Repository using the aws region, dynamoDb table name, name of the id key and optionally name of the range key.

With both id and range

let Repository = require('repository-dynamodb');
let repository = new Repository('eu-west-1', 'tableone', 'id', 'range');

With just id

let Repository = require('repository-dynamodb');
let repository= new Repository('eu-west-1', 'tableone', 'id');

API

repository.findBy(id, range, callback);
repository.findBy(id, callback);
repository.addOrReplace(item, callback);
repository.removeBy(id, range, callback);
repository.removeBy(id, callback);

Extending

If you want to provide an additional function specific to your repository, the dynamodb docClient is provided:

repository.listCurrentArticles = function scanDynamoDbForCurrentArticles(callback) {
    let params = {
        TableName: 'news',
        ExpressionAttributeNames: {
            "#D": "date",
            "#E": "expiration"
        },
        ExpressionAttributeValues: {
            ":NOW": new Date().toISOString()
        },
        FilterExpression: ':NOW between #D and #E'
    };
    this.docClient.scan(params, callback);
};
0.9.7

8 years ago

0.9.6

8 years ago

0.9.5

8 years ago

0.9.4

8 years ago