3.2.8 • Published 8 months ago
dynamoose-decorators v3.2.8
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;
People
author and maintainer is jinseok0