# @eggjs/transaction-decorator

> tegg transaction decorator

Latest version **4.1.0** (published 2026-10-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eggjs/transaction-decorator
pnpm add @eggjs/transaction-decorator
yarn add @eggjs/transaction-decorator
bun add @eggjs/transaction-decorator
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-10-07 |
| First published | 2025-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22.18.0 |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 18980 |
| Author | qile222 |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, hyj1991, killagu, coolme200, akitasummer, elrrrrrrr, niania |
| Keywords | decorator, egg, tegg, transaction, typescript |

## Links

- npm: https://www.npmjs.com/package/@eggjs/transaction-decorator
- Repository: https://github.com/eggjs/egg
- Homepage: https://github.com/eggjs/egg/tree/next/tegg/core/transaction-decorator
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/@eggjs/transaction-decorator

## Dependencies (2)

- [@eggjs/tegg-types](https://npm.io/package/@eggjs/tegg-types.md) 4.1.0
- [@eggjs/core-decorator](https://npm.io/package/@eggjs/core-decorator.md) 4.1.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-10-07
- 4.0.2-rc.1 (rc) — 2026-10-06
- 4.0.2-beta.27 (beta) — 2026-09-20
- 4.0.2 — 2026-10-06
- 4.0.2-rc.0 — 2026-09-23
- 4.0.2-beta.26 — 2026-08-07
- 4.0.2-beta.25 — 2026-07-13
- 4.0.2-beta.24 — 2026-07-12
- 4.0.2-beta.23 — 2026-07-11
- 4.0.2-beta.22 — 2026-07-11
- 4.0.2-beta.20 — 2026-07-09
- 4.0.2-beta.19 — 2026-06-29
- 4.0.2-beta.17 — 2026-06-28
- 4.0.2-beta.16 — 2026-06-26
- 4.0.2-beta.15 — 2026-06-26
- … 24 more at https://npm.io/package/@eggjs/transaction-decorator/versions

## README

# @eggjs/transaction-decorator

[![NPM version][npm-image]][npm-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/transaction-decorator.svg?style=flat)](https://nodejs.org/en/download/)

[npm-image]: https://img.shields.io/npm/v/@eggjs/transaction-decorator.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/transaction-decorator
[snyk-image]: https://snyk.io/test/npm/@eggjs/transaction-decorator/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/transaction-decorator
[download-image]: https://img.shields.io/npm/dm/@eggjs/transaction-decorator.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/transaction-decorator

事务注解

## Usage

### 传播机制

```ts
export class Foo {
  @Transactional({ propagation: PropagationType.ALWAYS_NEW })
  async bar() {
    await this.foo();
  }

  @Transactional({ propagation: PropagationType.REQUIRED })
  async foo(msg) {
    console.log('has msg: ', msg);
  }
}
```

### 数据源

```ts
export class Bar {
  @Transactional({ dataSourceName: 'xx' })
  async bar() {
    await this.foo();
  }
}
```

Foo.bar 始终会在一个独立的事务中执行，而 Foo.foo 会在 Foo.bar 的事务中执行

---
_Source: https://npm.io/package/@eggjs/transaction-decorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
