Skip to content

Commit aa50781

Browse files
committed
Additional array row explanation.
1 parent fcd9ec7 commit aa50781

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
- [Error handling](#error-handling)
4848
- [Exception Safety](#exception-safety)
4949
- [Type casting](#type-casting)
50+
- [Array row](#array-row)
5051
- [Connection Flags](#connection-flags)
5152
- [Debugging and reporting problems](#debugging-and-reporting-problems)
5253
- [Security issues](#security-issues)
@@ -1336,6 +1337,22 @@ parser.parseGeometryValue()
13361337
__You can find which field function you need to use by looking at: [RowDataPacket.prototype._typeCast](https://github.com/mysqljs/mysql/blob/master/lib/protocol/packets/RowDataPacket.js#L41)__
13371338

13381339

1340+
## Array row
1341+
1342+
The rows of a table can be returned as an array or an object on query or on connection level (including pooled connections):
1343+
1344+
```js
1345+
var connection = require('mysql').createConnection({arrayRow: true});
1346+
```
1347+
1348+
```js
1349+
connection.query({sql: '...', arrayRow: true}, function (err, result, fields) {
1350+
if (error) throw error;
1351+
// ...
1352+
});
1353+
```
1354+
1355+
13391356
## Connection Flags
13401357

13411358
If, for any reason, you would like to change the default connection flags, you

lib/protocol/sequences/Query.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ Query.prototype._handleFinalResultPacket = function(packet) {
141141

142142
Query.prototype['RowDataPacket'] = function(packet, parser, connection) {
143143
var row;
144+
144145
if (this.arrayRow) {
145146
row = packet.parseAsArray(parser, this._resultSet.fieldPackets, this.typeCast, connection);
146147
} else {
147148
packet.parse(parser, this._resultSet.fieldPackets, this.typeCast, this.nestTables, connection);
148149
row = packet;
149150
}
151+
150152
if (this._callback) {
151153
this._resultSet.rows.push(row);
152154
} else {

0 commit comments

Comments
 (0)