Skip to content
This repository was archived by the owner on Dec 10, 2017. It is now read-only.

Commit f76054b

Browse files
committed
JSlint fixes for postgres.js and a bug fix or two.
1 parent 24f469a commit f76054b

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

postgres.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var formatter = {
3838
.push_cstring(query)
3939
.push_int16(var_types.length);
4040
var_types.each(function (var_type) {
41-
stream.push_int32(var_type);
41+
builder.push_int32(var_type);
4242
});
4343
return builder;
4444
},
@@ -70,8 +70,8 @@ var formatter = {
7070

7171
// Parse response streams from the server
7272
function parse_response(code, stream) {
73-
var input = new bits.Decoder(stream);
74-
var type, args;
73+
var input, type, args, num_fields, data, size, i;
74+
input = new bits.Decoder(stream);
7575
args = [];
7676
switch (code) {
7777
case 'R':
@@ -126,10 +126,10 @@ function parse_response(code, stream) {
126126
break;
127127
case 'T':
128128
type = "RowDescription";
129-
var num_fields = stream.shift_int16();
130-
var row = [];
131-
for (var i = 0; i < num_fields; i += 1) {
132-
row.push({
129+
num_fields = stream.shift_int16();
130+
data = [];
131+
for (i = 0; i < num_fields; i += 1) {
132+
data.push({
133133
field: stream.shift_cstring(),
134134
table_id: stream.shift_int32(),
135135
column_id: stream.shift_int16(),
@@ -139,14 +139,14 @@ function parse_response(code, stream) {
139139
format_code: stream.shift_int16()
140140
});
141141
}
142-
args = [row];
142+
args = [data];
143143
break;
144144
case 'D':
145145
type = "DataRow";
146-
var data = [];
147-
var num_cols = stream.shift_int16();
148-
for (i = 0; i < num_cols; i += 1) {
149-
var size = stream.shift_int32();
146+
data = [];
147+
num_fields = stream.shift_int16();
148+
for (i = 0; i < num_fields; i += 1) {
149+
size = stream.shift_int32();
150150
if (size === -1) {
151151
data.push(null);
152152
} else {
@@ -168,20 +168,18 @@ function parse_response(code, stream) {
168168

169169

170170
exports.Connection = function (database, username, password, port) {
171+
var connection, events, query_queue, row_description, query_callback, results, readyState, closeState;
171172

172173
// Default to port 5432
173174
if (port === undefined) {
174175
port = 5432;
175176
}
176177

177-
var connection = tcp.createConnection(port);
178-
var events = new process.EventEmitter();
179-
var query_queue = [];
180-
var row_description;
181-
var query_callback;
182-
var results;
183-
var readyState = false;
184-
var closeState = false;
178+
connection = tcp.createConnection(port);
179+
events = new process.EventEmitter();
180+
query_queue = [];
181+
readyState = false;
182+
closeState = false;
185183

186184
// Sends a message to the postgres server
187185
function sendMessage(type, args) {
@@ -201,19 +199,20 @@ exports.Connection = function (database, username, password, port) {
201199
sendMessage('StartupMessage', [{user: username, database: database}]);
202200
});
203201
connection.addListener("receive", function (data) {
204-
var input = new bits.Decoder(data);
202+
var input, code, len, stream, command;
203+
input = new bits.Decoder(data);
205204
if (exports.DEBUG > 2) {
206205
sys.debug("<-" + JSON.stringify(data));
207206
}
208207

209208
while (input.data.length > 0) {
210-
var code = input.shift_code();
211-
var len = input.shift_int32();
212-
var stream = new bits.Decoder(input.shift_raw_string(len - 4));
209+
code = input.shift_code();
210+
len = input.shift_int32();
211+
stream = new bits.Decoder(input.shift_raw_string(len - 4));
213212
if (exports.DEBUG > 1) {
214213
sys.debug("stream: " + code + " " + JSON.stringify(stream));
215214
}
216-
var command = parse_response(code, stream);
215+
command = parse_response(code, stream);
217216
if (command.type) {
218217
if (exports.DEBUG > 0) {
219218
sys.debug("Received " + command.type + ": " + JSON.stringify(command.args));
@@ -265,10 +264,12 @@ exports.Connection = function (database, username, password, port) {
265264
results = [];
266265
});
267266
events.addListener("DataRow", function (data) {
268-
var row = {};
269-
for (var i = 0, l = data.length; i < l; i += 1) {
270-
var description = row_description[i];
271-
var value = data[i];
267+
var row, i, l, description, value;
268+
row = {};
269+
l = data.length;
270+
for (i = 0; i < l; i += 1) {
271+
description = row_description[i];
272+
value = data[i];
272273
if (value !== null) {
273274
// TODO: investigate to see if these numbers are stable across databases or
274275
// if we need to dynamically pull them from the pg_types table

0 commit comments

Comments
 (0)