【发布时间】:2016-01-14 22:29:48
【问题描述】:
我在sails.js 上执行多个sql 查询时遇到问题
我想从sails lift 上的文件运行脚本。
我在/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;
有没有办法执行这个文件?
【问题讨论】: