# @redredgroup/nestjs-database-trigger

> A SQL database trigger module for NestJS

Latest version **0.0.2** (published 2023-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @redredgroup/nestjs-database-trigger
pnpm add @redredgroup/nestjs-database-trigger
yarn add @redredgroup/nestjs-database-trigger
bun add @redredgroup/nestjs-database-trigger
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2023-07-24 |
| First published | 2023-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 117.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jieey1140 |
| Maintainers | redredgroup |

## Links

- npm: https://www.npmjs.com/package/@redredgroup/nestjs-database-trigger
- Repository: https://github.com/REDREDGROUP/nestjs-database-trigger
- Homepage: https://github.com/REDREDGROUP/nestjs-database-trigger#readme
- Issues: https://github.com/REDREDGROUP/nestjs-database-trigger/issues
- npm.io page: https://npm.io/package/@redredgroup/nestjs-database-trigger

## Recent versions

- 0.0.2 (latest) — 2023-07-24
- 0.0.1 — 2023-07-24

## README

# nestjs-database-trigger

[![NPM](https://nodei.co/npm/nestjs-database-trigger.png)](https://nodei.co/npm/nestjs-database-trigger/)

[![npm version](https://badge.fury.io/js/nestjs-database-trigger.svg)](https://badge.fury.io/js/nestjs-database-trigger)
![npm](https://img.shields.io/npm/dm/nestjs-database-trigger)
[![CircleCI](https://circleci.com/gh/kahoowkh/nestjs-database-trigger.svg?style=svg)](https://circleci.com/gh/kahoowkh/nestjs-database-trigger)
[![Coverage Status](https://coveralls.io/repos/github/kahoowkh/nestjs-database-trigger/badge.svg?branch=master)](https://coveralls.io/github/kahoowkh/nestjs-database-trigger?branch=master)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

# Description

This is a SQL (currently support only PostgreSQL) database trigger module for [NestJS]("http://nestjs.com/") which allow you to use decorators on SQL triggers.

# Installation

```
$ npm install nestjs-database-trigger --save
```

# Example

app.module.ts

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

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

notification.service.ts

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

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

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

Payload interface

```ts
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](LICENSE).

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tr>
    <td align="center"><a href="https://github.com/kahoowkh"><img src="https://avatars.githubusercontent.com/u/26565078?v=4?s=100" width="100px;" alt=""/><br /><sub><b>kahoowkh</b></sub></a><br /><a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=kahoowkh" title="Documentation">📖</a> <a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=kahoowkh" title="Tests">⚠️</a> <a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=kahoowkh" title="Code">💻</a></td>
    <td align="center"><a href="https://github.com/Marcotsept"><img src="https://avatars.githubusercontent.com/u/17099973?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marco Tse</b></sub></a><br /><a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=Marcotsept" title="Documentation">📖</a> <a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=Marcotsept" title="Tests">⚠️</a> <a href="https://github.com/kahoowkh/nestjs-database-trigger/commits?author=Marcotsept" title="Code">💻</a></td>
  </tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

---
_Source: https://npm.io/package/@redredgroup/nestjs-database-trigger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
