soronto3603 / dynamo1

Dynamo DB one table ORM for Javascript(& Typescript).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamo1

Build Downloads Version License Typescript
dependencies Status devDependencies Status

With Dynamo DB, only one table is enough.

Dynamo DB one table ORM for Javascript(& Typescript).

Installation

Usage

const connection = createConnection([
  {
    tableName: `${STAGE}-datas`,
    aliasName: 'datas',
    hashKey: { name: string, type: Buffer },
    rangeKey: { name: string, type: String },
    gsi: [
      { name: 'gsi1', hashKey: { name: string, type: String }, rangeKey: { name: string, type: String } },
      { name: 'gsi2', hashKey: { name: string, type: String }, rangeKey: { name: string, type: String } },
      { name: 'gsi3', hashKey: { name: string, type: String }, rangeKey: { name: string, type: String } },
    ],
  }, // tables[0] is default
])

Entity

import { v4 as uuid } from 'uuid'

import { Column, Entity, column, text } from 'dynamo1'

@Entity<User>({
  name: 'users',
  hashKey: text('users'),
  rangeKey: column('id'),
})
export class User {
  @Column({ name: 'user_id', onCreate: _ => uuid() })
  public id!: string

  @Column()
  public username?: string

  @Column()
  public email!: string

  @Column<User>({
    onCreate: entity => entity.createdAt || new Date().getTime(),
  })
  public createdAt!: number

  @Column<User>({
    onCreate: _ => new Date().getTime(),
    onUpdate: _ => new Date().getTime(),
  })
  public updatedAt!: number
}

Todo

About

Dynamo DB one table ORM for Javascript(& Typescript).


Languages

Language:TypeScript 98.4%Language:JavaScript 1.6%