node.js - 节点 mssql 在一个 BEGIN TRANSACTION 中进行多个查询
问题描述
想通过我的 API 使用mssql
事务进行多次更新。
例子:
- 运输表
- 列表表
- User_Notes 表
- 客户_登录表
- Push_Notification 表
哪种方法是正确的?
起初我想用原始查询来做。
BEGIN TRANSACTION
CREATE IN SHIPPING
UPDATE IN LISTING
CREATE IN USER_NOTES
UPDATE IN CUSTOMER_LOGIN
CREATE IN PUSH_NOTIFICATION
COMMIT
但是要避免编写像这样的大原始查询。
我也可以将mssql 事务和查询与 (request.query) 一起使用。
const transaction = new sql.Transaction(/* [pool] */)
transaction.begin(err => {
// ... error checks
const request = new sql.Request(transaction)
request.query('create in shipping table', (err, result) => {
// ... error checks
transaction.commit(err => {
// ... error checks
console.log("Transaction committed.")
})
})
request.query('Update in Listing Table', (err, result) => {
// ... error checks
transaction.commit(err => {
// ... error checks
console.log("Transaction committed.")
})
})
and so on...
.
.
.
})
解决方案
推荐阅读
- c++ - Visual Studio 多字节已启用但未检测到
- c# - MVC- 检索 EditorFor 的原始值
- react-native - 在 React-native 中使用 Redux Toolkit 持久化存储
- ios - 预计解码字典
但找到了一个数组而不是 JSON SwiftUI - shell - ansible 从用户输入中读取 openssl 公钥 (.pem) 内容并在服务器上创建文件
- c - C语言中for循环的新形式?
- java - buildSrc:无法为 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象获取未知属性
- winforms - Click-Once 应用程序的用户可访问文件夹
- python - 在 python 中,这是做什么的: tan_y[:-1][np.diff(tan_y) < 0]
- svn - 搜索托管在 tigris.org 上的旧代码:svnwcrev-1.0.tar.gz