Socket
Socket
Sign inDemoInstall

mysql2

Package Overview
Dependencies
Maintainers
1
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql2 - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

lib/compile_text_parser.js

37

lib/commands/query.js
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;

2

lib/packets/packet.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc