-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#770 Add an option to return resultset as array
- Loading branch information
1 parent
cf5d1e3
commit b33370a
Showing
6 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var Charsets = require('../constants/charsets'); | ||
var RowDataPacket = require('./RowDataPacket'); | ||
var Field = require('./Field'); | ||
|
||
module.exports = ArrayRowDataPacket; | ||
function ArrayRowDataPacket() { | ||
} | ||
|
||
Object.defineProperty(ArrayRowDataPacket.prototype, 'parse', { | ||
configurable : true, | ||
enumerable : false, | ||
value : parse | ||
}); | ||
|
||
Object.defineProperty(ArrayRowDataPacket.prototype, '_typeCast', { | ||
configurable : true, | ||
enumerable : false, | ||
value : RowDataPacket.prototype._typeCast | ||
}); | ||
|
||
function parse(parser, fieldPackets, typeCast, nestTables, connection) { | ||
var self = this; | ||
var next = function () { | ||
return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings); | ||
}; | ||
this.values = []; | ||
|
||
for (var i = 0; i < fieldPackets.length; i++) { | ||
var fieldPacket = fieldPackets[i]; | ||
var value; | ||
|
||
if (typeof typeCast === 'function') { | ||
value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]); | ||
} else { | ||
value = (typeCast) | ||
? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings) | ||
: ( (fieldPacket.charsetNr === Charsets.BINARY) | ||
? parser.parseLengthCodedBuffer() | ||
: parser.parseLengthCodedString() ); | ||
} | ||
this.values[i] = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var assert = require('assert'); | ||
var common = require('../../common'); | ||
var connection = common.createConnection({port: common.fakeServerPort, user: 'testuser'}); | ||
|
||
var server = common.createFakeServer(); | ||
|
||
server.listen(common.fakeServerPort, function (err) { | ||
assert.ifError(err); | ||
|
||
connection.query({ | ||
sql : 'SELECT CURRENT_USER()', | ||
arrayRows : true | ||
}, function (err, rows) { | ||
assert.ifError(err); | ||
assert.deepEqual(rows, [['testuser@localhost']]); | ||
|
||
connection.destroy(); | ||
server.destroy(); | ||
}); | ||
|
||
}); |