Git Product home page Git Product logo

dynatable's Introduction

Dynatable

A DynamoDB table wrapper with a promise wrapped simplified API for the AWS SDK's DynamoDB.DocumentClient.

Why?

DynamoDB.DocumentClient is the official way to talk to your DynamoDB databases, but the API is a little clunky and not very JavaScripty.

Dynatable gives you an easier to use API which borrows a little inspiration from MongoDB.

Usage

const AWS = require('aws-sdk');
const dynatable = require('dynatable');

AWS.config.update({
  region: "eu-west-1",
  accessKeyId: "YOUR_KEY_HERE",
  secretAccessKey: "YOUR_SECRET_KEY_HERE"
});
const docClient = new AWS.DynamoDB.DocumentClient();

// Imagine you have a table called `users`, which is set up with an `id` key in DynamoDB
const users = dynatable(docClient, 'users', { id: 'N' });

// You now have
users.get({ id: 1 })
  .then(users => console.log(users));
// [{ id: 1, name: 'Dynatable', interests: 'API wrapping, getting, putting, updating and deleting'}]

Or the way I use it, define (and export) all tables of your project in one file, and then import them where needed:

tables.js

// all the setup from the previous example here

export const userTable = dynatable(docClient, 'users', { id: 'N' });
export const postTable = dynatable(docClient, 'posts', { id: 'N' });

posts.js

import { userTable, postTable } from './tables';

// Get user details
const userDetails = userTable.findOne({ id: userId });

// Get user's post
const userPosts = postTable.find({ userId });

Promise.all([ userDetails, userPosts ])
  .then(([details, posts]) => {
    // Do something with details and posts here
  });

dynatable's People

Contributors

fanderzon avatar

Stargazers

 avatar

Watchers

 avatar

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.