Skip to content

Instantly share code, notes, and snippets.

@pbamotra
Forked from johannish/node-pool-oracle.js
Created July 31, 2014 01:19
Show Gist options
  • Save pbamotra/7dd76d04f764dd1cb10d to your computer and use it in GitHub Desktop.
Save pbamotra/7dd76d04f764dd1cb10d to your computer and use it in GitHub Desktop.
var genericPool = require('generic-pool');
// This is the 'nearinfinity' driver: `npm install oracle`
var oracle = require('oracle');
conf = {
"hostName": "localhost",
"port": 1521,
"user": "oracle",
"password": "oracle",
"database": "xe",
}
var query = "SELECT systimestamp FROM dual";
var pool = genericPool.Pool({
name: 'testpool',
log: true,
max: 20,
create: function(callback) {
var settings = {
hostname: conf.hostName,
port: conf.port,
database: conf.database,
user: conf.user,
password: conf.password
}
new oracle.connect(settings, function(err, connection) {
callback(err, connection);
});
},
destroy: function(connection) {
connection.close();
}
});
var acquireAndQuery = function() {
pool.acquire(function(err, connection) {
if (err) {
console.log(err, "Error acquiring from pool.");
return;
}
connection.execute(query, [], function(err, results) {
if (err) {
console.log(err, "Error executing query.");
// Simply releasing this connection back to the pool means a potentially
// corrupt connection may get reused.
pool.release(connection)
// This solves the issue
// pool.destroy(connection);
return;
}
pool.release(connection);
console.log(results);
});
});
};
// Continuously make DB calls
setInterval(acquireAndQuery, (3000));
setInterval(acquireAndQuery, (3100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment