我可以在mysql的一個存儲過程中從不同的表(多行)中選擇多個select並在nodejs中檢索這些結果嗎?在node.js中獲取存儲過程的結果
就像在與SQL Server,我們可以使用使用「sqlnextresult」 .NET
我可以在mysql的一個存儲過程中從不同的表(多行)中選擇多個select並在nodejs中檢索這些結果嗎?在node.js中獲取存儲過程的結果
就像在與SQL Server,我們可以使用使用「sqlnextresult」 .NET
在這裏,你可以選擇使用mssql
節點封裝的例子,你可以找到here這個包的文檔。
var sql = require('mssql'),
connectionObj = {
user: 'myUser',
password: 'myPassword',
server: 'http://mysqlserver.whatever'
options: {
database: 'myDB'
}
};
/**
* Opens connection to sql server.
*
* @return {Object} Connection object.
*/
function openConnection() {
var connection = new sql.Connection(connectionObj);
return connection;
};
/**
* Closes connection.
*
* @param {Object} connection - Connection Object.
* @return {Promise} Promise.
*/
function closeConnection(connection) {
return connection.close();
};
/**
* Does a request to sql server.
*
* @param {Object} connection - Connection object.
* @param {string} query - Query string to compute.
* @return {Promise} Promise.
*/
function doRequest(connection, query) {
return connection.request().query(query);
};
/**
* Gets Request.
*
* @param {Object} connection - Connection object.
*/
function getRequest(connection) {
return new sql.Request(connection);
};
var request, conn = openConnection();
// First open the connection with DB (method uses the object created at the begining.
conn.connect()
.then(function() {
// Now creates a Request.
request = getRequest(conn);
// Executes your stored procedure.
return request.execute('usp_get_Masters');
})
.then(function(result) {
console.log(result); // Here in result you have the result of the stored procedure execution.
})
.catch(function(error) {
console.log(error);
});
我想要做的是:'getMainRoutes(CB){ conn.query( 'usp_get_Masters()',CB); }',該執行可以檢索我發送的存儲過程的3個結果嗎? ,我的意思是像一個表的回調return =>結果[0],其他表的結果[1]和第三個表的結果[2] – lmichilot
結果的結構取決於你如何製作存儲過程,在你的情況下,我認爲就像你說的那樣,你將在'結果'3中出現在數組中,每次都發生在你發佈的每個選擇中。你有沒有試過我的代碼? – Kalamarico
我使用 「mysql的」: 「^ 2.13.0」 與快遞 – lmichilot