具有代理身份验证的Oracledb Nodejs池

时间:2018-10-17 09:10:55

标签: node.js express oracledb

我有使用Express的Node应用程序。我正在使用池身份验证,并尝试根据用户检索数据。这里的要点是请求已完成,但没有从数据库端得到任何东西,因此没有任何反应。 我的数据库操作文件如下所示

var oracledb = require('oracledb');
var dbConfig = require('./dbconfig');
exports.execute = async function (sqlStatement, paramSet, user_Id, res, callback, user_id) {
  oracledb.createPool({
      connectString: dbConfig.connectString,
      homogeneous: false
    },
    function (err, pool) {
       pool.getConnection({
          user: dbConfig.user + ((user_Id === '') ? '' : '[' + user_Id + ']'),
          password: dbConfig.password
        }),

        function (err, conn) {
          if (err) {
            console.error(err.message);
            callback(
              res,
              err
            );
            return;
          }
          conn.execute(sqlStatement, paramSet, {
              //maxRows: 1;
              outFormat: oracledb.OBJECT // query result format
              //, extendedMetaData: true      // get extra metadata
              //, fetchArraySize: 100         // internal buffer allocation size for tuning
            },
            function (err, result) {
              if (err) {
                console.error(err.message);
                doRelease(conn);
                callback(
                  res,
                  result,
                  err, user_id
                );
                return;
              }
              doRelease(conn);
              callback(
                res,
                result.rows, user_id
              );
            });

        }
    });
}

function doRelease(connection) {
  connection.close(function (err) {
    if (err) {
      console.error(err.message);
    }
  });
}

并且从这里收到请求

// BASE SETUP
// =============================================================================

// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
require('dotenv').config({
    path: __dirname + '\\mynode.env'
});
var db = require('./dbOp');

// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(bodyParser.json());
var port = process.env.PORT || 5550; // set our port

// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// test route to make sure everything is working (accessed at GET http://localhost:8080/api)
router.get('/', function (req, res) {
    db.execute(" SELECT 1 FROM dual", [], 'userid', res, aa);

    function aa(res, data, err) {
        console.log(data);
    }
});

// more routes for our API will happen here

// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);

// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);

感谢您的帮助

0 个答案:

没有答案