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