0
我有上sails.jssails.js运行多个命令查询在MySQL
我想在sails lift
运行从文件脚本中执行多个SQL查询的问题。
我写了一个自定义的处理内/config/bootstrap.js
module.exports.bootstrap = function(cb) {
fs.readFile('SQL\\StoredProcedures\\MyProcedure.sql', 'utf8', function (err,data) {
if (err) {
console.log(err);
}
console.log(data);
MyModel.query(data, function(err, records){
if(err){
console.log(err);
}
});
});
// It's very important to trigger this callback method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
};
的问题是,.query()
函数不接受内多次查询。我的意思是,它不接受的时候在我的文件,我有:
DROP PROCEDURE IF EXISTS `MyProcedure`;
但它不会接受,而在我的文件,我有:
DROP PROCEDURE IF EXISTS `MyProcedure`;
SELECT * FROM something;
有没有执行这个文件的方法吗?
如果我的一个查询是多行的,该怎么办? – Tomasz
你可以用';'或其他分隔符来分割吗? – elssar
尝试通过分隔符分割命令。不在这里工作 – Tomasz