使用Promise的oracledb链接sql调用 [英] oracledb chaining sql call using promises

查看:75
本文介绍了使用Promise的oracledb链接sql调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用NodeJS的oracledb很陌生。
我想做一些依赖的多重sql调用。
第一个sql查询之后,我需要使用该结果执行第二个sql查询,第二个查询的结果用于第三个查询。

I am pretty new to oracledb with NodeJS. I want to do some mutiple sql call that are dependant. After the first sql query, I need to use the result to execute the second sql query, and the result of the second query is used for the third.

我正在尝试查找一些示例,但未找到任何示例。

I am trying to find some examples but failed to find any.

编辑1 :添加用于链接sql查询的代码。
在执行查询sqltoExecute之前,我需要通过执行设置设置角色的查询来配置连接,然后再执行设置设置角色
的查询,然后再执行最终查询。

EDIT 1 : add code used to chain the sql queries. before executing query sqltoExecute, I need to configure the connection by executing a query that set "set role " and then another one to "set package" before executing my final query .

它只执行设置角色的第一个查询,然后不执行任何操作。

It only execute the first query that set the role and then nothing.

我在Ubuntu 14上的NodeJS 4.4.7上使用。

I am using on NodeJS 4.4.7 on Ubuntu 14.

exports.testChainingSqlQueries = function(config, sqlToExecute, callback) {

    if (config) {
        oracledb.getConnection(config)
            .then(function(conn){

                return conn.execute(
                        sqlQueries.sqlQuerySetRole()
                    )
                    .then(function(result){
                        console.log("Execution Succes : "+ sqlQueries.sqlQuerySetRole());
                        return conn;
                    })
                    .catch(function(err){
                        console.log("Error Executing  "+ sqlQueries.sqlQuerySetRole() );
                        return conn.close();
                    })
            })
            .then(function(conn){

                return conn.execute(
                        sqlQueries.sqlQuerySetPackage()
                    )
                    .then(function(result){
                        console.log("Execution Succes : "+ sqlQueries.sqlQuerySetPackage());
                        return conn;
                    })
                    .catch(function(err){
                        console.log("Error executing :  "+ sqlQueries.sqlQuerySetPackage());
                        return conn.close();
                    })
            })
            .then(function(conn){
                return conn.execute(
                        sqlToExecute
                    )
                    .then(function(result){
                        console.log("Execution Succes : "+ sqlToExecute);
                        callback(result, null);
                        return conn.close();
                    })
                    .catch(function(err){
                        console.log("Error executing : "+ sqlToExecute);
                        return conn.close();
                    })
            });

    } else {
        callback(null, {
            message: "Configuration is invalid ",
            config: config
        });
    }
};


推荐答案

在您重复的帖子中对此进行了讨论: https://github.com/oracle/node-oracledb/issues/490

This is being discussed in your duplicate post: https://github.com/oracle/node-oracledb/issues/490

这篇关于使用Promise的oracledb链接sql调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆