mysql2 2.3.2 → 2.3.3-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -212,7 +212,7 @@ class Query extends Command {
212
212
  if (this._receivedFieldsCount === this._fieldCount) {
213
213
  const fields = this._fields[this._resultIndex];
214
214
  this.emit('fields', fields);
215
- this._rowParser = new (getTextParser(fields, this.options, connection.config))();
215
+ this._rowParser = new (getTextParser(fields, this.options, connection.config))(fields);
216
216
  return Query.prototype.fieldsEOF;
217
217
  }
218
218
  return Query.prototype.readField;
@@ -103,9 +103,7 @@ class ColumnDefinition {
103
103
 
104
104
  // node-mysql compatibility: alias "db" to "schema"
105
105
  get db() {
106
- const start = this._schemaStart;
107
- const end = start._shemaLength;
108
- return this._buf.utf8Slice(start, end);
106
+ return this.schema;
109
107
  }
110
108
  }
111
109
 
@@ -78,6 +78,25 @@ function compile(fields, options, config) {
78
78
  options.typeCast = config.typeCast;
79
79
  }
80
80
 
81
+ function wrap(field, _this) {
82
+ return {
83
+ type: typeNames[field.columnType],
84
+ length: field.columnLength,
85
+ db: field.schema,
86
+ table: field.table,
87
+ name: field.name,
88
+ string: function() {
89
+ return _this.packet.readLengthCodedString(field.encoding);
90
+ },
91
+ buffer: function() {
92
+ return _this.packet.readLengthCodedBuffer();
93
+ },
94
+ geometry: function() {
95
+ return _this.packet.parseGeometryValue();
96
+ }
97
+ };
98
+ }
99
+
81
100
  const parserFn = genFunc();
82
101
 
83
102
  /* eslint-disable no-trailing-spaces */
@@ -88,42 +107,14 @@ function compile(fields, options, config) {
88
107
  );
89
108
 
90
109
  // constructor method
91
- parserFn('constructor() {');
110
+ parserFn('constructor(fields) {');
92
111
  // node-mysql typeCast compatibility wrapper
93
112
  // see https://github.com/mysqljs/mysql/blob/96fdd0566b654436624e2375c7b6604b1f50f825/lib/protocol/packets/Field.js
94
113
  if (typeof options.typeCast === 'function') {
95
114
  parserFn('const _this = this;');
96
- for(let i=0; i<fields.length; ++i) {
97
- const field = fields[i];
98
- const encodingExpr = helpers.srcEscape(field.encoding);
99
- const readCode = readCodeFor(
100
- fields[i].columnType,
101
- fields[i].characterSet,
102
- encodingExpr,
103
- config,
104
- options
105
- );
106
- parserFn(`this.wrap${i} = {
107
- type: ${helpers.srcEscape(typeNames[field.columnType])},
108
- length: ${helpers.srcEscape(field.columnLength)},
109
- db: ${helpers.srcEscape(field.schema)},
110
- table: ${helpers.srcEscape(field.table)},
111
- name: ${helpers.srcEscape(field.name)},
112
- string: function() {
113
- return _this.packet.readLengthCodedString(${encodingExpr});
114
- },
115
- buffer: function() {
116
- return _this.packet.readLengthCodedBuffer();
117
- },
118
- geometry: function() {
119
- return _this.packet.parseGeometryValue();
120
- },
121
- readNext: function() {
122
- const packet = _this.packet;
123
- return ${readCode};
124
- }
125
- };`);
126
- }
115
+ parserFn('for(let i=0; i<fields.length; ++i) {');
116
+ parserFn('this[`wrap${i}`] = wrap(fields[i], _this);');
117
+ parserFn('}');
127
118
  }
128
119
  parserFn('}');
129
120
 
@@ -165,9 +156,7 @@ function compile(fields, options, config) {
165
156
  } else {
166
157
  lvalue = `result[${fieldName}]`;
167
158
  }
168
- if (typeof options.typeCast === 'function') {
169
- parserFn(`${lvalue} = options.typeCast(this.wrap${i}, this.wrap${i}.readNext);`);
170
- } else if (options.typeCast === false) {
159
+ if (options.typeCast === false) {
171
160
  parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
172
161
  } else {
173
162
  const encodingExpr = `fields[${i}].encoding`;
@@ -178,8 +167,12 @@ function compile(fields, options, config) {
178
167
  config,
179
168
  options
180
169
  );
181
- parserFn(`${lvalue} = ${readCode};`);
182
- }
170
+ if (typeof options.typeCast === 'function') {
171
+ parserFn(`${lvalue} = options.typeCast(this.wrap${i}, function() { return ${readCode} });`);
172
+ } else {
173
+ parserFn(`${lvalue} = ${readCode};`);
174
+ }
175
+ }
183
176
  }
184
177
 
185
178
  parserFn('return result;');
@@ -196,6 +189,9 @@ function compile(fields, options, config) {
196
189
  parserFn.toString()
197
190
  );
198
191
  }
192
+ if (typeof options.typeCast === 'function') {
193
+ return parserFn.toFunction({wrap});
194
+ }
199
195
  return parserFn.toFunction();
200
196
  }
201
197
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "2.3.2",
3
+ "version": "2.3.3-rc.0",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -11,6 +11,7 @@
11
11
  "lint:code": "eslint index.js promise.js \"lib/**/*.js\" \"test/**/*.js\" \"benchmarks/**/*.js\"",
12
12
  "lint:docs": "eslint Contributing.md \"documentation/**/*.md\" \"examples/*.js\"",
13
13
  "test": "node ./test/run.js",
14
+ "coverage-test": "c8 -r cobertura -r lcov -r text node ./test/run.js",
14
15
  "benchmark": "node ./benchmarks/benchmark.js",
15
16
  "prettier": "prettier --single-quote --trailing-comma none --write \"{lib,examples,test}/**/*.js\"",
16
17
  "prettier:docs": "prettier --single-quote --trailing-comma none --write README.md documentation/*",
@@ -66,6 +67,7 @@
66
67
  "@typescript-eslint/parser": "^4.33.0",
67
68
  "assert-diff": "^3.0.2",
68
69
  "benchmark": "^2.1.4",
70
+ "c8": "^7.10.0",
69
71
  "error-stack-parser": "^2.0.3",
70
72
  "eslint": "^7.32.0",
71
73
  "eslint-config-prettier": "^8.3.0",