1

I want to get the data from oraclde db using nodejs and disply it over angularjs based ui. PFB my code for service.js :

var async = require('async');
var oracledb = require('oracledb');
var dbConfig = require('../utility/dbconfig.js');
var response = require('../utility/response.js');
var bodyParser = require('body-parser');
var express = require('express');
var router = express.Router();
router.use(bodyParser.json());
var dbdata='';
var app = express();

var oracledb = require('oracledb');
var dbConfig = require('../utility/dbconfig.js');

var doconnect = function(cb) {
  oracledb.getConnection(
    {
      user          : dbConfig.user,
      password      : dbConfig.password,
      connectString : dbConfig.connectString
    },
    cb);
    console.log('Connection was successful!');
};

var dorelease = function(conn) {
  conn.close(function (err) {
    if (err)
      console.error(err.message);
  });
  console.log('Connection closed successfully!');
};


// Optional Object Output Format
var doquery_object = function (conn, cb) {
  conn.execute(
    "SELECT d.dc_name,c.cobrand_name,c.cobrand_id,c.IS_CACHERUN_DISABLED,c.is_channel,c.environment,c.COBRAND_STATUS_ID,c.deployment_mode,c.db_name,c.gatherer_group FROM cobrand_master c,dc_master d where d.dc_id = c.dc_id ORDER BY c.display_priority",
    {}, 
    { outFormat: oracledb.OBJECT },
    function(err, result)
    {
      if (err) {
        return cb(err, conn);
      } else {
        console.log("----- cobrand_master details (OBJECT output format) --------");
        console.log(result.rows);
        return cb(null, conn);
      }
    });
};

async.waterfall(
  [
    doconnect,
    doquery_object
  ],
  function (err, conn) {
    if (err) { console.error("In waterfall error cb: ==>", err, "<=="); }
    if (conn)
      dorelease(conn);
  });

When I am doing npm start in command prompt, I am getting the data in JSON format.I want to save the output and send it over angular js UI. Since I am new to this, can anyone please help me with simple steps to do it with an example.

4

0 回答 0