@neohelden/commons-nestjs-server-transactional
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

neohelden-commons-nestjs-server-transactional

This module provides a database-agnostic transactional service for NestJS applications. The transactional service is build in a way, that any underlying database or transaction-supporting service can be used.

Transaction Bundle

The decisions are available to the Application using decorators. An example to load the module with TypeORM is:

import {
  TransactionHelper,
  Transactional,
} from "@neohelden/nestjs-server-transactional";

class BookService {
  @Transaction()
  async save(book: Book): Promise<Book> {
    repository.save(book);
    return book;
  }
}

class Repository {
  constructor(private readonly helper: TransactionHelper) {}

  @Transactional()
  async save(book: Book): Promise<Book> {
    return helper.transaction(async (dataManager) => {
      dataManager.save(book);
    });
  }
}

Configuration

The configuration of this module is accomplished using NestJS Dynamic modules. Therefore import the TransactionModule in your AppModule and provide the configuration.

Example:

TransactionModule.forRoot({
  getDataManager: async () => {
    return new DataManager();
  },
});

Dependencies (3)

Dev Dependencies (12)

Package Sidebar

Install

npm i @neohelden/commons-nestjs-server-transactional

Weekly Downloads

594

Version

1.0.4

License

Apache-2.0

Unpacked Size

30.4 kB

Total Files

15

Last publish

Collaborators

  • neo-robot
  • thedome