Skip to content
Browse files

basic typecasting to Number types where appropriate

  • Loading branch information...
1 parent a7dd6fa commit 8c5e5beb80087cbb940127fc20e176e414e2b44d @andykent andykent committed Jul 13, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 result_set.js
View
10 result_set.js
@@ -8,8 +8,16 @@ ResultSet.prototype.each = function(cb) {
var rowArray = this.rows[i].split("\t");
var row = {};
var headers = this.headers();
+ var schema = this.schema;
+ typecast = function(column, stringValue) {
+ var found = schema.filter(function(s) { return s.name === column });
+ var type = 'string';
+ if(found.length === 1) type = found[0].type;
+ if(type === 'double' || type === 'float' || type === 'int') return Number(stringValue);
+ return stringValue;
+ };
for(var a in rowArray) {
- row[headers[a]] = rowArray[a];
+ row[headers[a]] = typecast(headers[a], rowArray[a]);
}
cb(row);
};

0 comments on commit 8c5e5be

Please sign in to comment.
Something went wrong with that request. Please try again.