# nest-simple-transactional

> Simple transaction manager for nestjs/typeorm project

Latest version **1.1.0** (published 2025-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install nest-simple-transactional
pnpm add nest-simple-transactional
yarn add nest-simple-transactional
bun add nest-simple-transactional
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-04-09 |
| First published | 2023-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Tomohiro Hiratsuka |
| Maintainers | tomohiro.hiratsuka |
| Keywords | nestjs, typeorm, transaction |

## Links

- npm: https://www.npmjs.com/package/nest-simple-transactional
- Repository: https://github.com/tomohirohiratsuka/nest-simple-transactional
- Homepage: https://github.com/tomohirohiratsuka/nest-simple-transactional#readme
- Issues: https://github.com/tomohirohiratsuka/nest-simple-transactional/issues
- npm.io page: https://npm.io/package/nest-simple-transactional

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-04-09
- 1.0.0 — 2023-08-25

## README

# nest-simple-transactional
Simple transaction manager for nestjs/typeorm project. Inspired by [nest_transact](https://github.com/alphamikle/nest_transact)

## Installation

```bash
npm install nest-simple-transactional
```

## Usage
```typescript
import { Transactional } from 'nest-simple-transactional';

@Injectable()
export class SomeService extends Transactional<SomeService> {
  constructor(
      moduleRef: ModuleRef,
      @InjectRepository(SomeEntity)
      private readonly someRepository: Repository<SomeEntity>,
  ) {
      super(moduleRef)
  }

  @Transactional()
  async someMethod() {
    await this.someRepository.save(new SomeEntity());
  }
}
```

```typescript
import {DataSource} from "typeorm"; 
@Controller('items')
export class SomeController {
  constructor(
      private readonly someService: SomeService,
      dataSource: DataSource
  ) {}

  @Post()
  async create() {
      this.dataSource.transaction(async (manager) => {
          await this.someService.withTransaction(manager).someMethod();
      })
  }
}
```

## Basic Concepts
As it's said, this is inspired by `nest_transact`, this package provides simple utility wrapper class.
When you extend `Transactional` class, you can use `withTransaction` method to replace all dependent EntityManagers which is used by Repositories injected in the class to the one.
In short when you call withTransaction, it rebuilds the dependencies with the wanted EntityManger(So, it is a little costly operation, but it's not a big deal in most cases).

## Bugs
If you find some bugs or missing features, please create an issue or PR.

## License
MIT

---
_Source: https://npm.io/package/nest-simple-transactional · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
