簡體   English   中英

獲取node.js中存儲過程的結果

[英]Obtain the result of stored procedure in node.js

我可以在 mysql 的一個存儲過程中從不同的表(多行)中獲得多個選擇並在 nodejs 中檢索這些結果嗎?

就像在 .NET 和 SQL Server 中一樣,我們可以使用“sqlnextresult”

來自商店程序的圖像在此處輸入圖片說明

這里有一個使用mssql節點包的示例,您可以在此處找到有關此包的文檔。

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);
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM