事务demo

This commit is contained in:
ap 2021-04-29 09:43:48 +08:00
parent 3e9cb29daa
commit 7c826e1a86
2 changed files with 18 additions and 3 deletions

View File

@ -15,7 +15,7 @@
"lodash": "^4.17.21",
"md5": "^2.3.0",
"midwayjs-cool-alipay": "^1.0.3",
"midwayjs-cool-core": "^3.2.2",
"midwayjs-cool-core": "^3.2.5",
"midwayjs-cool-oss": "^1.0.12",
"midwayjs-cool-queue": "^1.0.7",
"midwayjs-cool-redis": "^1.1.6",

View File

@ -1,7 +1,7 @@
import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService, Cache } from 'midwayjs-cool-core';
import { BaseService, Cache, CoolTransaction } from 'midwayjs-cool-core';
import { InjectEntityModel } from '@midwayjs/orm';
import { Repository } from 'typeorm';
import { Repository, QueryRunner } from 'typeorm';
import { DemoAppGoodsEntity } from '../entity/goods';
import { ICoolCache } from 'midwayjs-cool-core';
@ -23,4 +23,19 @@ export class DemoGoodsService extends BaseService {
async all() {
return this.demoAppGoodsEntity.find();
}
/**
*
* @param params
* @param queryRunner
*/
@CoolTransaction({ isolation: 'SERIALIZABLE' })
async testTransaction(params: any, queryRunner?: QueryRunner) {
await queryRunner.manager.insert<DemoAppGoodsEntity>(DemoAppGoodsEntity, {
title: '这是个商品',
pic: '商品图',
price: 99.0,
type: 1,
});
}
}