Skip to content

Instantly share code, notes, and snippets.

@snmmaurya
Created October 25, 2018 09:04
Show Gist options
  • Save snmmaurya/d91a4ef4f6d7fc15ae66e42843ccb69e to your computer and use it in GitHub Desktop.
Save snmmaurya/d91a4ef4f6d7fc15ae66e42843ccb69e to your computer and use it in GitHub Desktop.
node dynamodb implementation
References: https://www.npmjs.com/package/dynamoose and https://dynamoosejs.com/api
Steps to start with dynamoose-
install dynamoose
npm install dynamoose
configure your dynamodb under aws DynamoDB service.
get required credentials -
1) key
2) secret
3) reason
create file config/dynamodb.rb
var dynamoose = require('dynamoose');
dynamoose.AWS.config.update({
accessKeyId: aws_dynamodb_access_key,
secretAccessKey: aws_dynamodb_secret_key,
region: process.env.aws_dynamodb_region,
});
module.exports = dynamoose;
Create file dynamodb/user.rb
// include configuration file
const dynamoose = require('../config/dynamodb')
// Create User model
var User = dynamoose.model('users',
{
name: String,
email: String,
status: Boolean,
user_id: Boolean
});
// Custom methods
User.customMethod = function(parameters){
};
module.exports = DynamoBinanceTrade;
Queries-
How to insert -
var user = new User({email: 'email', name: 'name', user_id: 'user_id', status: 'status'});
user.save(function (error){
if(!error){
console.log("saved");
}else{
console.log("Error: "+ error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment