midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.4k stars 576 forks source link

@midwayjs/sequelize 用了这个插件之后,怎么使用transaction #1600

Closed fflrichard closed 2 years ago

fflrichard commented 2 years ago

用了这个插件貌似不能获取到 sequelize 的实例,然后就不能用transaction。 请问是否有办法获取到 sequelize的实例,谢谢

waitingsong commented 2 years ago

手工管理吧

fflrichard commented 2 years ago

手工管理吧

手工管理是什么意思……再手动new 一个吗?

waitingsong commented 2 years ago

手工管理吧

手工管理是什么意思……再手动new 一个吗?

我用 Knex 可以手动管理事务,sequelize、 TypeORM 这些个应用使用 QueryBuilder 模式应该也支持吧

ericshao commented 2 years ago

@fflrichard 你可以直接从Model上获取到sequelize

import { Model } from 'sequelize-typescript'; class XyzModel extends Model { ... }

const sequelize = XyzModel.sequelize;

yurenmu commented 2 years ago

可以使用这个包,将transaction挂载到ctx上, "egg-tx-yurenmu": "^1.0.4", 缺点是每个方法上都得写明下transaction async saveOrUpdate(param) { const { ctx } = this; const result = await ctx.model.BaseMaterial.create(param, { transaction: ctx.tx.session, }); return result; }

czy88840616 commented 2 years ago

新版本可以直接拿连接了。

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.