Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynamoose-decorators

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamoose-decorators

generate a dynamoose schema with the decorator

  • 3.2.8
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

dynamoose-decorator

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

FAQs

Package last updated on 11 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc