Giter VIP home page Giter VIP logo

simple-dyno's Introduction

simple-dyno

Build Status

Easy to use, minimalistic wrapper for AWS DynamoDB

Installation

$ npm install @awkward/simple-dyno

Please also include require('babel-polyfill') in your project for node <= 4.0

Features

  • Easy way to create a model, keeping your code consistent and saving it to DynamoDB
  • Serializers to format your (json) response
  • Validation based on Joi
  • Encryption using bcrypt for your passwords
  • Local DynamoDB for testing purposes

Methods

To create a new entry, and options can include {skipValidation: true}:

Model.create(attributes, options)

To get an entry or multiple entries:

Model.get(keyValues)

To update an entry, and options can include {skipValidation: true}:

Model.update(keyValues, attributes, options)

To delete an entry:

Model.destroy(keyValues)

To perform a scan operation (not recommended):

Model.find(attributes)

To query using a secondary index:

Model.query(indexName, attributes)

To serialize the response attributes:

Model.serialize(response, options)

To run a local DynamoDB (which runs on Java), by default runs in memory but you can also store on disk using {inMemory: false} as options:

SimpleDyno.local(options)

To set the config, which you can pass the following options {accessKeyId: '', secretAccessKey: '', region: ''}:

SimpleDyno.config(options)

Example (in this case the config is set by default by AWS and assumes tables are already created)

// Import deps
import { Model } from 'simple-dyno';
import Joi from 'joi';

// Add your own methods
class UserModel extends Model {
  myAwesomeMethod(obj) {
    return obj.firstName+obj.lastName;
  }
}

// Create model instance
var User = new UserModel({
  table: 'users',
  hashKey: 'email',
  serializers: {
    default: ['email'],
    scary: ['access_token', 'password']
  },
  schema: {
    email: Joi.string().email(),
    access_token: Joi.string(),
    password: {
      format: Joi.string().regex(/[a-zA-Z0-9]{3,30}/),
      encrypt: true
    }
  }
});

var userObj = yield User.create({email: '[email protected]', access_token: 'aW12k3KDASsd012Ms1Mf29Mc7', password: '******'})
return User.serialize(userObj, {format: 'scary'});

Example of running the local environment

// Import deps
import * as SimpleDyno from 'simple-dyno';

// Start a local DynamoDB
yield SimpleDyno.local();

// Create accociated tables for the following model(s)
SimpleDyno.load(User);

Todo

  • Fix CI by allowing Java to run on Travis
  • Migrations
  • Better docs (explain how AWS works)

How to contribute

Please create a pull request, make sure to include and update the tests and that they're working. And don't forget to build the minified version (with babel) with npm run build.

Running tests

Use npm test to do a test run using Mocha.

Legal stuff (MIT License)

Copyright (c) 2016 Awkward.

Distributed under MIT license.

simple-dyno's People

Contributors

davidvanleeuwen avatar tmw avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-dyno's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.