Skip to content

Commit b274e72

Browse files
authored
fix(types): add supportBigNumbers, bigNumberStrings, dateStrings, and timezone options to QueryOptions (#4127)
* refactor: simplify typings * fix(types): add `supportBigNumbers`, `bigNumberStrings`, `dateStrings`, and `timezone` options to `QueryOptions` * ci: update tests * ci: remove debug
1 parent 69ee696 commit b274e72

File tree

11 files changed

+35
-18
lines changed

11 files changed

+35
-18
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
tool: 'benchmarkjs'
6666
output-file-path: output.txt
6767
external-data-json-path: ./cache/benchmark-data.json
68-
fail-on-alert: true
68+
fail-on-alert: false
6969
auto-push: false
7070
alert-threshold: '110%'
7171
github-token: ${{ secrets.GITHUB_TOKEN }}

test/integration/connection/test-binary-longlong.test.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ await describe('Binary LongLong', async () => {
8787
conn.query<RowDataPacket[]>(
8888
{
8989
sql: 'SELECT * from tmp_longlong',
90-
// @ts-expect-error: TODO: implement typings
9190
supportBigNumbers: supportBigNumbers,
9291
bigNumberStrings: bigNumberStrings,
9392
},
@@ -106,7 +105,6 @@ await describe('Binary LongLong', async () => {
106105
conn.execute<RowDataPacket[]>(
107106
{
108107
sql: 'SELECT * from tmp_longlong',
109-
// @ts-expect-error: TODO: implement typings
110108
supportBigNumbers: supportBigNumbers,
111109
bigNumberStrings: bigNumberStrings,
112110
},

test/integration/connection/test-insert-bigint.test.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ await describe('Insert BigInt', async () => {
7171
connection.query<BigRow[]>(
7272
{
7373
sql: 'select * from bigs',
74-
// @ts-expect-error: supportBigNumbers is not in QueryOptions typings
7574
supportBigNumbers: true,
76-
bigNumberString: false,
75+
bigNumberStrings: false,
7776
},
7877
(err, result) => (err ? reject(err) : resolve(result))
7978
);

test/unit/parsers/support-big-numbers-binary-sanitization.test.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ await describe('Binary Parser: supportBigNumbers Sanitization', async () => {
2929
await it(label, async () => {
3030
const [results] = await connection.execute<TotalRow[]>({
3131
sql,
32-
// @ts-expect-error: TODO: implement typings
3332
supportBigNumbers,
3433
});
3534

test/unit/parsers/support-big-numbers-text-sanitization.test.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ await describe('Text Parser: supportBigNumbers Sanitization', async () => {
2929
await it(label, async () => {
3030
const [results] = await connection.query<TotalRow[]>({
3131
sql,
32-
// @ts-expect-error: TODO: implement typings
3332
supportBigNumbers,
3433
});
3534

test/unit/parsers/timezone-binary-sanitization.test.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ await describe('Binary Parser: timezone Sanitization', async () => {
1010

1111
await connection.execute({
1212
sql: 'SELECT NOW()',
13-
// @ts-expect-error: TODO: implement typings
1413
timezone: `'); process.env.TEST_ENV_VALUE = "not so much"; //`,
1514
});
1615

test/unit/parsers/timezone-text-sanitization.test.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ await describe('Text Parser: timezone Sanitization', async () => {
1010

1111
await connection.query({
1212
sql: 'SELECT NOW()',
13-
// @ts-expect-error: TODO: implement typings
1413
timezone: `'); process.env.TEST_ENV_VALUE = "not so much"; //`,
1514
});
1615

typings/mysql/lib/Connection.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { EventEmitter } from 'events';
77
import { Readable } from 'stream';
8+
import { Timezone } from 'sql-escaper';
89
import { Query, QueryError } from './protocol/sequences/Query.js';
910
import { Prepare, PrepareStatementInfo } from './protocol/sequences/Prepare.js';
1011
import {
@@ -150,7 +151,7 @@ export interface ConnectionOptions {
150151
/**
151152
* The timezone used to store local dates. (Default: 'local')
152153
*/
153-
timezone?: string | 'local';
154+
timezone?: Timezone;
154155

155156
/**
156157
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)

typings/mysql/lib/protocol/sequences/Query.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Sequence } from './Sequence.js';
22
import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js';
33
import { Readable } from 'stream';
4+
import { Timezone } from 'sql-escaper';
45
import { TypeCast } from '../../parsers/typeCast.js';
56

67
export type QueryValues =
@@ -95,6 +96,35 @@ export interface QueryOptions {
9596
* By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
9697
*/
9798
infileStreamFactory?: (path: string) => Readable;
99+
100+
/**
101+
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
102+
* (Default: false)
103+
*/
104+
supportBigNumbers?: boolean;
105+
106+
/**
107+
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
108+
* always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
109+
* bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
110+
* represented with JavaScript Number objects (which happens when they exceed the [-2^53, +2^53] range),
111+
* otherwise they will be returned as Number objects.
112+
* This option is ignored if supportBigNumbers is disabled.
113+
*/
114+
bigNumberStrings?: boolean;
115+
116+
/**
117+
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date
118+
* objects. Can be true/false or an array of type names to keep as strings.
119+
*
120+
* (Default: false)
121+
*/
122+
dateStrings?: boolean | Array<'TIMESTAMP' | 'DATETIME' | 'DATE'>;
123+
124+
/**
125+
* The timezone used to store local dates. (Default: 'local')
126+
*/
127+
timezone?: Timezone;
98128
}
99129

100130
export interface StreamOptions {

typings/mysql/lib/protocol/sequences/promise/ExecutableBase.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ export declare function ExecutableBase<T extends QueryableConstructor>(
55
Base?: T
66
): {
77
new (...args: any[]): {
8-
execute<T extends QueryResult>(sql: string): Promise<[T, FieldPacket[]]>;
98
execute<T extends QueryResult>(
109
sql: string,
1110
values?: QueryValues
1211
): Promise<[T, FieldPacket[]]>;
13-
execute<T extends QueryResult>(
14-
options: QueryOptions
15-
): Promise<[T, FieldPacket[]]>;
1612
execute<T extends QueryResult>(
1713
options: QueryOptions,
1814
values?: QueryValues

0 commit comments

Comments
 (0)