[英]How to implement “SQL Transactions” in “Clean Architecture”?
I am working on an Express-based (Nodejs) API that uses MySQL for data persistence.我正在研究基于 Express(Nodejs)的 API,它使用 MySQL 进行数据持久性。 I have tried to follow the CLEAN ARCHITECTURE proposed by Sir R.C.
我试图遵循 R.C 爵士提出的清洁架构。 Martin.
马丁。
Long story short:-长话短说:-
There are some crop vendors and some users.有一些作物供应商和一些用户。 A user can request an order of some crops with a defined quantity from a vendor.
用户可以向供应商请求一些具有定义数量的作物的订单。 This puts the order in PENDING state.
这会将订单置于 PENDING state 中。 Then the vendor will confirm the orders he/she gets from the user.
然后供应商将确认他/她从用户那里获得的订单。
Domain/Entity -> CROP, Use-case -> add, remove, edit, find, updateQty域/实体 -> CROP、用例 -> 添加、删除、编辑、查找、更新数量
Domain/Entity -> ORDER, Use-case -> request, confirm, cancel域/实体 -> 订单、用例 -> 请求、确认、取消
I have to implement a confirm order functionality我必须实现确认订单功能
I know how to run Mysql specific transactions using "Sequelize", but with a lot of coupling and poor source code architecture.我知道如何使用“Sequelize”运行 Mysql 特定事务,但有很多耦合和糟糕的源代码架构。 (If I do it that way, then DB won't be like plugin anymore)
(如果我这样做,那么 DB 将不再像插件一样)
I am not able to understand how to do this while maintaining the architecture and at what layer to implement this transaction thing, use-case/data-access, or what?我无法理解如何在维护架构的同时执行此操作,以及在哪一层实现此事务、用例/数据访问或什么?
Thanks in advance提前致谢
I recommend keeping the transaction in the "adapters layer" by using "unit of work" pattern.我建议使用“工作单元”模式将事务保存在“适配器层”中。 This way the database remains a plug-in to the business logic.
这样,数据库仍然是业务逻辑的插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.