Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Creates an instance of Oracle, representing an interface to an
  3.  * Oracle database.
  4.  *
  5.  * @constructor
  6.  * @this {Oracle}
  7.  * @param {string} user The database username
  8.  * @param {string} password The database password
  9.  * @param {string} connectString The Oracle connection string
  10.  */
  11. var q = require('q');
  12. var oracledb = require('oracledb');
  13. oracledb.outFormat = oracledb.OBJECT;
  14. oracledb.poolMax = 10;
  15. oracledb.poolMin = 2;
  16.  
  17. function Oracle(user, password, connectString) {
  18.     this.credentials = {
  19.         user: user,
  20.         password: password,
  21.         connectString: connectString
  22.     };
  23.     var that = this;
  24.     this.poolPromise = oracledb.createPool(this.credentials)
  25.         .then(function(pool) {
  26.             console.log(pool.poolAlias);
  27.             that.pool = pool;
  28.         });
  29. };
  30.  
  31.  
  32. /**
  33.  * Returns a promise, the result being an object containing
  34.  * the results returned from the query
  35.  *
  36.  * @this {Oracle}
  37.  * @param {string} queryString The query to be executed
  38.  * @return {promise} The promise returned with the query results
  39.  */
  40. Oracle.prototype.query = function(queryString) {
  41.     var deferred = q.defer();
  42.  
  43.     if (!this.pool) {
  44.        
  45.     }
  46.  
  47.     this.pool.getConnection()
  48.         .then(function(conn) {
  49.             console.log("Executing query");
  50.             conn.execute(queryString)
  51.                 .then(function(result) {
  52.                     conn.close()
  53.                     deferred.resolve(result);
  54.                     console.log("should be returning results");
  55.                 })
  56.                 .catch(function(err) {
  57.                     console.error(err);
  58.                     conn.close();
  59.                 });
  60.         });
  61.         return deferred.promise;
  62. };
  63.  
  64. module.exports = {
  65.     Oracle: Oracle
  66. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement