0.0.3 • Published 3 years ago

ddb-orm v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

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 aws-sdk
# or
npm --save install ddb-orm aws-sdk

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.findOne({ username: 'test_user' });
console.log(user);

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

API Guide

Key

OptionDescriptionTypeRequiredDefault
nameKey name for table.stringYES
sortKeySort key for the particular index.stringNO
indexIndex key (and sort-key) if there is any. This will create a Global Secondary index for quering. Not required for primary index.stringNO
isPrimaryIndexSpecify primary index for the table.BooleanNOfalse
projectionProjection type of index.string(ALL | KEYS_ONLY | INCLUDE)NOALL
attributesOnly required for projection type INCLUDE.Array<string>NO[]
rcuRead capacity units for Index.numberNO3
wcuWrite capacity of the Index.numberNO3

TableFactory

OptionDescriptionTypeRequiredDefault
nameName of the table used.stringYES
keysArrays of Key. (at-least primary key is required)ArrayYES
regionAWS region to be used for table.stringNOap-south-1
endpointAWS dyanamodb endpoint. (http://localhost:8000 for local and for production https://dyanmodb.<aws-region>.amazonaws.com)stringNO
useLocalUse local dyanmodb instead of cloud. (You need to run dyanamodb locally first)booleanNO

Attribute

Marks any property as attribute.

Entity

TODO

Example

TODO


0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.6-alpha

3 years ago

1.0.5-alpha

3 years ago

1.0.7-alpha

3 years ago

1.0.3-alpha

3 years ago

1.0.4-alpha

3 years ago

1.0.2-alpha

3 years ago

1.0.1-alpha

3 years ago

1.0.0-alpha

3 years ago