Coder Social home page Coder Social logo

node-oracledb-autoreconnect's Introduction

This library is wrapper with additional features, that uses Oracle official NodeJS driver on background.

Additional features

  • Auto-connect. So just call sql query and does not care of anything else.
  • Auto-reconnect if connection get lost.
  • Promises, that official driver don't have. :-)

Installation

npm install oracledb-autoreconnect

Installation Prerequires

Because this small library is only wrapper for Oracle official NodeJS driver, so please read Installing node-oracledb or Installing node-oracledb - extended version.

NOTE: If you will have some issues, try (as test) install npm install oracledb and solve, why it fails.

Example using library

// Include this library

var db = require('oracledb-autoreconnect');


// Set connection parameters on application init.

db.setConnection({
    user          : "hr",
    password      : "welcome",
    connectString : "localhost/XE"
});


// Just make query anytime.
// Don't care about connect to db. It is solved automatically.

var queryString = "SELECT id, firstname, lastname FROM db.persons WHERE firstname LIKE :1 AND lastname LIKE :2";
var queryParams = ["John","Brown"];
db.query(queryString, queryParams).then(function (dbResult) {

    // Convert result to better structured object
    var assocDbResult = db.transformToAssociated(dbResult);
    
    // Print results to console
    assocDbResult.map(function(person) {
        console.log(person.firstname + " " + person.lastname + " has id " + person.id);
    });
});

API of library

function setConnection(oracledbConnectionObject)

Configuration of server connection parameters and credentials for future use in autoconnection/reconnection.

Note: Object with parameters will be pushed directly into Oracle library into official oracledb.getConnection method.

  • @returns {undefined} - Does return nothing

function query(query, queryParams)

Makes SQL query with autoconnection and reconnection on error If oracle DB is not connected yet, method will try to connect automatically. If DB is connected, but connection is lost (connection timeout), method will automatically try to reconnect.

  • @param {String} query - SQL query
  • @param {Array} queryParams - Array of values to SQL query
  • @returns {Promise} - Result of SQL query

function transformToAssociated(sqlResult);

Converts common SQL SELECT result into Array of rows with associated column names.

Example:

Input:
{
    metaData: [{name:"ID"},{name:"FIRSTNAME"}],
    rows: [[1, "JOHN"],[2,"JARYN"]]
}
Converted output:
[
    {"ID":1, "FIRSTNAME":"JOHN"}
    {"ID":2, "FIRSTNAME":"JARYN"}
]
  • @param {Object} sqlSelectResult
  • @returns {Array.<Object.<string,*>>}

function connect()

Manual create connection to Oracle server. If already connected to server, it does NOT connect second one, but use the first one. NOTE: In common use in not necessary to call.

  • @returns {Promise} - Oracledb connection object of official Oracledb driver

function disconnect()

Manual disconnect from DB.

NOTE: In common use in not necessary to call.

  • @returns {Promise}

node-oracledb-autoreconnect's People

Contributors

ma-zal avatar vasekch avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.