wangzhibo
2026-07-16 bac4362a0b7726d38a23d38f0d7913f2c2bab262
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { DemoGoodsEntity } from './../entity/goods';
import { Provide } from '@midwayjs/core';
import { BaseService, CoolTransaction } from '@cool-midway/core';
import { QueryRunner } from 'typeorm';
 
/**
 * 操作事务
 */
@Provide()
export class DemoTransactionService extends BaseService {
  /**
   * 事务操作
   */
  @CoolTransaction({
    connectionName: 'default',
  })
  async add(param, queryRunner?: QueryRunner) {
    await queryRunner.manager.insert<DemoGoodsEntity>(DemoGoodsEntity, param);
    return {
      id: param.id,
    };
  }
}