From a1ef606fdc04005872f0135b097495cfccf2dc35 Mon Sep 17 00:00:00 2001 From: Mike D Pilsbury Date: Wed, 3 Oct 2012 21:34:46 +0100 Subject: [PATCH] Add a placeholder ConnectionPool class, that doesn't do much yet. --- index.js | 26 ++++++++++++++++++++++++++ test/connection-pool.test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 index.js create mode 100644 test/connection-pool.test.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..0169467 --- /dev/null +++ b/index.js @@ -0,0 +1,26 @@ +var Connection = require('tedious').Connection; +var util = require('util'); + +function PooledConnection(config) { + Connection.call(this, config); +} + +util.inherits(PooledConnection, Connection); + +PooledConnection.prototype.close = function() { + this._close(); +} + +PooledConnection.prototype._close = function() { + Connection.prototype.close.call(this); +} + +function ConnectionPool(config) { + return { + getConnection: function() { + return new PooledConnection(config); + } + }; +}; + +module.exports = ConnectionPool; diff --git a/test/connection-pool.test.js b/test/connection-pool.test.js new file mode 100644 index 0000000..54b6ce7 --- /dev/null +++ b/test/connection-pool.test.js @@ -0,0 +1,34 @@ +var assert = require('assert') +var ConnectionPool = require('../index'); + +var config = { + userName: 'test', + password: 'test', + server: '192.168.1.212', +}; + +describe('ConnectionPool', function() { + describe('one connection', function() { + it('should connect', function(done) { + + // var connection = new Connection(config); + + // connection.on('connect', function(err) { + // done(); + // }); + + var cp = new ConnectionPool(config); + var connection = cp.getConnection(); + // console.log(connection); + + connection.on('connect', function(err) { + connection.close(); + }); + + connection.on('end', function(err) { + console.log('end') + done(); + }); + }) + }) +})