Skip to content

Commit a580c8a

Browse files
committed
code cleanup
1 parent 6c7b908 commit a580c8a

File tree

4 files changed

+33
-40
lines changed

4 files changed

+33
-40
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
defaults: defaults
1212
}
1313

14-
//lazy require native as it may not have been built
14+
//lazy require native module...the c++ may not have been compiled
1515
module.exports.__defineGetter__("native", function() {
1616
return require(__dirname + '/native');
1717
})

lib/native.js

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,6 @@ var types = require(__dirname + "/types");
88
var Connection = binding.Connection;
99
var p = Connection.prototype;
1010

11-
var add = function(params, config, paramName) {
12-
var value = config[paramName];
13-
if(value) {
14-
params.push(paramName+"='"+value+"'");
15-
}
16-
}
17-
18-
var getLibpgConString = function(config, callback) {
19-
if(typeof config == 'object') {
20-
var params = []
21-
add(params, config, 'user');
22-
add(params, config, 'password');
23-
add(params, config, 'port');
24-
if(config.database) {
25-
params.push("dbname='" + config.database + "'");
26-
}
27-
if(config.host) {
28-
if(config.host != 'localhost' && config.host != '127.0.0.1') {
29-
throw new Error("Need to use node to do async DNS on host");
30-
}
31-
params.push("hostaddr=127.0.0.1 ");
32-
}
33-
callback(params.join(" "));
34-
} else {
35-
throw new Error("Unrecognized config type for connection");
36-
}
37-
}
38-
3911
var nativeConnect = p.connect;
4012

4113
p.connect = function() {
@@ -148,12 +120,13 @@ var NativeQuery = function(text, values, callback) {
148120
var item = this.values[i];
149121
if(item instanceof Date) {
150122
this.values[i] = JSON.stringify(item);
123+
} else {
124+
this.values[i] = item.toString();
151125
}
152126
}
153127
}
154128

155129
EventEmitter.call(this);
156-
this._translateValues();
157130
};
158131

159132
sys.inherits(NativeQuery, EventEmitter);
@@ -194,12 +167,32 @@ p.handleReadyForQuery = function() {
194167
this.emit('end');
195168
};
196169

197-
//translates values into strings
198-
p._translateValues = function() {
199-
if(this.values) {
200-
this.values = this.values.map(function(val) {
201-
return val.toString();
202-
});
170+
var add = function(params, config, paramName) {
171+
var value = config[paramName];
172+
if(value) {
173+
params.push(paramName+"='"+value+"'");
174+
}
175+
}
176+
177+
//connection string helper
178+
var getLibpgConString = function(config, callback) {
179+
if(typeof config == 'object') {
180+
var params = []
181+
add(params, config, 'user');
182+
add(params, config, 'password');
183+
add(params, config, 'port');
184+
if(config.database) {
185+
params.push("dbname='" + config.database + "'");
186+
}
187+
if(config.host) {
188+
if(config.host != 'localhost' && config.host != '127.0.0.1') {
189+
throw new Error("Need to use node to do async DNS on host");
190+
}
191+
params.push("hostaddr=127.0.0.1 ");
192+
}
193+
callback(params.join(" "));
194+
} else {
195+
throw new Error("Unrecognized config type for connection");
203196
}
204197
}
205198

lib/query.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ var Query = function(config) {
99
this.rows = config.rows;
1010
this.types = config.types;
1111
this.name = config.name;
12-
//for code clarity purposes we'll declare this here though it's not
13-
//set or used until a rowDescription message comes in
14-
this.rowDescription = null;
1512
this.callback = config.callback;
1613
this._fieldNames = [];
1714
this._fieldConverters = [];
@@ -125,7 +122,7 @@ p.prepare = function(connection) {
125122
connection.parsedStatements[this.name] = true;
126123
}
127124

128-
//TODO is there some btter way to prepare values for the database?
125+
//TODO is there some better way to prepare values for the database?
129126
if(self.values) {
130127
self.values = self.values.map(function(val) {
131128
return (val instanceof Date) ? JSON.stringify(val) : val;

lib/writer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//binary data writer tuned for creating
2+
//postgres message packets as effeciently as possible by reusing the
3+
//same buffer to avoid memcpy and limit memory allocations
14
var Writer = function(size) {
25
this.size = size || 1024;
36
this.buffer = new Buffer(this.size + 5);

0 commit comments

Comments
 (0)