mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-01-07 11:58:13 +00:00
事务demo
This commit is contained in:
parent
3e9cb29daa
commit
7c826e1a86
@ -15,7 +15,7 @@
|
|||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"midwayjs-cool-alipay": "^1.0.3",
|
"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-oss": "^1.0.12",
|
||||||
"midwayjs-cool-queue": "^1.0.7",
|
"midwayjs-cool-queue": "^1.0.7",
|
||||||
"midwayjs-cool-redis": "^1.1.6",
|
"midwayjs-cool-redis": "^1.1.6",
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Inject, Provide } from '@midwayjs/decorator';
|
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 { InjectEntityModel } from '@midwayjs/orm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository, QueryRunner } from 'typeorm';
|
||||||
import { DemoAppGoodsEntity } from '../entity/goods';
|
import { DemoAppGoodsEntity } from '../entity/goods';
|
||||||
import { ICoolCache } from 'midwayjs-cool-core';
|
import { ICoolCache } from 'midwayjs-cool-core';
|
||||||
|
|
||||||
@ -23,4 +23,19 @@ export class DemoGoodsService extends BaseService {
|
|||||||
async all() {
|
async all() {
|
||||||
return this.demoAppGoodsEntity.find();
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user