|
@@ -4,7 +4,7 @@ import { compact, get, isArray, isObject } from 'lodash';
|
|
|
import path = require('path');
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
|
-import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
+import { InjectEntityModel, TypeORMDataSourceManager } from '@midwayjs/typeorm';
|
|
|
import { News } from '../entity/platform/news.entity';
|
|
|
import { Demand } from '../entity/platform/demand.entity';
|
|
|
import { Expert } from '../entity/users/expert.entity';
|
|
@@ -12,13 +12,13 @@ import { Company } from '../entity/users/company.entity';
|
|
|
import { Context } from '@midwayjs/koa';
|
|
|
import * as Excel from 'exceljs';
|
|
|
import { Achievement } from '../entity/platform/achievement.entity';
|
|
|
+import { Test } from '../entity/test.entity';
|
|
|
+import { ServiceError } from '../error/service.error';
|
|
|
|
|
|
|
|
|
|
|
|
@Provide()
|
|
|
export class UtilService {
|
|
|
-
|
|
|
-
|
|
|
@Inject()
|
|
|
ctx: Context;
|
|
|
randomStr(len = 6) {
|
|
@@ -34,6 +34,37 @@ export class UtilService {
|
|
|
|
|
|
|
|
|
}
|
|
|
+ @Inject()
|
|
|
+ dataSourceManager: TypeORMDataSourceManager;
|
|
|
+ async DBTransaction() {
|
|
|
+ const dataSource = this.dataSourceManager.getDataSource('default');
|
|
|
+ const data: Test = {
|
|
|
+ nick_name: '测试',
|
|
|
+ account: `test-${new Date().getTime()}`,
|
|
|
+ hobby: ['睡觉'],
|
|
|
+ props: { hobby: '睡觉' },
|
|
|
+ array_props: [{ hobby: '睡觉', lik: 'nothing' }],
|
|
|
+ };
|
|
|
+ await dataSource.transaction(async em => {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const tb = em
|
|
|
+ .getRepository(Test)
|
|
|
+ .createQueryBuilder()
|
|
|
+
|
|
|
+ .where('hobby @> :hobby', { hobby: '睡觉' });
|
|
|
+ const tres = await tb.getOne();
|
|
|
+ console.log(tres);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
@InjectEntityModel(Demand)
|
|
|
model: Repository<Demand>;
|