ddb-orm
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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

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


Readme

Keywords

none

Package Sidebar

Install

npm i ddb-orm

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

57.6 kB

Total Files

18

Last publish

Collaborators

  • faisal_manzer