@redredgroup/nestjs-database-trigger
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

nestjs-database-trigger

NPM

npm version npm CircleCI Coverage Status

All Contributors

Description

This is a SQL (currently support only PostgreSQL) database trigger module for NestJS which allow you to use decorators on SQL triggers.

Installation

$ npm install nestjs-database-trigger --save

Example

app.module.ts

import { TriggerModule } from "nestjs-database-trigger";

TriggerModule.forRootAsync({
  imports: [UtilsModule],
  inject: [UtilsService],
  useFactory: async (utilsService: UtilsService) => ({
    connectionString: databaseUrl,
    tables: ["Notification"],
  }),
});

notification.service.ts

import { onTrigger } from "nestjs-database-trigger";

@Injectable()
export class NotificationService {
  constructor() {}

  @OnTrigger("Notification")
  async printout(payload: MessagePayload) {
    console.log(payload);
  }
}

Payload interface

interface MessagePayload<T = any> {
  table: string;
  action: "INSERT" | "UPDATE" | "DELETE";
  data: T | null;
  oldData: T | null;
}

Roadmap

We plan to support other SQL database in the future.

License

nestjs-database-trigger is MIT licensed.

Contributors

Thanks goes to these wonderful people (emoji key):


kahoowkh

📖 ⚠️ 💻

Marco Tse

📖 ⚠️ 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Readme

Keywords

none

Package Sidebar

Install

npm i @redredgroup/nestjs-database-trigger

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

121 kB

Total Files

31

Last publish

Collaborators

  • jieey1140