3.0.3 • Published 7 years ago

hapi-plugin-oracledb v3.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

#Hapi plugin for OracleDB NPM version Known Vulnerabilities

Installation (via npm)

  $ npm install hapi-plugin-oracledb --save

What does this plugin do?

Initialize a Oracle database connection pool and either attach a OracleDB connection to every request or enable the user to manually use connection from the server via server.getDb(function (err, connection) {}).

How to use this plugin?

Initialize the plugin using same options you can pass onto the oracledb lib for making a connection. See https://www.npmjs.com/package/oracledb for more info on the oracledb lib itself.

Initialize Plugin

server.register({
	register: require('hapi-plugin-oracledb'),
	options: {
		connectString: "localhost:1521/servicename",
		user: "root",
		password: ""
	}
}, function (err) {
	if (err) console.log(err);
	...
});

Enabling DB pool injection

OracleDB pool injection into request.app.db object will be enabled only if routes or api realms which need the injection pass the following parameter during initialization.

Route Injection

server.route({ 
	method: 'GET', 
	config: {
        plugins:{
            oracledb: true
        }
    },
	path: '/api/getName', 
	handler: function (request, reply) { 
			
	} 
});

Plugin Realm Injection

server.register(
    {
        register:require('./server/api/main'),
        options:{
            oracledb:true
        },
        routes: {
            prefix: '/api'
        }
    }, (err) =>
    {
        if (err) {
            console.error('Failed to load plugin:', err);
        }
    }
);

Querying Using injected pool connection

server.route({
        method: 'GET',
        path: '/teamhierarchy/{employeenumbers}',
        config: {
            plugins:{
                'oracledb': true  //No need to pass this here if already passed at Plugin Realm level
            }
        },
        handler: function (request, reply) {
		var query = 'select firstname,lastname from users';
		request.app.db.execute(query,function (err,result) {
                    reply(result);
                });
	}
});

Querying Using server.getDB()

Via request.app.db. You can also manualy get a connection from the server via server.getDb(function (err, connection) {}).

server.route({ 
	method: 'GET', 
	config: {
        plugins:{
            'oracledb': true
        }
    },
	path: '/api/getName', 
	handler: function (request, reply) { 
			var query = 'select firstname,lastname from users';
			server.getDb(function(err,connection){
			   connection.execute(query,function (err,result) {
                reply(result);
              }); 
			});
		} 
	});

License

MIT

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago