blazejkustra / dynamode

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

Add a decorator to set custom names for entities #33

Closed blazejkustra closed 1 month ago

blazejkustra commented 2 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