All Projects → typedorm → typedorm

typedorm / typedorm

Licence: MIT license
Strongly typed ORM for DynamoDB - Built with the single-table-design pattern in mind.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to typedorm

aws-dynamodb-java-example-local-testing
Example Gradle Java project for using AWS DynamoDB for local testing.
Stars: ✭ 22 (-90.18%)
Mutual labels:  dynamodb, aws-dynamodb
telegram-stepfunctions-bot
Serverless Telegram bot made on 4 AWS Lambda chained by AWS Step Functions. All of this written on Serverless Framework using plugins.
Stars: ✭ 26 (-88.39%)
Mutual labels:  dynamodb, aws-dynamodb
DynamodbToCSV4j
Dump DynamoDB data into a CSV file using java
Stars: ✭ 18 (-91.96%)
Mutual labels:  dynamodb, aws-dynamodb
react-native-appsync-s3
React Native app for image uploads to S3 and storing their records in Amazon DynamoDB using AWS Amplify and AppSync SDK
Stars: ✭ 18 (-91.96%)
Mutual labels:  dynamodb, aws-dynamodb
terraform-aws-dynamodb-autoscaler
Terraform module to provision DynamoDB autoscaler
Stars: ✭ 21 (-90.62%)
Mutual labels:  dynamodb, dynamodb-table
dynamodb-copy-table
A simple python script to copy dynamodb table (useful for achieving renaming of table)
Stars: ✭ 115 (-48.66%)
Mutual labels:  dynamodb, dynamodb-table
dynamodb-simple
Type-safe Haskell framework for AWS DynamoDB
Stars: ✭ 16 (-92.86%)
Mutual labels:  dynamodb, aws-dynamodb
cognito-to-dynamodb-lambda
Copy newly-confirmed users from Cognito to DynamoDB
Stars: ✭ 68 (-69.64%)
Mutual labels:  dynamodb, aws-dynamodb
dynamo-node
DynamoDB mapper
Stars: ✭ 12 (-94.64%)
Mutual labels:  dynamodb, dynamodb-orm
terraform-aws-backup
Terraform module to provision AWS Backup, a fully managed backup service that makes it easy to centralize and automate the back up of data across AWS services such as EBS volumes, RDS databases, DynamoDB tables, EFS file systems, and AWS Storage Gateway volumes.
Stars: ✭ 62 (-72.32%)
Mutual labels:  dynamodb, aws-dynamodb
Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (-58.93%)
Mutual labels:  dynamodb
toi
A TypeScript validation library capable of inferring types
Stars: ✭ 25 (-88.84%)
Mutual labels:  dynamodb
AspNetCore.Identity.DynamoDB
DynamoDB Data Store Adaptor for ASP.NET Core Identity
Stars: ✭ 31 (-86.16%)
Mutual labels:  dynamodb
jest-dynalite
Jest preset to run Dynalite (DynamoDB local) per test runner
Stars: ✭ 125 (-44.2%)
Mutual labels:  dynamodb
go-localstack
Go Wrapper for using localstack
Stars: ✭ 56 (-75%)
Mutual labels:  dynamodb
service
Service for storing and computing BundleWatch data
Stars: ✭ 17 (-92.41%)
Mutual labels:  dynamodb
aws-python-utilities
Python utilities for AWS related tasks.
Stars: ✭ 34 (-84.82%)
Mutual labels:  dynamodb
SparForte
Bourne shell, template engine, scripting language mission-critical, scalable projects. Based a ISO standard proven effective for large, mission-critical projects, SparForte is designed for fast development while, at the same time, providing easier designing, maintenance and bug removal. About 120.000 lines of code.
Stars: ✭ 47 (-79.02%)
Mutual labels:  strongly-typed
go-web-dynamo-starter
Aims to be a starting point for dynamodb based serverless fun
Stars: ✭ 13 (-94.2%)
Mutual labels:  dynamodb
thunder
REST API application that manages user databases
Stars: ✭ 22 (-90.18%)
Mutual labels:  dynamodb

TypeDORM

Code Style: Google semantic-release

Object Relational mapper for DynamoDB, inspired by typeorm.

TypeDORM is an ORM built from ground up using typescript and latest javascript features to provide an easy gateway when doing complex highly relational data modeling in dynamoDB. TypeDORM is built with single-table-design first in mind, but should work as smoothly with regular entity table <-> design pattern. TypeDORM would have not existed without TypeORM and dynamodb-toolbox, big shout-out to these projects and their awesome contributors.

TypeDORM borrows decorator based syntax from TypeORM and provides fully type safe ORM to with dynamodb. TypeDORM currently only support Data Mapper.

Packages

Package Latest Stable Recent Beta Recent Alpha
@typedorm/common NPM Release NPM Release NPM Release
@typedorm/core NPM Release NPM Release NPM Release
@typedorm/testing NPM Release NPM Release NPM Release

Branches

Branches Stability
main Stability
beta Stability
alpha Stability

Features

  • Single-Table design pattern first class support
  • DataMapper development pattern
  • Attribute level per entity transformation, enabled via class-transformer
  • Full type safety
  • Declarative relational schema
  • Entity manager - easy to use findOne, find, count, exists, create, update, and delete operations
  • Transaction manager - easy to use write and read operations
  • Batch manager - powerful write and read operations
  • Scan Manager - powerful find, count, parallelScan and scan operations
  • Safer parallel scan with configurable concurrency control
  • Multiple connections support
  • Code follows all possible best practices when modeling for dynamodb
  • Supports specifying non key attribute as unique, built in pagination support for querying
  • Supports updating Primary key attributes
  • Auto Generated values for attributes
  • Auto update attribute values on UPDATE operations
  • Most type safe, powerful and flexible update expression generator engine
  • Dynamic & Static default values for attributes
  • Complex update, key condition and condition expression all made easy to work with
  • Powerful expression builder to auto generate expressions from input
  • Typescript and javascript support

And many more to come.

Getting Started

Installation

  1. Install core and common modules from npm.

    npm install @typedorm/core @typedorm/common --save

  2. Install aws-sdk for nodejs, TypeDORM uses documentClient to interact with dynamodb.

    npm install aws-sdk --save

  3. Install reflect-metadata shim

    npm install reflect-metadata --save

    and import it as the first thing in node entry file as

    import 'reflect-metadata'

Typescript configuration

If you are using TypeDORM with typescript, make sure you also have below options enabled in tsconfig.json

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Developing with TypeDORM

Creating Table

First thing to do when working with TypeDORM is to setup dynamodb table config. Currently this needs to be manually setup and have also have it configured in deployed table instance(s).

This guide shows how to setup single-table-design

my-table.ts

import {Table, INDEX_TYPE} from '@typedorm/common';

// create table

const myGlobalTable = new Table({
  name: 'test-table',
  partitionKey: 'PK',
  sortKey: 'SK',
  indexes: {
    GSI1: {
      type: INDEX_TYPE.GSI,
      partitionKey: 'GSI1PK',
      sortKey: 'GSI1SK',
    },
    GSI2: {
      type: INDEX_TYPE.GSI,
      partitionKey: 'GSI2PK',
      sortKey: 'GSI2SK',
    },
    LSI1: {
      type: INDEX_TYPE.LSI,
      sortKey: 'LSI1SK',
    },
  },
});

Note: These indexes must match exactly to what is created in dynamo table instance hosted.

Creating an entity

organisation.entity.ts

import {Attribute, Entity, AutoGenerateAttribute} from '@typedorm/common';
import {AUTO_GENERATE_ATTRIBUTE_STRATEGY} from '@typedorm/common';

@Entity({
  name: 'organisation',
  primaryKey: {
    partitionKey: 'ORG#{{id}}',
    sortKey: 'ORG#{{id}}',
  },
  indexes: {
    // specify GSI1 key - "GSI1" named global secondary index needs to exist in above table declaration
    GSI1: {
      partitionKey: 'ORG#{{id}}#STATUS#{{status}}',
      sortKey: 'ORG#{{id}}#ACTIVE#{{active}}',
      type: INDEX_TYPE.GSI,
    },
    // specify LSI1 key
    LSI1: {
      sortKey: 'TICKETS#UPDATED_AT#{{updatedAt}}',
      type: INDEX_TYPE.LSI
    }
  },
})
export class Organisation{

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.UUID4,
  })
  id: string;

  @Attribute()
  name: string;

  @Attribute()
  status: string;

  @Attribute()
  active: boolean;

  @AutoGenerateAttribute({
    strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.EPOCH,
    autoUpdate: true // this will make this attribute and any indexes referencing it auto update for any write operation
  })
  updatedAt: number;
}

Initialize default connection

import {createConnection} from '@typedorm/core';

// initialize with specifying list of entities
createConnection({
  table: myGlobalTable,
  entities: [Organisation],
});

// or initialize with specifying path match for entities
createConnection({
  table: myGlobalTable,
  entities: 'path-to-entities/*.entity.ts',
});

Working with entity manager

import {getEntityManager} from '@typedorm/core';

const org = new Organisation();
org.name = 'My awesome org';
org.status = 'onboarding';
org.active = true;

const entityManger = getEntityManager();

// create item
const response = await entityManger.create(org);

// get item
const org = await entityManger.findOne(Organisation, {
  id: response.id,
  status: 'onboarding',
  active: true,
});

// delete item
await entityManger.delete(Organisation, {
  id: response.id,
  status: 'onboarding',
  active: true,
});

Table of contents

More

DynamoDB is different, different than most other no-sql databases, and therefore data in dynamodb should be stored the way dynamodb expects to get the most benefits out of it. While doing this development experience suffers and all data can become a huge mess very quickly, this is specially true with single-table-design patten. To resolve this, TypeDORM let's declaratively define schema and later takes control from there to provide best development experience possible.

To find out more about how the data looks like when it is stored in dynamo have a look at this detailed guide.

Step by step guide

Current Limitations

  • TypeDORM, at the moment WILL NOT create/update table configuration and must be done separately by the developer.

Sponsors

Nextfaze

Contributions

Please submit an issue for any bugs or ideas here, or you can reach out to me on twitter @whimzy_live.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].