mysql2 3.9.2 → 3.9.3

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.
@@ -47,7 +47,7 @@ class ColumnDefinition {
47
47
  this.name = StringParser.decode(
48
48
  this._buf,
49
49
  this.encoding === 'binary' ? this._clientEncoding : this.encoding,
50
- _nameStart,
50
+ _nameStart,
51
51
  _nameStart + _nameLength
52
52
  );
53
53
  this.columnLength = packet.readInt32();
@@ -90,7 +90,7 @@ class ColumnDefinition {
90
90
  if (f === 'PRI_KEY') {
91
91
  flagNames.push('PRIMARY KEY');
92
92
  } else if (f === 'NOT_NULL') {
93
- flagNames.push('NOT NULL');
93
+ flagNames.push('NOT NULL');
94
94
  } else if (f === 'BINARY') {
95
95
  // ignore flag for now
96
96
  } else if (f === 'MULTIPLE_KEY') {
@@ -98,7 +98,7 @@ class ColumnDefinition {
98
98
  // in the schema usually this is part of index definition
99
99
  // example: UNIQUE KEY `my_uniq_id` (`id_box_elements`,`id_router`)
100
100
  // note that only first column has MULTIPLE_KEY flag set in this case
101
- // so there is no good way of knowing that this is part of index just
101
+ // so there is no good way of knowing that this is part of index just
102
102
  // by looking at indifidual field flags
103
103
  } else if (f === 'NO_DEFAULT_VALUE') {
104
104
  // almost the same as NOT_NULL?
@@ -265,10 +265,10 @@ const addString = function(name) {
265
265
  const val = StringParser.decode(
266
266
  this._buf,
267
267
  this.encoding === 'binary' ? this._clientEncoding : this.encoding,
268
- start,
268
+ start,
269
269
  end
270
270
  );
271
-
271
+
272
272
  Object.defineProperty(this, name, {
273
273
  value: val,
274
274
  writable: false,
@@ -3,26 +3,38 @@
3
3
  const LRU = require('lru-cache').default;
4
4
 
5
5
  const parserCache = new LRU({
6
- max: 15000
6
+ max: 15000,
7
7
  });
8
8
 
9
9
  function keyFromFields(type, fields, options, config) {
10
- let res =
11
- `${type}` +
12
- `/${typeof options.nestTables}` +
13
- `/${options.nestTables}` +
14
- `/${options.rowsAsArray}` +
15
- `/${options.supportBigNumbers || config.supportBigNumbers}` +
16
- `/${options.bigNumberStrings || config.bigNumberStrings}` +
17
- `/${typeof options.typeCast}` +
18
- `/${options.timezone || config.timezone}` +
19
- `/${options.decimalNumbers}` +
20
- `/${options.dateStrings}`;
10
+ const res = [
11
+ type,
12
+ typeof options.nestTables,
13
+ options.nestTables,
14
+ Boolean(options.rowsAsArray),
15
+ Boolean(options.supportBigNumbers || config.supportBigNumbers),
16
+ Boolean(options.bigNumberStrings || config.bigNumberStrings),
17
+ typeof options.typeCast,
18
+ options.timezone || config.timezone,
19
+ Boolean(options.decimalNumbers),
20
+ options.dateStrings,
21
+ ];
22
+
21
23
  for (let i = 0; i < fields.length; ++i) {
22
24
  const field = fields[i];
23
- res += `/${field.name}:${field.columnType}:${field.length}:${field.schema}:${field.table}:${field.flags}:${field.characterSet}`;
25
+
26
+ res.push([
27
+ field.name,
28
+ field.columnType,
29
+ field.length,
30
+ field.schema,
31
+ field.table,
32
+ field.flags,
33
+ field.characterSet,
34
+ ]);
24
35
  }
25
- return res;
36
+
37
+ return JSON.stringify(res, null, 0);
26
38
  }
27
39
 
28
40
  function getParser(type, fields, options, config, compiler) {
@@ -49,5 +61,6 @@ function clearCache() {
49
61
  module.exports = {
50
62
  getParser: getParser,
51
63
  setMaxCache: setMaxCache,
52
- clearCache: clearCache
64
+ clearCache: clearCache,
65
+ _keyFromFields: keyFromFields,
53
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.9.2",
3
+ "version": "3.9.3",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "typings": "typings/mysql/index",
@@ -8,10 +8,12 @@
8
8
  "lint": "npm run lint:docs && npm run lint:code",
9
9
  "lint:code": "eslint index.js promise.js index.d.ts promise.d.ts \"typings/**/*.ts\" \"lib/**/*.js\" \"test/**/*.{js,ts}\" \"benchmarks/**/*.js\"",
10
10
  "lint:docs": "eslint Contributing.md README.md",
11
- "test": "node ./test/run.js",
12
- "test:builtin-node-runner": "NODE_V8_COVERAGE=./coverage node --test --experimental-test-coverage test/builtin-runner",
11
+ "lint:typings": "npx prettier --check ./typings",
12
+ "lint:tests": "npx prettier --check ./test",
13
+ "test": "poku --debug --include=\"test/esm,test/unit,test/integration\"",
14
+ "test:bun": "poku --debug --platform=\"bun\" --include=\"test/esm,test/unit,test/integration\"",
13
15
  "test:tsc-build": "cd \"test/tsc-build\" && npx tsc -p \"tsconfig.json\"",
14
- "coverage-test": "c8 -r cobertura -r lcov -r text node ./test/run.js",
16
+ "coverage-test": "c8 -r cobertura -r lcov -r text npm run test",
15
17
  "benchmark": "node ./benchmarks/benchmark.js",
16
18
  "prettier": "prettier --single-quote --trailing-comma none --write \"{lib,test}/**/*.js\"",
17
19
  "prettier:docs": "prettier --single-quote --trailing-comma none --write README.md",
@@ -75,13 +77,13 @@
75
77
  "eslint": "^8.27.0",
76
78
  "eslint-config-prettier": "^9.0.0",
77
79
  "eslint-plugin-async-await": "0.0.0",
78
- "eslint-plugin-markdown": "^3.0.0",
80
+ "eslint-plugin-markdown": "^4.0.1",
79
81
  "husky": "^9.0.2",
80
82
  "lint-staged": "^15.0.1",
83
+ "poku": "^1.8.1",
81
84
  "portfinder": "^1.0.28",
82
85
  "prettier": "^3.0.0",
83
86
  "progress": "^2.0.3",
84
- "typescript": "^5.0.2",
85
- "utest": "0.0.8"
87
+ "typescript": "^5.0.2"
86
88
  }
87
89
  }
@@ -62,14 +62,14 @@ export function format(
62
62
  sql: string,
63
63
  values: any[],
64
64
  stringifyObjects?: boolean,
65
- timeZone?: string
65
+ timeZone?: string,
66
66
  ): string;
67
67
 
68
68
  export function format(
69
69
  sql: string,
70
70
  values: any,
71
71
  stringifyObjects?: boolean,
72
- timeZone?: string
72
+ timeZone?: string,
73
73
  ): string;
74
74
 
75
75
  export function raw(sql: string): {
@@ -5,7 +5,7 @@ export type AuthPlugin = (pluginMetadata: {
5
5
  connection: Connection;
6
6
  command: string;
7
7
  }) => (
8
- pluginData: Buffer
8
+ pluginData: Buffer,
9
9
  ) => Promise<string> | string | Buffer | Promise<Buffer> | null;
10
10
 
11
11
  type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin;
@@ -43,14 +43,14 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
43
43
  getConnection(
44
44
  callback: (
45
45
  err: NodeJS.ErrnoException | null,
46
- connection: PoolConnection
47
- ) => any
46
+ connection: PoolConnection,
47
+ ) => any,
48
48
  ): void;
49
49
 
50
50
  releaseConnection(connection: PoolConnection | PromisePoolConnection): void;
51
51
 
52
52
  end(
53
- callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any
53
+ callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any,
54
54
  ): void;
55
55
 
56
56
  on(event: string, listener: (...args: any[]) => void): this;
@@ -6,7 +6,7 @@ import { QueryableBase as QueryableBaseClass } from './protocol/sequences/Querya
6
6
 
7
7
  // Expose class interfaces
8
8
  declare class QueryableAndExecutableBase extends QueryableBaseClass(
9
- ExecutableBaseClass(EventEmitter)
9
+ ExecutableBaseClass(EventEmitter),
10
10
  ) {}
11
11
 
12
12
  export interface PoolClusterOptions {
@@ -40,8 +40,8 @@ export interface PoolNamespace extends QueryableAndExecutableBase {
40
40
  getConnection(
41
41
  callback: (
42
42
  err: NodeJS.ErrnoException | null,
43
- connection: PoolConnection
44
- ) => any
43
+ connection: PoolConnection,
44
+ ) => any,
45
45
  ): void;
46
46
  }
47
47
 
@@ -57,23 +57,23 @@ declare class PoolCluster extends EventEmitter {
57
57
  getConnection(
58
58
  callback: (
59
59
  err: NodeJS.ErrnoException | null,
60
- connection: PoolConnection
61
- ) => void
60
+ connection: PoolConnection,
61
+ ) => void,
62
62
  ): void;
63
63
  getConnection(
64
64
  group: string,
65
65
  callback: (
66
66
  err: NodeJS.ErrnoException | null,
67
- connection: PoolConnection
68
- ) => void
67
+ connection: PoolConnection,
68
+ ) => void,
69
69
  ): void;
70
70
  getConnection(
71
71
  group: string,
72
72
  selector: string,
73
73
  callback: (
74
74
  err: NodeJS.ErrnoException | null,
75
- connection: PoolConnection
76
- ) => void
75
+ connection: PoolConnection,
76
+ ) => void,
77
77
  ): void;
78
78
 
79
79
  of(pattern: string, selector?: string): PoolNamespace;
@@ -17,7 +17,7 @@ declare interface FieldPacket {
17
17
  protocol41?: boolean;
18
18
  table: string;
19
19
  type?: number;
20
- columnType?: number
20
+ columnType?: number;
21
21
  zerofill?: boolean;
22
22
  typeName?: string;
23
23
  encoding?: string;
@@ -17,7 +17,7 @@ declare interface OkPacket {
17
17
  serverStatus: number;
18
18
  warningCount: number;
19
19
  message: string;
20
- procotol41: boolean;
20
+ protocol41: boolean;
21
21
  }
22
22
 
23
23
  export { OkPacket };
@@ -7,7 +7,7 @@ declare type ProcedureCallPacket<
7
7
  > = T extends RowDataPacket[]
8
8
  ? [T, ResultSetHeader]
9
9
  : T extends ResultSetHeader | OkPacket
10
- ? ResultSetHeader
11
- : [RowDataPacket[], ResultSetHeader] | ResultSetHeader;
10
+ ? ResultSetHeader
11
+ : [RowDataPacket[], ResultSetHeader] | ResultSetHeader;
12
12
 
13
13
  export { ProcedureCallPacket };
@@ -7,6 +7,15 @@ import { ResultSetHeader } from './ResultSetHeader.js';
7
7
  import { OkPacketParams } from './params/OkPacketParams.js';
8
8
  import { ErrorPacketParams } from './params/ErrorPacketParams.js';
9
9
 
10
+ export type QueryResult =
11
+ | OkPacket
12
+ | ResultSetHeader
13
+ | ResultSetHeader[]
14
+ | RowDataPacket[]
15
+ | RowDataPacket[][]
16
+ | OkPacket[]
17
+ | ProcedureCallPacket;
18
+
10
19
  export {
11
20
  OkPacket,
12
21
  RowDataPacket,
@@ -1,10 +1,4 @@
1
- import {
2
- OkPacket,
3
- FieldPacket,
4
- RowDataPacket,
5
- ResultSetHeader,
6
- ProcedureCallPacket,
7
- } from '../packets/index.js';
1
+ import { FieldPacket, QueryResult } from '../packets/index.js';
8
2
  import {
9
3
  Query,
10
4
  QueryError,
@@ -13,70 +7,34 @@ import {
13
7
  } from './Query.js';
14
8
 
15
9
  export declare function ExecutableBase<T extends QueryableConstructor>(
16
- Base?: T
10
+ Base?: T,
17
11
  ): {
18
12
  new (...args: any[]): {
19
- execute<
20
- T extends
21
- | OkPacket
22
- | ResultSetHeader
23
- | ResultSetHeader[]
24
- | RowDataPacket[]
25
- | RowDataPacket[][]
26
- | OkPacket[]
27
- | ProcedureCallPacket
28
- >(
13
+ execute<T extends QueryResult>(
29
14
  sql: string,
30
15
  callback?:
31
16
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
32
- | undefined
17
+ | undefined,
33
18
  ): Query;
34
- execute<
35
- T extends
36
- | OkPacket
37
- | ResultSetHeader
38
- | ResultSetHeader[]
39
- | RowDataPacket[]
40
- | RowDataPacket[][]
41
- | OkPacket[]
42
- | ProcedureCallPacket
43
- >(
19
+ execute<T extends QueryResult>(
44
20
  sql: string,
45
21
  values: any,
46
22
  callback?:
47
23
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
48
- | undefined
24
+ | undefined,
49
25
  ): Query;
50
- execute<
51
- T extends
52
- | OkPacket
53
- | ResultSetHeader
54
- | ResultSetHeader[]
55
- | RowDataPacket[]
56
- | RowDataPacket[][]
57
- | OkPacket[]
58
- | ProcedureCallPacket
59
- >(
26
+ execute<T extends QueryResult>(
60
27
  options: QueryOptions,
61
28
  callback?:
62
29
  | ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
63
- | undefined
30
+ | undefined,
64
31
  ): Query;
65
- execute<
66
- T extends
67
- | OkPacket
68
- | ResultSetHeader
69
- | ResultSetHeader[]
70
- | RowDataPacket[]
71
- | RowDataPacket[][]
72
- | OkPacket[]
73
- | ProcedureCallPacket
74
- >(
32
+ execute<T extends QueryResult>(
75
33
  options: QueryOptions,
76
34
  values: any,
77
35
  callback?:
78
36
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
79
- | undefined
37
+ | undefined,
80
38
  ): Query;
81
39
  };
82
40
  } & T;
@@ -16,10 +16,14 @@ export class PrepareStatementInfo {
16
16
  | RowDataPacket[]
17
17
  | OkPacket
18
18
  | OkPacket[]
19
- | ResultSetHeader
19
+ | ResultSetHeader,
20
20
  >(
21
21
  parameters: any | any[] | { [param: string]: any },
22
- callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
22
+ callback?: (
23
+ err: QueryError | null,
24
+ result: T,
25
+ fields: FieldPacket[],
26
+ ) => any,
23
27
  ): Query;
24
28
  }
25
29
 
@@ -53,11 +57,11 @@ declare class Prepare extends Sequence {
53
57
  on(event: 'error', listener: (err: QueryError) => any): this;
54
58
  on(
55
59
  event: 'fields',
56
- listener: (fields: FieldPacket, index: number) => any
60
+ listener: (fields: FieldPacket, index: number) => any,
57
61
  ): this;
58
62
  on(
59
63
  event: 'result',
60
- listener: (result: RowDataPacket | OkPacket, index: number) => any
64
+ listener: (result: RowDataPacket | OkPacket, index: number) => any,
61
65
  ): this;
62
66
  on(event: 'end', listener: () => any): this;
63
67
  }
@@ -1,10 +1,4 @@
1
- import {
2
- OkPacket,
3
- FieldPacket,
4
- RowDataPacket,
5
- ResultSetHeader,
6
- ProcedureCallPacket,
7
- } from '../packets/index.js';
1
+ import { FieldPacket, QueryResult } from '../packets/index.js';
8
2
  import {
9
3
  Query,
10
4
  QueryError,
@@ -13,70 +7,34 @@ import {
13
7
  } from './Query.js';
14
8
 
15
9
  export declare function QueryableBase<T extends QueryableConstructor>(
16
- Base?: T
10
+ Base?: T,
17
11
  ): {
18
12
  new (...args: any[]): {
19
- query<
20
- T extends
21
- | OkPacket
22
- | ResultSetHeader
23
- | ResultSetHeader[]
24
- | RowDataPacket[]
25
- | RowDataPacket[][]
26
- | OkPacket[]
27
- | ProcedureCallPacket
28
- >(
13
+ query<T extends QueryResult>(
29
14
  sql: string,
30
15
  callback?:
31
16
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
32
- | undefined
17
+ | undefined,
33
18
  ): Query;
34
- query<
35
- T extends
36
- | OkPacket
37
- | ResultSetHeader
38
- | ResultSetHeader[]
39
- | RowDataPacket[]
40
- | RowDataPacket[][]
41
- | OkPacket[]
42
- | ProcedureCallPacket
43
- >(
19
+ query<T extends QueryResult>(
44
20
  sql: string,
45
21
  values: any,
46
22
  callback?:
47
23
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
48
- | undefined
24
+ | undefined,
49
25
  ): Query;
50
- query<
51
- T extends
52
- | OkPacket
53
- | ResultSetHeader
54
- | ResultSetHeader[]
55
- | RowDataPacket[]
56
- | RowDataPacket[][]
57
- | OkPacket[]
58
- | ProcedureCallPacket
59
- >(
26
+ query<T extends QueryResult>(
60
27
  options: QueryOptions,
61
28
  callback?:
62
29
  | ((err: QueryError | null, result: T, fields?: FieldPacket[]) => any)
63
- | undefined
30
+ | undefined,
64
31
  ): Query;
65
- query<
66
- T extends
67
- | OkPacket
68
- | ResultSetHeader
69
- | ResultSetHeader[]
70
- | RowDataPacket[]
71
- | RowDataPacket[][]
72
- | OkPacket[]
73
- | ProcedureCallPacket
74
- >(
32
+ query<T extends QueryResult>(
75
33
  options: QueryOptions,
76
34
  values: any,
77
35
  callback?:
78
36
  | ((err: QueryError | null, result: T, fields: FieldPacket[]) => any)
79
- | undefined
37
+ | undefined,
80
38
  ): Query;
81
39
  };
82
40
  } & T;
@@ -1,65 +1,21 @@
1
- import {
2
- OkPacket,
3
- FieldPacket,
4
- RowDataPacket,
5
- ResultSetHeader,
6
- ProcedureCallPacket,
7
- } from '../../packets/index.js';
1
+ import { FieldPacket, QueryResult } from '../../packets/index.js';
8
2
  import { QueryOptions, QueryableConstructor } from '../Query.js';
9
3
 
10
4
  export declare function ExecutableBase<T extends QueryableConstructor>(
11
- Base?: T
5
+ Base?: T,
12
6
  ): {
13
7
  new (...args: any[]): {
14
- execute<
15
- T extends
16
- | OkPacket
17
- | ResultSetHeader
18
- | ResultSetHeader[]
19
- | RowDataPacket[]
20
- | RowDataPacket[][]
21
- | OkPacket[]
22
- | ProcedureCallPacket
23
- >(
24
- sql: string
25
- ): Promise<[T, FieldPacket[]]>;
26
- execute<
27
- T extends
28
- | OkPacket
29
- | ResultSetHeader
30
- | ResultSetHeader[]
31
- | RowDataPacket[]
32
- | RowDataPacket[][]
33
- | OkPacket[]
34
- | ProcedureCallPacket
35
- >(
8
+ execute<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
9
+ execute<T extends QueryResult>(
36
10
  sql: string,
37
- values: any
11
+ values: any,
38
12
  ): Promise<[T, FieldPacket[]]>;
39
- execute<
40
- T extends
41
- | OkPacket
42
- | ResultSetHeader
43
- | ResultSetHeader[]
44
- | RowDataPacket[]
45
- | RowDataPacket[][]
46
- | OkPacket[]
47
- | ProcedureCallPacket
48
- >(
49
- options: QueryOptions
13
+ execute<T extends QueryResult>(
14
+ options: QueryOptions,
50
15
  ): Promise<[T, FieldPacket[]]>;
51
- execute<
52
- T extends
53
- | OkPacket
54
- | ResultSetHeader
55
- | ResultSetHeader[]
56
- | RowDataPacket[]
57
- | RowDataPacket[][]
58
- | OkPacket[]
59
- | ProcedureCallPacket
60
- >(
16
+ execute<T extends QueryResult>(
61
17
  options: QueryOptions,
62
- values: any
18
+ values: any,
63
19
  ): Promise<[T, FieldPacket[]]>;
64
20
  };
65
21
  } & T;
@@ -1,65 +1,21 @@
1
- import {
2
- OkPacket,
3
- FieldPacket,
4
- RowDataPacket,
5
- ResultSetHeader,
6
- ProcedureCallPacket,
7
- } from '../../packets/index.js';
1
+ import { FieldPacket, QueryResult } from '../../packets/index.js';
8
2
  import { QueryOptions, QueryableConstructor } from '../Query.js';
9
3
 
10
4
  export declare function QueryableBase<T extends QueryableConstructor>(
11
- Base?: T
5
+ Base?: T,
12
6
  ): {
13
7
  new (...args: any[]): {
14
- query<
15
- T extends
16
- | OkPacket
17
- | ResultSetHeader
18
- | ResultSetHeader[]
19
- | RowDataPacket[]
20
- | RowDataPacket[][]
21
- | OkPacket[]
22
- | ProcedureCallPacket
23
- >(
24
- sql: string
25
- ): Promise<[T, FieldPacket[]]>;
26
- query<
27
- T extends
28
- | OkPacket
29
- | ResultSetHeader
30
- | ResultSetHeader[]
31
- | RowDataPacket[]
32
- | RowDataPacket[][]
33
- | OkPacket[]
34
- | ProcedureCallPacket
35
- >(
8
+ query<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
9
+ query<T extends QueryResult>(
36
10
  sql: string,
37
- values: any
11
+ values: any,
38
12
  ): Promise<[T, FieldPacket[]]>;
39
- query<
40
- T extends
41
- | OkPacket
42
- | ResultSetHeader
43
- | ResultSetHeader[]
44
- | RowDataPacket[]
45
- | RowDataPacket[][]
46
- | OkPacket[]
47
- | ProcedureCallPacket
48
- >(
49
- options: QueryOptions
13
+ query<T extends QueryResult>(
14
+ options: QueryOptions,
50
15
  ): Promise<[T, FieldPacket[]]>;
51
- query<
52
- T extends
53
- | OkPacket
54
- | ResultSetHeader
55
- | ResultSetHeader[]
56
- | RowDataPacket[]
57
- | RowDataPacket[][]
58
- | OkPacket[]
59
- | ProcedureCallPacket
60
- >(
16
+ query<T extends QueryResult>(
61
17
  options: QueryOptions,
62
- values: any
18
+ values: any,
63
19
  ): Promise<[T, FieldPacket[]]>;
64
20
  };
65
21
  } & T;