Skip to content

Commit 64cba58

Browse files
author
Quentin Presley
authored
Set connection properties (#44)
* Add setConnectionProperties prototype
1 parent cc0ac2b commit 64cba58

1 file changed

Lines changed: 32 additions & 28 deletions

File tree

lib/ibmdb.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,41 @@ function IBMDB(name, settings) {
4242
debug('IBMDB constructor settings: %j', settings);
4343
SQLConnector.call(this, name, settings);
4444

45-
this.dbname = (settings.database || settings.db || 'testdb');
46-
this.dsn = settings.dsn;
47-
this.hostname = (settings.hostname || settings.host);
48-
this.username = (settings.username || settings.user);
49-
this.password = settings.password;
50-
this.portnumber = settings.port;
51-
this.protocol = (settings.protocol || 'TCPIP');
52-
53-
// Save off the connectionOptions passed in for connection pooling
54-
this.connectionOptions = {};
55-
this.connectionOptions.minPoolSize = parseInt(settings.minPoolSize, 10) || 0;
56-
this.connectionOptions.maxPoolSize = parseInt(settings.maxPoolSize, 10) || 0;
57-
this.connectionOptions.connectionTimeout =
58-
parseInt(settings.connectionTimeout, 10) || 60;
59-
6045
// Create the Connection Pool object. It will be initialized once we
6146
// have the connection string prepped below.
47+
this.setConnectionProperties(name, settings);
6248
this.client = new Driver.Pool(this.connectionOptions);
49+
this.client.init(this.connectionOptions.minPoolSize, this.connStr);
50+
};
51+
52+
util.inherits(IBMDB, SQLConnector);
53+
54+
IBMDB.prototype.setConnectionProperties = function(name, settings) {
55+
var self = this;
56+
self.dbname = (settings.database || settings.db || 'testdb');
57+
self.dsn = settings.dsn;
58+
self.hostname = (settings.hostname || settings.host);
59+
self.username = (settings.username || settings.user);
60+
self.password = settings.password;
61+
self.portnumber = settings.port;
62+
self.protocol = (settings.protocol || 'TCPIP');
63+
64+
// Save off the connectionOptions passed in for connection pooling
65+
self.connectionOptions = {};
66+
self.connectionOptions.minPoolSize = parseInt(settings.minPoolSize, 10) || 0;
67+
self.connectionOptions.maxPoolSize = parseInt(settings.maxPoolSize, 10) || 0;
68+
self.connectionOptions.connectionTimeout =
69+
parseInt(settings.connectionTimeout, 10) || 60;
6370

6471
var dsn = settings.dsn;
6572
if (dsn) {
66-
this.connStr = dsn;
73+
self.connStr = dsn;
6774

68-
var DSNObject = parseDSN(dsn);
75+
var DSNObject = self.parseDSN(dsn);
6976
if (!('CurrentSchema' in DSNObject)) {
70-
this.connStr += ';CurrentSchema=' + DSNObject.UID;
77+
self.connStr += ';CurrentSchema=' + DSNObject.UID;
7178
}
72-
this.schema = DSNObject.CurrentSchema || DSNObject.UID;
79+
self.schema = DSNObject.CurrentSchema || DSNObject.UID;
7380
} else {
7481
var connStrGenerate =
7582
'DRIVER={' + name + '}' +
@@ -79,22 +86,19 @@ function IBMDB(name, settings) {
7986
';PWD=' + this.password +
8087
';PORT=' + this.portnumber +
8188
';PROTOCOL=' + this.protocol;
82-
this.connStr = connStrGenerate;
89+
self.connStr = connStrGenerate;
8390

84-
this.schema = this.username;
91+
self.schema = this.username;
8592
if (settings.schema) {
86-
this.schema = settings.schema.toUpperCase();
93+
self.schema = settings.schema.toUpperCase();
8794
}
8895

89-
this.connStr += ';CurrentSchema=' + this.schema;
96+
self.connStr += ';CurrentSchema=' + self.schema;
9097
}
91-
92-
this.client.init(this.connectionOptions.minPoolSize, this.connStr);
9398
};
9499

95-
util.inherits(IBMDB, SQLConnector);
96100

97-
function parseDSN(dsn) {
101+
IBMDB.prototype.parseDSN = function(dsn) {
98102
// Split dsn into an array of optionStr
99103
var dsnOption = dsn.split(';');
100104
// Handle dsn string ended with ';'
@@ -110,7 +114,7 @@ function parseDSN(dsn) {
110114
});
111115

112116
return result;
113-
}
117+
};
114118

115119
IBMDB.prototype.tableEscaped = function(model) {
116120
var escapedName = this.escapeName(this.table(model));

0 commit comments

Comments
 (0)