Giter Site home page Giter Site logo

ddb-orm's Introduction

Dynamodb Single Table ORM

This is an abstraction for using single table design with dynamodb.

Inspired by mythical Rick Houlihan

THIS IS NOT READY YET: DON'T USE THIS

This is an alpha software and is currently in active development. Documentations and API are to be done.

Getting Started

yarn add ddb-orm
# or
npm --save install ddb-orm

Declare keys used in table

import { Key } from 'ddb-orm';

const PK = Key({ name: 'PK', sortKey: 'SK', isPrimaryIndex: true });
const SK = Key({ key: 'SK', sortKey: 'PK', index: 'InvertedIndex', });

Declare table properties

import { TableFactory } from 'ddb-orm'

const Table = TableFactory({
    name: 'SocialTable',
    keys: [PK, SK],
    useLocal: true,  // using locally running dynamodb
});

Create the table (optional)

await Table.create();

Define your entities

import { Entity, Attribute } from 'ddb-orm'

@Table  // attach our table instance to entity
class User extends Entity {
    @PK('USER')
    @SK('#METADATA')
    username: string;

    @Attribute
    name: string;
}

Save new user

const user = new User({ username: 'test_user', name: 'Test User' });
await user.save();

Find Multiple users

const users = await User.find({ where: { username: 'test_user' } });
console.log(users);

/*
    [
        User { 
                "username": "test_user",
                "name": "Test User",
                "PK": "USER#test_user",
                "SK": "#METADATA#test_user"
        }
    ]
*/

Find Particular user

const user = await User.find({ username: 'test_user' });
console.log(user);

/*
    User { 
        "username": "test_user",
        "name": "Test User",
        "PK": "USER#test_user",
        "SK": "#METADATA#test_user"
    }
*/

API Guide

Key

Option Description Type Required Default
name Key name for table. string YES
sortKey Sort key for the particular index. string NO
index Index key (and sort-key) if there is any. This will create a Global Secondary index for quering. Not required for primary index. string NO
isPrimaryIndex Specify primary index for the table. Boolean NO false
projection Projection type of index. string(ALL | KEYS_ONLY | INCLUDE) NO ALL
attributes Only required for projection type INCLUDE. Array<string> NO []
rcu Read capacity units for Index. number NO 3
wcu Write capacity of the Index. number NO 3

TableFactory

Option Description Type Required Default
name Name of the table used. string YES
keys Arrays of Key. (at-least primary key is required) Array YES
region AWS region to be used for table. string NO ap-south-1
endpoint AWS dyanamodb endpoint. (http://localhost:8000 for local and for production https://dyanmodb.<aws-region>.amazonaws.com) string NO
useLocal Use local dyanmodb instead of cloud. (You need to run dyanamodb locally first) boolean NO

Attribute

Marks any property as attribute.

Entity

TODO

Example

TODO


ddb-orm's People

Contributors

faisal-manzer avatar

Watchers

 avatar  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.