3.2.8 • Published 8 months ago

dynamoose-decorators v3.2.8

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

inspired by sequelize-typescript and @nestjs/mongoose

Getting started

install using npm

npm install dynamoose-decorator dynamoose

or install using yarn

yarn add dynamoose-decorator dynamoose

or install using pnpm

pnpm add dynamoose-decorator dynamoose

this package follows the version of dynamose

Usage

import { randomUUID } from "crypto";
import {
  Attribute,
  CreatedAt,
  Model,
  UpdatedAt,
  Storage,
  getModel,
  Item,
} from "dynamoose-decorator";

@Model()
export class OrderHistory extends Item {
  @Attribute({
    hashKey: true,
  })
  id!: string;

  @Attribute({
    required: true,
  })
  price!: number;

  @Attribute({
    enum: Object.keys(Status),
  })
  status!: Status;

  @Storage("iso")
  @Attribute()
  shipmentAt?: Date;

  @Storage("milliseconds")
  @CreatedAt()
  createdAt!: Date;

  @Storage("milliseconds")
  @UpdatedAt()
  updatedAt!: Date;
}

const OrderHistoryModel = getModel(OrderHistory);

(async () => {
  // create
  const orderHistory = await OrderHistoryModel.create({
    id: randomUUID(),
    price: 99.99,
    status: Status.Unshipped,
  });

  // update
  orderHistory.status = Status.Shipped;
  orderHistory.shipmentAt = new Date();
  await orderHistory.save();

  // delete
  await orderHistory.delete();
})();

const Status = {
  Shipped: "Shipped",
  Unshipped: "Unshipped",
  Canceled: "Canceled",
} as const;

type Status = keyof typeof Status;

more documents

People

author and maintainer is jinseok0

License

MIT

3.2.8

8 months ago

3.2.7

8 months ago

3.2.6

8 months ago

3.2.5

9 months ago

3.2.4

9 months ago

3.2.3

9 months ago

3.2.2

9 months ago

3.2.1

9 months ago

3.2.0

9 months ago