result.js
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Result:
// Result set
var sys = require('sys');
var utils = require('./utils');
// Result set
var ResultBase = function(fields) {
this.fields = fields;
this.records = [];
this.fieldname_with_table = false;
}
exports.ResultBase = ResultBase;
var Result = function(fields, protocol) {
ResultBase.call(this, fields);
this.protocol = protocol;
}
sys.inherits(Result, ResultBase);
exports.Result = Result;
Result.prototype.fetch_all = function() {
var promise = this.protocol.retr_all_records(this.fields,
utils.scope(this, function(rec) { // each
this.records.push(rec);
}),
utils.scope(this, function() { // result
return this;
}));
return promise;
}
Result.prototype.toHash = function(row) {
var result, name, field;
result = {};
for(var i = 0; i<this.fields.length; ++i) {
field = this.fields[i];
name = ((this.fieldname_with_table && field.table) ? (field.table+".") : "") + field.name;
result[name] = row[i];
}
return result;
}
var StatementResult = function(fields, protocol) {
ResultBase.call(this, fields);
this.protocol = protocol;
}
sys.inherits(StatementResult, ResultBase);
exports.StatementResult = Result;
/*
node-mysql
A node.js interface for MySQL
Author: masuidrive <masui@masuidrive.jp>
License: MIT License
Copyright (c) Yuichiro MASUI
# Original:
# http://github.com/tmtm/ruby-mysql
# Copyright (C) 2009-2010 TOMITA Masahiro
# mailto:tommy@tmtm.org
# License: Ruby's
*/