Comparing version 3.7.1 to 3.8.0
@@ -282,3 +282,3 @@ 'use strict'; | ||
stream.push(null); // pushing null, indicating EOF | ||
stream.emit('close'); // notify readers that query has completed | ||
setImmediate(() => stream.emit('close')); // notify readers that query has completed | ||
}); | ||
@@ -285,0 +285,0 @@ this.on('fields', fields => { |
'use strict'; | ||
const Iconv = require('iconv-lite'); | ||
const LRU = require('lru-cache').default; | ||
exports.decode = function(buffer, encoding, start, end, options) { | ||
const decoderCache = new LRU({ | ||
max: 500, | ||
}); | ||
exports.decode = function (buffer, encoding, start, end, options) { | ||
if (Buffer.isEncoding(encoding)) { | ||
@@ -10,3 +15,19 @@ return buffer.toString(encoding, start, end); | ||
const decoder = Iconv.getDecoder(encoding, options || {}); | ||
// Optimize for common case: encoding="short_string", options=undefined. | ||
let decoder; | ||
if (!options) { | ||
decoder = decoderCache.get(encoding); | ||
if (!decoder) { | ||
decoder = Iconv.getDecoder(encoding); | ||
decoderCache.set(encoding, decoder); | ||
} | ||
} else { | ||
const decoderArgs = { encoding, options }; | ||
const decoderKey = JSON.stringify(decoderArgs); | ||
decoder = decoderCache.get(decoderKey); | ||
if (!decoder) { | ||
decoder = Iconv.getDecoder(decoderArgs.encoding, decoderArgs.options); | ||
decoderCache.set(decoderKey, decoder); | ||
} | ||
} | ||
@@ -19,3 +40,3 @@ const res = decoder.write(buffer.slice(start, end)); | ||
exports.encode = function(string, encoding, options) { | ||
exports.encode = function (string, encoding, options) { | ||
if (Buffer.isEncoding(encoding)) { | ||
@@ -22,0 +43,0 @@ return Buffer.from(string, encoding); |
@@ -103,2 +103,3 @@ 'use strict'; | ||
this._closed = true; | ||
clearTimeout(this._removeIdleTimeoutConnectionsTimer); | ||
if (typeof cb !== 'function') { | ||
@@ -105,0 +106,0 @@ cb = function(err) { |
{ | ||
"name": "mysql2", | ||
"version": "3.7.1", | ||
"version": "3.8.0", | ||
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,2 +22,3 @@ // This file was modified by Oracle on November 04, 2021. | ||
import { ExecutableBase } from './protocol/sequences/ExecutableBase.js'; | ||
import { TypeCast } from './parsers/typeCast.js'; | ||
@@ -176,22 +177,44 @@ export interface SslOptions { | ||
/** | ||
* Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future) | ||
* to disable type casting, but you can currently do so on either the connection or query level. (Default: true) | ||
* Determines if column values should be converted to native JavaScript types. | ||
* | ||
* You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself. | ||
* @default true | ||
* | ||
* WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once. | ||
* It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level. | ||
* | ||
* field.string() | ||
* field.buffer() | ||
* field.geometry() | ||
* --- | ||
* | ||
* are aliases for | ||
* You can also specify a function to do the type casting yourself: | ||
* ```ts | ||
* (field: Field, next: () => void) => { | ||
* return next(); | ||
* } | ||
* ``` | ||
* | ||
* parser.parseLengthCodedString() | ||
* parser.parseLengthCodedBuffer() | ||
* parser.parseGeometryValue() | ||
* --- | ||
* | ||
* You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast | ||
* **WARNING:** | ||
* | ||
* YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once: | ||
* | ||
* ```js | ||
* field.string(); | ||
* field.buffer(); | ||
* field.geometry(); | ||
* ``` | ||
* Which are aliases for: | ||
* | ||
* ```js | ||
* parser.parseLengthCodedString(); | ||
* parser.parseLengthCodedBuffer(); | ||
* parser.parseGeometryValue(); | ||
* ``` | ||
* | ||
* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`. | ||
* | ||
* --- | ||
* | ||
* For `execute`, please see: [typeCast not supported with .execute #649](https://github.com/sidorares/node-mysql2/issues/649). | ||
*/ | ||
typeCast?: boolean | ((field: any, next: () => void) => any); | ||
typeCast?: TypeCast; | ||
@@ -198,0 +221,0 @@ /** |
import { Sequence } from './Sequence.js'; | ||
import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js'; | ||
import { Readable } from 'stream'; | ||
import { TypeCast } from '../../parsers/typeCast.js'; | ||
@@ -36,22 +37,44 @@ export interface QueryOptions { | ||
/** | ||
* Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future) | ||
* to disable type casting, but you can currently do so on either the connection or query level. (Default: true) | ||
* Determines if column values should be converted to native JavaScript types. | ||
* | ||
* You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself. | ||
* @default true | ||
* | ||
* WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once. | ||
* It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level. | ||
* | ||
* field.string() | ||
* field.buffer() | ||
* field.geometry() | ||
* --- | ||
* | ||
* are aliases for | ||
* You can also specify a function to do the type casting yourself: | ||
* ```ts | ||
* (field: Field, next: () => void) => { | ||
* return next(); | ||
* } | ||
* ``` | ||
* | ||
* parser.parseLengthCodedString() | ||
* parser.parseLengthCodedBuffer() | ||
* parser.parseGeometryValue() | ||
* --- | ||
* | ||
* You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast | ||
* **WARNING:** | ||
* | ||
* YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once: | ||
* | ||
* ```js | ||
* field.string(); | ||
* field.buffer(); | ||
* field.geometry(); | ||
* ``` | ||
* Which are aliases for: | ||
* | ||
* ```js | ||
* parser.parseLengthCodedString(); | ||
* parser.parseLengthCodedBuffer(); | ||
* parser.parseGeometryValue(); | ||
* ``` | ||
* | ||
* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`. | ||
* | ||
* --- | ||
* | ||
* For `execute`, please see: [typeCast not supported with .execute #649](https://github.com/sidorares/node-mysql2/issues/649). | ||
*/ | ||
typeCast?: any; | ||
typeCast?: TypeCast; | ||
@@ -141,7 +164,7 @@ /** | ||
event: 'fields', | ||
listener: (fields: FieldPacket, index: number) => any | ||
listener: (fields: FieldPacket, index: number) => any, | ||
): this; | ||
on( | ||
event: 'result', | ||
listener: (result: RowDataPacket | OkPacket, index: number) => any | ||
listener: (result: RowDataPacket | OkPacket, index: number) => any, | ||
): this; | ||
@@ -148,0 +171,0 @@ on(event: 'end', listener: () => any): this; |
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
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
602070
109
15181