Comparing version 0.2.0 to 0.2.1
var Command = require('./command'); | ||
var Packets = require('../packets/index.js'); | ||
var util = require('util'); | ||
var compileParser = require('../compile_text_parser'); | ||
@@ -14,2 +15,3 @@ function Query(sql, callback) | ||
this.rows = []; | ||
this.rowParser = null; | ||
} | ||
@@ -36,7 +38,22 @@ util.inherits(Query, Command); | ||
Query.prototype.readField = function(packet) { | ||
function getFieldsKey(fields) { | ||
var res = ''; | ||
for (var i=0; i < fields.length; ++i) | ||
res += '/' + fields[i].name + ':' + fields[i].columnType; | ||
return res; | ||
} | ||
Query.prototype.readField = function(packet, connection) { | ||
var field = new Packets.ColumnDefinition(packet); | ||
this.fields.push(field); | ||
if (this.fields.length == this.fieldCount) | ||
if (this.fields.length == this.fieldCount) { | ||
var parserKey = getFieldsKey(this.fields); | ||
// try cached first | ||
this.rowParser = connection.textProtocolParsers[parserKey]; | ||
if (!this.rowParser) { | ||
this.rowParser = compileParser(this.fields); | ||
connection.textProtocolParsers[parserKey] = this.rowParser; | ||
} | ||
return Query.prototype.fieldsEOF; | ||
} | ||
return Query.prototype.readField; | ||
@@ -49,4 +66,2 @@ }; | ||
throw "Expected EOF packet"; | ||
// PROFILING | ||
this._fieldsEOFTime = process.hrtime(); | ||
return Query.prototype.row; | ||
@@ -62,4 +77,16 @@ }; | ||
} | ||
if (this.rowParser) { | ||
// compiled version: | ||
// TODO: compile (and assign to this.next) whole command handler, not just row constructor+parser? | ||
var row = new this.rowParser(packet); | ||
if (this.onResult) | ||
this.rows.push(row); | ||
else | ||
this.emit('result', row); | ||
return Query.prototype.row; | ||
} | ||
// non-compiled | ||
var row = Packets.TextRow.fromPacket(packet); | ||
// TODO: here we'll have dynamically pre-compiled and cached row parser | ||
@@ -66,0 +93,0 @@ if (true) // TODO: think of API to store raw copulns array (most probably connection options flags) |
@@ -39,3 +39,9 @@ var _ = require('underscore'); | ||
this.statements = {}; | ||
this._cmdBytesReceived = 0; | ||
// TODO: make it lru cache | ||
// https://github.com/mercadolibre/node-simple-lru-cache | ||
// or https://github.com/rsms/js-lru | ||
// or https://github.com/monsur/jscache | ||
// | ||
// key is field.name + ':' + field.columnType + '/' | ||
this.textProtocolParsers = {}; | ||
@@ -42,0 +48,0 @@ var connection = this; |
@@ -121,3 +121,3 @@ //var BigNumber = require("bignumber.js"); | ||
return this.parseInt(this.readLengthCodedNumber()); | ||
} | ||
}; | ||
@@ -124,0 +124,0 @@ Packet.prototype.isError = function() { |
{ | ||
"name": "mysql2", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "fast mysql driver", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45044
40
1285
10