npm.io
4.1.0 • Published 1 week ago

@eggjs/transaction-decorator

Licence
MIT
Version
4.1.0
Deps
2
Size
7 kB
Vulns
0
Weekly
0
Stars
19.0K

@eggjs/transaction-decorator

NPM version Known Vulnerabilities npm download Node.js Version

事务注解

Usage

传播机制

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);
  }
}
数据源
export class Bar {
  @Transactional({ dataSourceName: 'xx' })
  async bar() {
    await this.foo();
  }
}

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

Keywords