blazejkustra / dynamode

Dynamode is a modeling tool for Amazon's DynamoDB
MIT License
62 stars 2 forks source link

Add a decorator to set custom names for entities #33

Closed blazejkustra closed 3 months ago

blazejkustra commented 3 months ago

Fixes https://github.com/blazejkustra/dynamode/issues/32. Now it is possible to overwrite the name of the class with a decorator.

import Table, { tableManager, TableProps } from "./table";
import attribute, { entity } from "dynamode/decorators";

export interface UserProps {
  pk: string;
}

@entity.customName("USER_ENTITY")
export class User extends Table {
  @attribute.partitionKey.string({ prefix: "USER" })
  pk!: string;

  constructor(props: UserProps) {
    super(props);
  }
}

export const UserManager = tableManager.entityManager(User);

The outcome is that you get entity names even with minification: image