0
有没有更好的方式来使用与mariasql库的交易,而不是将BEGIN
添加到查询的开始,并使用提交或回滚进行最终确定?与mariadb和node.js使用交易
目前,如果我想换一系列查询在交易我必须做这样的事情:
const MariaClient = require('mariasql');
let client = new MariaClient();
client.connect({
host: "127.0.0.1",
user: "user",
password: "pass",
db: "some_db",
multiStatements: true
});
client.query('BEGIN; INSERT INTO some_table VALUES ("a0","b0"), ("a1","b1"), ("a2","b2");', function (err) {
if (err) {
client.query('ROLLBACK;');
}
client.query('COMMIT;');
});
这似乎笨重,可能容易出错。我们使用generic-pool来管理mariadb客户端,因此看起来可能会有一些意想不到的结果以这种方式处理交易。
'client.beginTransaction'不存在?如果不是,请改用mysql库 –