From 98623dd7fc82cfbe556fc4b92828d382b86625d8 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 23 Jun 2023 23:06:31 -0300 Subject: [PATCH 01/18] fix: `createPool` uri overload --- typings/mysql/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/mysql/index.d.ts b/typings/mysql/index.d.ts index 8654ec16db..b1d1b83d40 100644 --- a/typings/mysql/index.d.ts +++ b/typings/mysql/index.d.ts @@ -44,6 +44,7 @@ export interface Prepare extends BasePrepare {} export function createConnection(connectionUri: string): BaseConnection; export function createConnection(config: ConnectionOptions): BaseConnection; +export function createPool(connectionUri: string): BasePool; export function createPool(config: PoolOptions): BasePool; export function createPoolCluster(config?: PoolClusterOptions): PoolCluster; From 297d34d792582126e6c7ee0754d096b21ed6339b Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 23 Jun 2023 23:35:08 -0300 Subject: [PATCH 02/18] ci: add uri test for `createPool` --- test/tsc-build/mysql/baseConnection.ts | 2 ++ .../mysql/createPool/callbacks/createPool.ts | 12 ++++++++++++ test/tsc-build/promise/baseConnection.ts | 2 ++ test/tsc-build/promise/createPool/createPool.ts | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/tsc-build/mysql/createPool/callbacks/createPool.ts create mode 100644 test/tsc-build/promise/createPool/createPool.ts diff --git a/test/tsc-build/mysql/baseConnection.ts b/test/tsc-build/mysql/baseConnection.ts index d01156e4a0..09f0fcba08 100644 --- a/test/tsc-build/mysql/baseConnection.ts +++ b/test/tsc-build/mysql/baseConnection.ts @@ -7,6 +7,8 @@ export const access: mysql.ConnectionOptions = { database: '', }; +export const uriAccess = `mysql://${access.host}:${access.password}@${access.host}:${access.port}/${access.database}`; + /** The SQL for the query */ export const sql = 'SELECT * FROM `table`'; diff --git a/test/tsc-build/mysql/createPool/callbacks/createPool.ts b/test/tsc-build/mysql/createPool/callbacks/createPool.ts new file mode 100644 index 0000000000..c671358bb7 --- /dev/null +++ b/test/tsc-build/mysql/createPool/callbacks/createPool.ts @@ -0,0 +1,12 @@ +import { mysql } from '../../../index.js'; +import { uriAccess, access } from '../../baseConnection.js'; + +(() => { + let uriPool: mysql.Pool | null = null; + let pool: mysql.Pool | null = null; + + if (uriPool === null || pool === null) return; + + uriPool = mysql.createPool(uriAccess); + pool = mysql.createPool(access); +})(); diff --git a/test/tsc-build/promise/baseConnection.ts b/test/tsc-build/promise/baseConnection.ts index 15283fc57d..e9bcf9899f 100644 --- a/test/tsc-build/promise/baseConnection.ts +++ b/test/tsc-build/promise/baseConnection.ts @@ -7,6 +7,8 @@ export const access: mysql.ConnectionOptions = { database: '', }; +export const uriAccess = `mysql://${access.host}:${access.password}@${access.host}:${access.port}/${access.database}`; + /** The SQL for the query */ export const sql = 'SELECT * FROM `table`'; diff --git a/test/tsc-build/promise/createPool/createPool.ts b/test/tsc-build/promise/createPool/createPool.ts new file mode 100644 index 0000000000..83a930f0e1 --- /dev/null +++ b/test/tsc-build/promise/createPool/createPool.ts @@ -0,0 +1,12 @@ +import { mysqlp as mysql } from '../../index.js'; +import { uriAccess, access } from '../baseConnection.js'; + +(() => { + let uriPool: mysql.Pool | null = null; + let pool: mysql.Pool | null = null; + + if (uriPool === null || pool === null) return; + + uriPool = mysql.createPool(uriAccess); + pool = mysql.createPool(access); +})(); From 4ce2c70313ecbe2c4c5fd73f34b4ce7d32a9c83c Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 00:31:35 -0300 Subject: [PATCH 03/18] fix: missing constants in `promise.js` --- promise.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/promise.js b/promise.js index cde9c5035d..95b234e179 100644 --- a/promise.js +++ b/promise.js @@ -563,3 +563,13 @@ exports.raw = core.raw; exports.PromisePool = PromisePool; exports.PromiseConnection = PromiseConnection; exports.PromisePoolConnection = PromisePoolConnection; + +exports.__defineGetter__('Types', () => require('./lib/constants/types.js')); + +exports.__defineGetter__('Charsets', () => + require('./lib/constants/charsets.js') +); + +exports.__defineGetter__('CharsetToEncoding', () => + require('./lib/constants/charset_encodings.js') +); From 7f35cf5f6e69cc8aa3d2008bf5b0434c4d7ee5ac Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 00:49:17 -0300 Subject: [PATCH 04/18] fix: missing `parserCache` in `promise.js` --- promise.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/promise.js b/promise.js index 95b234e179..c4bb609038 100644 --- a/promise.js +++ b/promise.js @@ -2,6 +2,7 @@ const core = require('./index.js'); const EventEmitter = require('events').EventEmitter; +const parserCache = require('./lib/parsers/parser_cache.js'); function makeDoneCb(resolve, reject, localErr) { return function (err, rows, fields) { @@ -573,3 +574,11 @@ exports.__defineGetter__('Charsets', () => exports.__defineGetter__('CharsetToEncoding', () => require('./lib/constants/charset_encodings.js') ); + +exports.setMaxParserCache = function(max) { + parserCache.setMaxCache(max); +}; + +exports.clearParserCache = function() { + parserCache.clearCache(); +}; From 04601ddbd1430b37a7a7ab8d8d63ad27bd00bb54 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 01:55:32 -0300 Subject: [PATCH 05/18] fix: missing typings for `Types` constant --- typings/mysql/index.d.ts | 1 + typings/mysql/lib/constants/Types.d.ts | 38 ++++++++++++++++++++++++++ typings/mysql/lib/constants/index.d.ts | 3 ++ 3 files changed, 42 insertions(+) create mode 100644 typings/mysql/lib/constants/Types.d.ts create mode 100644 typings/mysql/lib/constants/index.d.ts diff --git a/typings/mysql/index.d.ts b/typings/mysql/index.d.ts index b1d1b83d40..f737d601c1 100644 --- a/typings/mysql/index.d.ts +++ b/typings/mysql/index.d.ts @@ -32,6 +32,7 @@ export { export * from './lib/protocol/packets/index.js'; export * from './lib/Auth.js'; +export * from './lib/constants/index.js'; // Expose class interfaces export interface Connection extends BaseConnection {} diff --git a/typings/mysql/lib/constants/Types.d.ts b/typings/mysql/lib/constants/Types.d.ts new file mode 100644 index 0000000000..ecbbcfa72c --- /dev/null +++ b/typings/mysql/lib/constants/Types.d.ts @@ -0,0 +1,38 @@ +/** + * Constant `Types`. + * + * Please note that `Types` can only be accessed from the `mysql` object and not imported directly. + */ +declare const Types: { + [key: number]: string; + DECIMAL: 0x00; + TINY: 0x01; + SHORT: 0x02; + LONG: 0x03; + FLOAT: 0x04; + DOUBLE: 0x05; + NULL: 0x06; + TIMESTAMP: 0x07; + LONGLONG: 0x08; + INT24: 0x09; + DATE: 0x0a; + TIME: 0x0b; + DATETIME: 0x0c; + YEAR: 0x0d; + NEWDATE: 0x0e; + VARCHAR: 0x0f; + BIT: 0x10; + JSON: 0xf5; + NEWDECIMAL: 0xf6; + ENUM: 0xf7; + SET: 0xf8; + TINY_BLOB: 0xf9; + MEDIUM_BLOB: 0xfa; + LONG_BLOB: 0xfb; + BLOB: 0xfc; + VAR_STRING: 0xfd; + STRING: 0xfe; + GEOMETRY: 0xff; +}; + +export { Types }; diff --git a/typings/mysql/lib/constants/index.d.ts b/typings/mysql/lib/constants/index.d.ts new file mode 100644 index 0000000000..63b8e5eac0 --- /dev/null +++ b/typings/mysql/lib/constants/index.d.ts @@ -0,0 +1,3 @@ +import { Types } from './Types.js'; + +export { Types }; From 04eeb6aef4abfd90916b35c68bf5564f91f9e0af Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 02:02:29 -0300 Subject: [PATCH 06/18] ci: add tests for `Types` constants --- test/tsc-build/mysql/constants/Types.ts | 7 +++++++ test/tsc-build/promise/constants/Types.ts | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 test/tsc-build/mysql/constants/Types.ts create mode 100644 test/tsc-build/promise/constants/Types.ts diff --git a/test/tsc-build/mysql/constants/Types.ts b/test/tsc-build/mysql/constants/Types.ts new file mode 100644 index 0000000000..30f231a796 --- /dev/null +++ b/test/tsc-build/mysql/constants/Types.ts @@ -0,0 +1,7 @@ +import { mysql } from '../../index.js'; + +const BLOB: number = mysql.Types.BLOB; +const DECIMAL: string = mysql.Types[0x00]; +const DOUBLE: string = mysql.Types[5]; + +console.log(BLOB, DECIMAL, DOUBLE); diff --git a/test/tsc-build/promise/constants/Types.ts b/test/tsc-build/promise/constants/Types.ts new file mode 100644 index 0000000000..565ed3883e --- /dev/null +++ b/test/tsc-build/promise/constants/Types.ts @@ -0,0 +1,7 @@ +import { mysqlp as mysql } from '../../index.js'; + +const BLOB: number = mysql.Types.BLOB; +const DECIMAL: string = mysql.Types[0x00]; +const DOUBLE: string = mysql.Types[5]; + +console.log(BLOB, DECIMAL, DOUBLE); From 86655ec6ad8ab8deae11a3c4919ae2ee553f4120 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:27:45 -0300 Subject: [PATCH 07/18] fix: missing keys for `Types` constant --- typings/mysql/lib/constants/Types.d.ts | 92 +++++++++++++++++--------- 1 file changed, 61 insertions(+), 31 deletions(-) diff --git a/typings/mysql/lib/constants/Types.d.ts b/typings/mysql/lib/constants/Types.d.ts index ecbbcfa72c..73f34f0f85 100644 --- a/typings/mysql/lib/constants/Types.d.ts +++ b/typings/mysql/lib/constants/Types.d.ts @@ -1,38 +1,68 @@ +interface Types { + 0x00: string; + 0x01: string; + 0x02: string; + 0x03: string; + 0x04: string; + 0x05: string; + 0x06: string; + 0x07: string; + 0x08: string; + 0x09: string; + 0x0a: string; + 0x0b: string; + 0x0c: string; + 0x0d: string; + 0x0e: string; + 0x0f: string; + 0x10: string; + 0xf5: string; + 0xf6: string; + 0xf7: string; + 0xf8: string; + 0xf9: string; + 0xfa: string; + 0xfb: string; + 0xfc: string; + 0xfd: string; + 0xfe: string; + 0xff: string; + + DECIMAL: number; + TINY: number; + SHORT: number; + LONG: number; + FLOAT: number; + DOUBLE: number; + NULL: number; + TIMESTAMP: number; + LONGLONG: number; + INT24: number; + DATE: number; + TIME: number; + DATETIME: number; + YEAR: number; + NEWDATE: number; + VARCHAR: number; + BIT: number; + JSON: number; + NEWDECIMAL: number; + ENUM: number; + SET: number; + TINY_BLOB: number; + MEDIUM_BLOB: number; + LONG_BLOB: number; + BLOB: number; + VAR_STRING: number; + STRING: number; + GEOMETRY: number; +} + /** * Constant `Types`. * * Please note that `Types` can only be accessed from the `mysql` object and not imported directly. */ -declare const Types: { - [key: number]: string; - DECIMAL: 0x00; - TINY: 0x01; - SHORT: 0x02; - LONG: 0x03; - FLOAT: 0x04; - DOUBLE: 0x05; - NULL: 0x06; - TIMESTAMP: 0x07; - LONGLONG: 0x08; - INT24: 0x09; - DATE: 0x0a; - TIME: 0x0b; - DATETIME: 0x0c; - YEAR: 0x0d; - NEWDATE: 0x0e; - VARCHAR: 0x0f; - BIT: 0x10; - JSON: 0xf5; - NEWDECIMAL: 0xf6; - ENUM: 0xf7; - SET: 0xf8; - TINY_BLOB: 0xf9; - MEDIUM_BLOB: 0xfa; - LONG_BLOB: 0xfb; - BLOB: 0xfc; - VAR_STRING: 0xfd; - STRING: 0xfe; - GEOMETRY: 0xff; -}; +declare const Types: Types; export { Types }; From 01f77a0db471682e7c4f523bde1189fc5d11d43d Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:31:48 -0300 Subject: [PATCH 08/18] fix: missing typings for `Charsets` constants --- typings/mysql/lib/constants/Charsets.ts | 326 ++++++++++++++++++++++++ typings/mysql/lib/constants/index.d.ts | 3 +- 2 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 typings/mysql/lib/constants/Charsets.ts diff --git a/typings/mysql/lib/constants/Charsets.ts b/typings/mysql/lib/constants/Charsets.ts new file mode 100644 index 0000000000..0b35769e9c --- /dev/null +++ b/typings/mysql/lib/constants/Charsets.ts @@ -0,0 +1,326 @@ +interface Charsets { + BIG5_CHINESE_CI: number; + LATIN2_CZECH_CS: number; + DEC8_SWEDISH_CI: number; + CP850_GENERAL_CI: number; + LATIN1_GERMAN1_CI: number; + HP8_ENGLISH_CI: number; + KOI8R_GENERAL_CI: number; + LATIN1_SWEDISH_CI: number; + LATIN2_GENERAL_CI: number; + SWE7_SWEDISH_CI: number; + ASCII_GENERAL_CI: number; + UJIS_JAPANESE_CI: number; + SJIS_JAPANESE_CI: number; + CP1251_BULGARIAN_CI: number; + LATIN1_DANISH_CI: number; + HEBREW_GENERAL_CI: number; + TIS620_THAI_CI: number; + EUCKR_KOREAN_CI: number; + LATIN7_ESTONIAN_CS: number; + LATIN2_HUNGARIAN_CI: number; + KOI8U_GENERAL_CI: number; + CP1251_UKRAINIAN_CI: number; + GB2312_CHINESE_CI: number; + GREEK_GENERAL_CI: number; + CP1250_GENERAL_CI: number; + LATIN2_CROATIAN_CI: number; + GBK_CHINESE_CI: number; + CP1257_LITHUANIAN_CI: number; + LATIN5_TURKISH_CI: number; + LATIN1_GERMAN2_CI: number; + ARMSCII8_GENERAL_CI: number; + UTF8_GENERAL_CI: number; + CP1250_CZECH_CS: number; + UCS2_GENERAL_CI: number; + CP866_GENERAL_CI: number; + KEYBCS2_GENERAL_CI: number; + MACCE_GENERAL_CI: number; + MACROMAN_GENERAL_CI: number; + CP852_GENERAL_CI: number; + LATIN7_GENERAL_CI: number; + LATIN7_GENERAL_CS: number; + MACCE_BIN: number; + CP1250_CROATIAN_CI: number; + UTF8MB4_GENERAL_CI: number; + UTF8MB4_BIN: number; + LATIN1_BIN: number; + LATIN1_GENERAL_CI: number; + LATIN1_GENERAL_CS: number; + CP1251_BIN: number; + CP1251_GENERAL_CI: number; + CP1251_GENERAL_CS: number; + MACROMAN_BIN: number; + UTF16_GENERAL_CI: number; + UTF16_BIN: number; + UTF16LE_GENERAL_CI: number; + CP1256_GENERAL_CI: number; + CP1257_BIN: number; + CP1257_GENERAL_CI: number; + UTF32_GENERAL_CI: number; + UTF32_BIN: number; + UTF16LE_BIN: number; + BINARY: number; + ARMSCII8_BIN: number; + ASCII_BIN: number; + CP1250_BIN: number; + CP1256_BIN: number; + CP866_BIN: number; + DEC8_BIN: number; + GREEK_BIN: number; + HEBREW_BIN: number; + HP8_BIN: number; + KEYBCS2_BIN: number; + KOI8R_BIN: number; + KOI8U_BIN: number; + UTF8_TOLOWER_CI: number; + LATIN2_BIN: number; + LATIN5_BIN: number; + LATIN7_BIN: number; + CP850_BIN: number; + CP852_BIN: number; + SWE7_BIN: number; + UTF8_BIN: number; + BIG5_BIN: number; + EUCKR_BIN: number; + GB2312_BIN: number; + GBK_BIN: number; + SJIS_BIN: number; + TIS620_BIN: number; + UCS2_BIN: number; + UJIS_BIN: number; + GEOSTD8_GENERAL_CI: number; + GEOSTD8_BIN: number; + LATIN1_SPANISH_CI: number; + CP932_JAPANESE_CI: number; + CP932_BIN: number; + EUCJPMS_JAPANESE_CI: number; + EUCJPMS_BIN: number; + CP1250_POLISH_CI: number; + UTF16_UNICODE_CI: number; + UTF16_ICELANDIC_CI: number; + UTF16_LATVIAN_CI: number; + UTF16_ROMANIAN_CI: number; + UTF16_SLOVENIAN_CI: number; + UTF16_POLISH_CI: number; + UTF16_ESTONIAN_CI: number; + UTF16_SPANISH_CI: number; + UTF16_SWEDISH_CI: number; + UTF16_TURKISH_CI: number; + UTF16_CZECH_CI: number; + UTF16_DANISH_CI: number; + UTF16_LITHUANIAN_CI: number; + UTF16_SLOVAK_CI: number; + UTF16_SPANISH2_CI: number; + UTF16_ROMAN_CI: number; + UTF16_PERSIAN_CI: number; + UTF16_ESPERANTO_CI: number; + UTF16_HUNGARIAN_CI: number; + UTF16_SINHALA_CI: number; + UTF16_GERMAN2_CI: number; + UTF16_CROATIAN_CI: number; + UTF16_UNICODE_520_CI: number; + UTF16_VIETNAMESE_CI: number; + UCS2_UNICODE_CI: number; + UCS2_ICELANDIC_CI: number; + UCS2_LATVIAN_CI: number; + UCS2_ROMANIAN_CI: number; + UCS2_SLOVENIAN_CI: number; + UCS2_POLISH_CI: number; + UCS2_ESTONIAN_CI: number; + UCS2_SPANISH_CI: number; + UCS2_SWEDISH_CI: number; + UCS2_TURKISH_CI: number; + UCS2_CZECH_CI: number; + UCS2_DANISH_CI: number; + UCS2_LITHUANIAN_CI: number; + UCS2_SLOVAK_CI: number; + UCS2_SPANISH2_CI: number; + UCS2_ROMAN_CI: number; + UCS2_PERSIAN_CI: number; + UCS2_ESPERANTO_CI: number; + UCS2_HUNGARIAN_CI: number; + UCS2_SINHALA_CI: number; + UCS2_GERMAN2_CI: number; + UCS2_CROATIAN_CI: number; + UCS2_UNICODE_520_CI: number; + UCS2_VIETNAMESE_CI: number; + UCS2_GENERAL_MYSQL500_CI: number; + UTF32_UNICODE_CI: number; + UTF32_ICELANDIC_CI: number; + UTF32_LATVIAN_CI: number; + UTF32_ROMANIAN_CI: number; + UTF32_SLOVENIAN_CI: number; + UTF32_POLISH_CI: number; + UTF32_ESTONIAN_CI: number; + UTF32_SPANISH_CI: number; + UTF32_SWEDISH_CI: number; + UTF32_TURKISH_CI: number; + UTF32_CZECH_CI: number; + UTF32_DANISH_CI: number; + UTF32_LITHUANIAN_CI: number; + UTF32_SLOVAK_CI: number; + UTF32_SPANISH2_CI: number; + UTF32_ROMAN_CI: number; + UTF32_PERSIAN_CI: number; + UTF32_ESPERANTO_CI: number; + UTF32_HUNGARIAN_CI: number; + UTF32_SINHALA_CI: number; + UTF32_GERMAN2_CI: number; + UTF32_CROATIAN_CI: number; + UTF32_UNICODE_520_CI: number; + UTF32_VIETNAMESE_CI: number; + UTF8_UNICODE_CI: number; + UTF8_ICELANDIC_CI: number; + UTF8_LATVIAN_CI: number; + UTF8_ROMANIAN_CI: number; + UTF8_SLOVENIAN_CI: number; + UTF8_POLISH_CI: number; + UTF8_ESTONIAN_CI: number; + UTF8_SPANISH_CI: number; + UTF8_SWEDISH_CI: number; + UTF8_TURKISH_CI: number; + UTF8_CZECH_CI: number; + UTF8_DANISH_CI: number; + UTF8_LITHUANIAN_CI: number; + UTF8_SLOVAK_CI: number; + UTF8_SPANISH2_CI: number; + UTF8_ROMAN_CI: number; + UTF8_PERSIAN_CI: number; + UTF8_ESPERANTO_CI: number; + UTF8_HUNGARIAN_CI: number; + UTF8_SINHALA_CI: number; + UTF8_GERMAN2_CI: number; + UTF8_CROATIAN_CI: number; + UTF8_UNICODE_520_CI: number; + UTF8_VIETNAMESE_CI: number; + UTF8_GENERAL_MYSQL500_CI: number; + UTF8MB4_UNICODE_CI: number; + UTF8MB4_ICELANDIC_CI: number; + UTF8MB4_LATVIAN_CI: number; + UTF8MB4_ROMANIAN_CI: number; + UTF8MB4_SLOVENIAN_CI: number; + UTF8MB4_POLISH_CI: number; + UTF8MB4_ESTONIAN_CI: number; + UTF8MB4_SPANISH_CI: number; + UTF8MB4_SWEDISH_CI: number; + UTF8MB4_TURKISH_CI: number; + UTF8MB4_CZECH_CI: number; + UTF8MB4_DANISH_CI: number; + UTF8MB4_LITHUANIAN_CI: number; + UTF8MB4_SLOVAK_CI: number; + UTF8MB4_SPANISH2_CI: number; + UTF8MB4_ROMAN_CI: number; + UTF8MB4_PERSIAN_CI: number; + UTF8MB4_ESPERANTO_CI: number; + UTF8MB4_HUNGARIAN_CI: number; + UTF8MB4_SINHALA_CI: number; + UTF8MB4_GERMAN2_CI: number; + UTF8MB4_CROATIAN_CI: number; + UTF8MB4_UNICODE_520_CI: number; + UTF8MB4_VIETNAMESE_CI: number; + GB18030_CHINESE_CI: number; + GB18030_BIN: number; + GB18030_UNICODE_520_CI: number; + /** @deprecated */ + UTF8_GENERAL50_CI: number; + UTF8MB4_0900_AI_CI: number; + UTF8MB4_DE_PB_0900_AI_CI: number; + UTF8MB4_IS_0900_AI_CI: number; + UTF8MB4_LV_0900_AI_CI: number; + UTF8MB4_RO_0900_AI_CI: number; + UTF8MB4_SL_0900_AI_CI: number; + UTF8MB4_PL_0900_AI_CI: number; + UTF8MB4_ET_0900_AI_CI: number; + UTF8MB4_ES_0900_AI_CI: number; + UTF8MB4_SV_0900_AI_CI: number; + UTF8MB4_TR_0900_AI_CI: number; + UTF8MB4_CS_0900_AI_CI: number; + UTF8MB4_DA_0900_AI_CI: number; + UTF8MB4_LT_0900_AI_CI: number; + UTF8MB4_SK_0900_AI_CI: number; + UTF8MB4_ES_TRAD_0900_AI_CI: number; + UTF8MB4_LA_0900_AI_CI: number; + UTF8MB4_EO_0900_AI_CI: number; + UTF8MB4_HU_0900_AI_CI: number; + UTF8MB4_HR_0900_AI_CI: number; + UTF8MB4_VI_0900_AI_CI: number; + UTF8MB4_0900_AS_CS: number; + UTF8MB4_DE_PB_0900_AS_CS: number; + UTF8MB4_IS_0900_AS_CS: number; + UTF8MB4_LV_0900_AS_CS: number; + UTF8MB4_RO_0900_AS_CS: number; + UTF8MB4_SL_0900_AS_CS: number; + UTF8MB4_PL_0900_AS_CS: number; + UTF8MB4_ET_0900_AS_CS: number; + UTF8MB4_ES_0900_AS_CS: number; + UTF8MB4_SV_0900_AS_CS: number; + UTF8MB4_TR_0900_AS_CS: number; + UTF8MB4_CS_0900_AS_CS: number; + UTF8MB4_DA_0900_AS_CS: number; + UTF8MB4_LT_0900_AS_CS: number; + UTF8MB4_SK_0900_AS_CS: number; + UTF8MB4_ES_TRAD_0900_AS_CS: number; + UTF8MB4_LA_0900_AS_CS: number; + UTF8MB4_EO_0900_AS_CS: number; + UTF8MB4_HU_0900_AS_CS: number; + UTF8MB4_HR_0900_AS_CS: number; + UTF8MB4_VI_0900_AS_CS: number; + UTF8MB4_JA_0900_AS_CS: number; + UTF8MB4_JA_0900_AS_CS_KS: number; + UTF8MB4_0900_AS_CI: number; + UTF8MB4_RU_0900_AI_CI: number; + UTF8MB4_RU_0900_AS_CS: number; + UTF8MB4_ZH_0900_AS_CS: number; + UTF8MB4_0900_BIN: number; + + BIG5: number; + DEC8: number; + CP850: number; + HP8: number; + KOI8R: number; + LATIN1: number; + LATIN2: number; + SWE7: number; + ASCII: number; + UJIS: number; + SJIS: number; + HEBREW: number; + TIS620: number; + EUCKR: number; + KOI8U: number; + GB2312: number; + GREEK: number; + CP1250: number; + GBK: number; + LATIN5: number; + ARMSCII8: number; + UTF8: number; + UCS2: number; + CP866: number; + KEYBCS2: number; + MACCE: number; + MACROMAN: number; + CP852: number; + LATIN7: number; + UTF8MB4: number; + CP1251: number; + UTF16: number; + UTF16LE: number; + CP1256: number; + CP1257: number; + UTF32: number; + CP932: number; + EUCJPMS: number; + GB18030: number; + GEOSTD8: number; +} + +/** + * Constant `Charsets`. + * + * Please note that `Charsets` can only be accessed from the `mysql` object and not imported directly. + */ +declare const Charsets: Charsets; + +export { Charsets }; diff --git a/typings/mysql/lib/constants/index.d.ts b/typings/mysql/lib/constants/index.d.ts index 63b8e5eac0..a7b69a73df 100644 --- a/typings/mysql/lib/constants/index.d.ts +++ b/typings/mysql/lib/constants/index.d.ts @@ -1,3 +1,4 @@ import { Types } from './Types.js'; +import { Charsets } from './Charsets.js'; -export { Types }; +export { Types, Charsets }; From 51c4196d50472eb18e440ea0291f2b571a3e7585 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:34:22 -0300 Subject: [PATCH 09/18] fix: rename file of typings `Charsets` constants --- typings/mysql/lib/constants/{Charsets.ts => Charsets.d.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename typings/mysql/lib/constants/{Charsets.ts => Charsets.d.ts} (100%) diff --git a/typings/mysql/lib/constants/Charsets.ts b/typings/mysql/lib/constants/Charsets.d.ts similarity index 100% rename from typings/mysql/lib/constants/Charsets.ts rename to typings/mysql/lib/constants/Charsets.d.ts From 3661c0f0468a85a8a7460a8d5d2a65d37b907757 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:37:48 -0300 Subject: [PATCH 10/18] ci: add tests for `Charsets` constants --- test/tsc-build/mysql/constants/Charsets.ts | 6 ++++++ test/tsc-build/promise/constants/Charsets.ts | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 test/tsc-build/mysql/constants/Charsets.ts create mode 100644 test/tsc-build/promise/constants/Charsets.ts diff --git a/test/tsc-build/mysql/constants/Charsets.ts b/test/tsc-build/mysql/constants/Charsets.ts new file mode 100644 index 0000000000..65dbe424b9 --- /dev/null +++ b/test/tsc-build/mysql/constants/Charsets.ts @@ -0,0 +1,6 @@ +import { mysql } from '../../index.js'; + +const BIG5_CHINESE_CI: number = mysql.Charsets.BIG5_CHINESE_CI; +const BIG5: number = mysql.Charsets.BIG5; + +console.log(BIG5_CHINESE_CI, BIG5); diff --git a/test/tsc-build/promise/constants/Charsets.ts b/test/tsc-build/promise/constants/Charsets.ts new file mode 100644 index 0000000000..1e5f1b668b --- /dev/null +++ b/test/tsc-build/promise/constants/Charsets.ts @@ -0,0 +1,6 @@ +import { mysqlp as mysql } from '../../index.js'; + +const BIG5_CHINESE_CI: number = mysql.Charsets.BIG5_CHINESE_CI; +const BIG5: number = mysql.Charsets.BIG5; + +console.log(BIG5_CHINESE_CI, BIG5); From 609229a973031615cb93b5678b5932cf3714480f Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:43:29 -0300 Subject: [PATCH 11/18] fix: missing typings for `CharsetToEncoding` constants --- typings/mysql/lib/constants/CharsetToEncoding.d.ts | 8 ++++++++ typings/mysql/lib/constants/index.d.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 typings/mysql/lib/constants/CharsetToEncoding.d.ts diff --git a/typings/mysql/lib/constants/CharsetToEncoding.d.ts b/typings/mysql/lib/constants/CharsetToEncoding.d.ts new file mode 100644 index 0000000000..aa28389cb9 --- /dev/null +++ b/typings/mysql/lib/constants/CharsetToEncoding.d.ts @@ -0,0 +1,8 @@ +/** + * Constant `CharsetToEncoding`. + * + * Please note that `CharsetToEncoding` can only be accessed from the `mysql` object and not imported directly. + */ +declare const CharsetToEncoding: string[]; + +export { CharsetToEncoding }; diff --git a/typings/mysql/lib/constants/index.d.ts b/typings/mysql/lib/constants/index.d.ts index a7b69a73df..d08ba2cb89 100644 --- a/typings/mysql/lib/constants/index.d.ts +++ b/typings/mysql/lib/constants/index.d.ts @@ -1,4 +1,5 @@ import { Types } from './Types.js'; import { Charsets } from './Charsets.js'; +import { CharsetToEncoding } from './CharsetToEncoding.js'; -export { Types, Charsets }; +export { Types, Charsets, CharsetToEncoding }; From 4327cc3bb712caf85a8d69f54ad31b5afb46ff1c Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:46:38 -0300 Subject: [PATCH 12/18] ci: add tests for `CharsetToEncoding` constants --- test/tsc-build/mysql/constants/CharsetToEncoding.ts | 6 ++++++ test/tsc-build/promise/constants/CharsetToEncoding.ts | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 test/tsc-build/mysql/constants/CharsetToEncoding.ts create mode 100644 test/tsc-build/promise/constants/CharsetToEncoding.ts diff --git a/test/tsc-build/mysql/constants/CharsetToEncoding.ts b/test/tsc-build/mysql/constants/CharsetToEncoding.ts new file mode 100644 index 0000000000..4b6a55f348 --- /dev/null +++ b/test/tsc-build/mysql/constants/CharsetToEncoding.ts @@ -0,0 +1,6 @@ +import { mysql } from '../../index.js'; + +const charsetToEncoding: string[] = mysql.CharsetToEncoding; +const utf8: string = charsetToEncoding[0]; + +console.log(utf8, charsetToEncoding); diff --git a/test/tsc-build/promise/constants/CharsetToEncoding.ts b/test/tsc-build/promise/constants/CharsetToEncoding.ts new file mode 100644 index 0000000000..852a046134 --- /dev/null +++ b/test/tsc-build/promise/constants/CharsetToEncoding.ts @@ -0,0 +1,6 @@ +import { mysqlp as mysql } from '../../index.js'; + +const charsetToEncoding: string[] = mysql.CharsetToEncoding; +const utf8: string = charsetToEncoding[0]; + +console.log(utf8, charsetToEncoding); From 891a523939120666e8d85db634262889657aff45 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:57:20 -0300 Subject: [PATCH 13/18] fix: missing typings for `parserCache` --- typings/mysql/index.d.ts | 1 + typings/mysql/lib/parsers/ParserCache.d.ts | 4 ++++ typings/mysql/lib/parsers/index.d.ts | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 typings/mysql/lib/parsers/ParserCache.d.ts create mode 100644 typings/mysql/lib/parsers/index.d.ts diff --git a/typings/mysql/index.d.ts b/typings/mysql/index.d.ts index f737d601c1..ee5835036c 100644 --- a/typings/mysql/index.d.ts +++ b/typings/mysql/index.d.ts @@ -33,6 +33,7 @@ export { export * from './lib/protocol/packets/index.js'; export * from './lib/Auth.js'; export * from './lib/constants/index.js'; +export * from './lib/parsers/index.js'; // Expose class interfaces export interface Connection extends BaseConnection {} diff --git a/typings/mysql/lib/parsers/ParserCache.d.ts b/typings/mysql/lib/parsers/ParserCache.d.ts new file mode 100644 index 0000000000..0f1e7fa219 --- /dev/null +++ b/typings/mysql/lib/parsers/ParserCache.d.ts @@ -0,0 +1,4 @@ +declare function setMaxParserCache(max: number): void; +declare function clearParserCache(): void; + +export { setMaxParserCache, clearParserCache }; diff --git a/typings/mysql/lib/parsers/index.d.ts b/typings/mysql/lib/parsers/index.d.ts new file mode 100644 index 0000000000..7f1d48e943 --- /dev/null +++ b/typings/mysql/lib/parsers/index.d.ts @@ -0,0 +1,3 @@ +import { setMaxParserCache, clearParserCache } from './ParserCache.js'; + +export { setMaxParserCache, clearParserCache }; From b2c5b49f75ce7b871613b728e40402da035049c9 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 04:02:22 -0300 Subject: [PATCH 14/18] ci: add tests for `parserCache` typings --- test/tsc-build/mysql/parsers/clearParserCache.ts | 3 +++ test/tsc-build/mysql/parsers/setMaxParserCache.ts | 6 ++++++ test/tsc-build/promise/parsers/clearParserCache.ts | 3 +++ test/tsc-build/promise/parsers/setMaxParserCache.ts | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 test/tsc-build/mysql/parsers/clearParserCache.ts create mode 100644 test/tsc-build/mysql/parsers/setMaxParserCache.ts create mode 100644 test/tsc-build/promise/parsers/clearParserCache.ts create mode 100644 test/tsc-build/promise/parsers/setMaxParserCache.ts diff --git a/test/tsc-build/mysql/parsers/clearParserCache.ts b/test/tsc-build/mysql/parsers/clearParserCache.ts new file mode 100644 index 0000000000..7b580a3487 --- /dev/null +++ b/test/tsc-build/mysql/parsers/clearParserCache.ts @@ -0,0 +1,3 @@ +import { mysql } from '../../index.js'; + +mysql.clearParserCache(); diff --git a/test/tsc-build/mysql/parsers/setMaxParserCache.ts b/test/tsc-build/mysql/parsers/setMaxParserCache.ts new file mode 100644 index 0000000000..8a8ffc6da6 --- /dev/null +++ b/test/tsc-build/mysql/parsers/setMaxParserCache.ts @@ -0,0 +1,6 @@ +import { mysql } from '../../index.js'; + +mysql.setMaxParserCache(1000); + +// @ts-expect-error: The `max` param is required +mysql.setMaxParserCache(); diff --git a/test/tsc-build/promise/parsers/clearParserCache.ts b/test/tsc-build/promise/parsers/clearParserCache.ts new file mode 100644 index 0000000000..7b0ed7cec3 --- /dev/null +++ b/test/tsc-build/promise/parsers/clearParserCache.ts @@ -0,0 +1,3 @@ +import { mysqlp as mysql } from '../../index.js'; + +mysql.clearParserCache(); diff --git a/test/tsc-build/promise/parsers/setMaxParserCache.ts b/test/tsc-build/promise/parsers/setMaxParserCache.ts new file mode 100644 index 0000000000..f6d75c8746 --- /dev/null +++ b/test/tsc-build/promise/parsers/setMaxParserCache.ts @@ -0,0 +1,6 @@ +import { mysqlp as mysql } from '../../index.js'; + +mysql.setMaxParserCache(1000); + +// @ts-expect-error: The `max` param is required +mysql.setMaxParserCache(); From 3902ca6534fd64a798c5b2dc29402fe396d4a67c Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 06:23:14 -0300 Subject: [PATCH 15/18] fix: `PoolCluster` typings --- typings/mysql/lib/PoolCluster.d.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/typings/mysql/lib/PoolCluster.d.ts b/typings/mysql/lib/PoolCluster.d.ts index db39b5a130..bf34111660 100644 --- a/typings/mysql/lib/PoolCluster.d.ts +++ b/typings/mysql/lib/PoolCluster.d.ts @@ -1,6 +1,13 @@ import { EventEmitter } from 'events'; import { PoolConnection } from './PoolConnection.js'; import { PoolOptions } from './Pool.js'; +import { ExecutableBase as ExecutableBaseClass } from './protocol/sequences/ExecutableBase.js'; +import { QueryableBase as QueryableBaseClass } from './protocol/sequences/QueryableBase.js'; + +// Expose class interfaces +declare class QueryableAndExecutableBase extends QueryableBaseClass( + ExecutableBaseClass(EventEmitter) +) {} export interface PoolClusterOptions { /** @@ -29,10 +36,20 @@ export interface PoolClusterOptions { defaultSelector?: string; } +export interface PoolNamespace extends QueryableAndExecutableBase { + getConnection( + callback: ( + err: NodeJS.ErrnoException | null, + connection: PoolConnection + ) => any + ): void; +} + declare class PoolCluster extends EventEmitter { config: PoolClusterOptions; add(config: PoolOptions): void; + add(group: string, connectionUri: string): void; add(group: string, config: PoolOptions): void; end(): void; @@ -59,7 +76,7 @@ declare class PoolCluster extends EventEmitter { ) => void ): void; - of(pattern: string, selector?: string): PoolCluster; + of(pattern: string, selector?: string): PoolNamespace; on(event: string, listener: (args: any[]) => void): this; on(event: 'remove', listener: (nodeId: number) => void): this; From 7f38496097fa6d9cfbced604fe0ddc392b1b1979 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 06:45:50 -0300 Subject: [PATCH 16/18] fix: create promise-based `PoolCluster` typings --- promise.d.ts | 27 +++++++++++++++++++++++++++ typings/mysql/index.d.ts | 2 ++ 2 files changed, 29 insertions(+) diff --git a/promise.d.ts b/promise.d.ts index 50435b0d83..f0c56b7e27 100644 --- a/promise.d.ts +++ b/promise.d.ts @@ -8,6 +8,7 @@ import { QueryOptions, ConnectionOptions, PoolOptions, + PoolClusterOptions, Pool as CorePool, } from './index.js'; import { ExecutableBase as ExecutableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/ExecutableBase.js'; @@ -95,6 +96,30 @@ export interface Pool extends Connection { pool: CorePool; } +export interface PoolNamespace extends QueryableAndExecutableBase { + getConnection(): Promise; +} + +export interface PoolCluster extends EventEmitter { + config: PoolClusterOptions; + + add(config: PoolOptions): void; + add(group: string, connectionUri: string): void; + add(group: string, config: PoolOptions): void; + + end(): Promise; + + getConnection(): Promise; + getConnection(group: string): Promise; + getConnection(group: string, selector: string): Promise; + + of(pattern: string, selector?: string): PoolNamespace; + + on(event: string, listener: (args: any[]) => void): this; + on(event: 'remove', listener: (nodeId: number) => void): this; + on(event: 'connection', listener: (connection: PoolConnection) => void): this; +} + export function createConnection(connectionUri: string): Promise; export function createConnection( config: ConnectionOptions @@ -102,3 +127,5 @@ export function createConnection( export function createPool(connectionUri: string): Pool; export function createPool(config: PoolOptions): Pool; + +export function createPoolCluster(config?: PoolClusterOptions): PoolCluster; diff --git a/typings/mysql/index.d.ts b/typings/mysql/index.d.ts index ee5835036c..b7fd83a90c 100644 --- a/typings/mysql/index.d.ts +++ b/typings/mysql/index.d.ts @@ -12,6 +12,7 @@ import { import { PoolCluster as BasePoolCluster, PoolClusterOptions, + PoolNamespace, } from './lib/PoolCluster.js'; import { PoolConnection as BasePoolConnection } from './lib/PoolConnection.js'; import { @@ -25,6 +26,7 @@ export { SslOptions, PoolOptions, PoolClusterOptions, + PoolNamespace, QueryOptions, QueryError, PrepareStatementInfo, From 4ac27e41ccec1f046c9d843f7fe2ea6ada948976 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 07:42:07 -0300 Subject: [PATCH 17/18] ci: add tests for `PoolCluster` callback typings --- test/tsc-build/mysql/createPoolCluster/add.ts | 14 ++++ .../mysql/createPoolCluster/getConnection.ts | 69 ++++++++++++++++++ .../createPoolCluster/of/getConnection.ts | 69 ++++++++++++++++++ .../mysql/createPoolCluster/of/of.ts | 73 +++++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 test/tsc-build/mysql/createPoolCluster/add.ts create mode 100644 test/tsc-build/mysql/createPoolCluster/getConnection.ts create mode 100644 test/tsc-build/mysql/createPoolCluster/of/getConnection.ts create mode 100644 test/tsc-build/mysql/createPoolCluster/of/of.ts diff --git a/test/tsc-build/mysql/createPoolCluster/add.ts b/test/tsc-build/mysql/createPoolCluster/add.ts new file mode 100644 index 0000000000..e5e72690bd --- /dev/null +++ b/test/tsc-build/mysql/createPoolCluster/add.ts @@ -0,0 +1,14 @@ +import { mysql } from '../../index.js'; +import { access, uriAccess } from '../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +// Overload: poolCluster.add(group, connectionUri); +poolCluster.add('cluster1', uriAccess); +// Overload: poolCluster.add(group, config); +poolCluster.add('cluster2', access); +// Overload: poolCluster.add(config); +poolCluster.add(access); + +// @ts-expect-error: The option to pass only `URI` doesn't exists +poolCluster.add(uriAccess); diff --git a/test/tsc-build/mysql/createPoolCluster/getConnection.ts b/test/tsc-build/mysql/createPoolCluster/getConnection.ts new file mode 100644 index 0000000000..bebc0efced --- /dev/null +++ b/test/tsc-build/mysql/createPoolCluster/getConnection.ts @@ -0,0 +1,69 @@ +import { mysql } from '../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +poolCluster.getConnection((err, conn) => { + /** Overload: execute(sql, () => {}}) */ + conn.execute(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(sql, values, () => {}}) */ + conn.execute(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) I */ + conn.execute({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) II */ + conn.execute({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, values, () => {}}) */ + conn.execute({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Checking `PoolConnection` */ + conn.release(); +}); + +/** query */ +poolCluster.getConnection('cluster1', (err, conn) => { + /** Overload: query(sql, () => {}}) */ + conn.query(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(sql, values, () => {}}) */ + conn.query(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) I */ + conn.query({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) II */ + conn.query({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, values, () => {}}) */ + conn.query({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Checking `PoolConnection` */ + conn.release(); +}); diff --git a/test/tsc-build/mysql/createPoolCluster/of/getConnection.ts b/test/tsc-build/mysql/createPoolCluster/of/getConnection.ts new file mode 100644 index 0000000000..1956008633 --- /dev/null +++ b/test/tsc-build/mysql/createPoolCluster/of/getConnection.ts @@ -0,0 +1,69 @@ +import { mysql } from '../../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +poolCluster.of('cluster1').getConnection((err, conn) => { + /** Overload: execute(sql, () => {}}) */ + conn.execute(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(sql, values, () => {}}) */ + conn.execute(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) I */ + conn.execute({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) II */ + conn.execute({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, values, () => {}}) */ + conn.execute({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Checking `PoolConnection` */ + conn.release(); +}); + +/** query */ +poolCluster.of('cluster2').getConnection((err, conn) => { + /** Overload: query(sql, () => {}}) */ + conn.query(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(sql, values, () => {}}) */ + conn.query(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) I */ + conn.query({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) II */ + conn.query({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, values, () => {}}) */ + conn.query({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Checking `PoolConnection` */ + conn.release(); +}); diff --git a/test/tsc-build/mysql/createPoolCluster/of/of.ts b/test/tsc-build/mysql/createPoolCluster/of/of.ts new file mode 100644 index 0000000000..6d1206e6bb --- /dev/null +++ b/test/tsc-build/mysql/createPoolCluster/of/of.ts @@ -0,0 +1,73 @@ +import { mysql } from '../../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +{ + const conn = poolCluster.of('cluster1'); + + /** Overload: execute(sql, () => {}}) */ + conn.execute(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(sql, values, () => {}}) */ + conn.execute(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) I */ + conn.execute({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, () => {}}) II */ + conn.execute({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: execute(QueryOptions, values, () => {}}) */ + conn.execute({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** @ts-expect-error: PoolNamespace can't be a `PoolConnection` */ + conn.release(); +} + +/** query */ +{ + const conn = poolCluster.of('cluster2'); + + /** Overload: query(sql, () => {}}) */ + conn.query(sql, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(sql, values, () => {}}) */ + conn.query(sqlPS, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) I */ + conn.query({ sql }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, () => {}}) II */ + conn.query({ sql: sqlPS, values }, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** Overload: query(QueryOptions, values, () => {}}) */ + conn.query({ sql: sqlPS }, values, (err, result, fields) => { + console.log(err, result, fields); + }); + + /** @ts-expect-error: PoolNamespace can't be a `PoolConnection` */ + conn.release(); +} From fbc8a7eebf0a171e3c86f67e9e4ab8f4d161ef38 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 24 Jun 2023 07:59:36 -0300 Subject: [PATCH 18/18] ci: add tests for `PoolCluster` promise-based typings --- .../promise/createPoolCluster/add.ts | 14 ++++ .../createPoolCluster/getConnection.ts | 83 +++++++++++++++++++ .../createPoolCluster/of/getConnection.ts | 83 +++++++++++++++++++ .../promise/createPoolCluster/of/of.ts | 83 +++++++++++++++++++ 4 files changed, 263 insertions(+) create mode 100644 test/tsc-build/promise/createPoolCluster/add.ts create mode 100644 test/tsc-build/promise/createPoolCluster/getConnection.ts create mode 100644 test/tsc-build/promise/createPoolCluster/of/getConnection.ts create mode 100644 test/tsc-build/promise/createPoolCluster/of/of.ts diff --git a/test/tsc-build/promise/createPoolCluster/add.ts b/test/tsc-build/promise/createPoolCluster/add.ts new file mode 100644 index 0000000000..fd60548749 --- /dev/null +++ b/test/tsc-build/promise/createPoolCluster/add.ts @@ -0,0 +1,14 @@ +import { mysqlp as mysql } from '../../index.js'; +import { access, uriAccess } from '../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +// Overload: poolCluster.add(group, connectionUri); +poolCluster.add('cluster1', uriAccess); +// Overload: poolCluster.add(group, config); +poolCluster.add('cluster2', access); +// Overload: poolCluster.add(config); +poolCluster.add(access); + +// @ts-expect-error: The option to pass only `URI` doesn't exists +poolCluster.add(uriAccess); diff --git a/test/tsc-build/promise/createPoolCluster/getConnection.ts b/test/tsc-build/promise/createPoolCluster/getConnection.ts new file mode 100644 index 0000000000..21d0397fb1 --- /dev/null +++ b/test/tsc-build/promise/createPoolCluster/getConnection.ts @@ -0,0 +1,83 @@ +import { mysqlp as mysql } from '../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +(async () => { + const conn = await poolCluster.getConnection(); + + { + /** Overload: execute(sql) */ + const [results, fields] = await conn.execute(sql); + console.log(results, fields); + } + + { + /** Overload: execute(sql, values) */ + const [results, fields] = await conn.execute(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) I */ + const [results, fields] = await conn.execute({ sql }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) II */ + const [results, fields] = await conn.execute({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions, values) */ + const [results, fields] = await conn.execute({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** Checking `PoolConnection` */ + conn.release(); +})(); + +/** query */ +(async () => { + const conn = await poolCluster.getConnection('cluster1'); + + { + /** Overload: query(sql) */ + const [results, fields] = await conn.query(sql); + console.log(results, fields); + } + + { + /** Overload: query(sql, values) */ + const [results, fields] = await conn.query(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) I */ + const [results, fields] = await conn.query({ sql }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) II */ + const [results, fields] = await conn.query({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions, values) */ + const [results, fields] = await conn.query({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** Checking `PoolConnection` */ + conn.release(); +})(); diff --git a/test/tsc-build/promise/createPoolCluster/of/getConnection.ts b/test/tsc-build/promise/createPoolCluster/of/getConnection.ts new file mode 100644 index 0000000000..5730a9f766 --- /dev/null +++ b/test/tsc-build/promise/createPoolCluster/of/getConnection.ts @@ -0,0 +1,83 @@ +import { mysqlp as mysql } from '../../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +(async () => { + const conn = await poolCluster.of('cluster1').getConnection(); + + { + /** Overload: execute(sql) */ + const [results, fields] = await conn.execute(sql); + console.log(results, fields); + } + + { + /** Overload: execute(sql, values) */ + const [results, fields] = await conn.execute(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) I */ + const [results, fields] = await conn.execute({ sql }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) II */ + const [results, fields] = await conn.execute({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions, values) */ + const [results, fields] = await conn.execute({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** Checking `PoolConnection` */ + conn.release(); +})(); + +/** query */ +(async () => { + const conn = await poolCluster.of('cluster2').getConnection(); + + { + /** Overload: query(sql) */ + const [results, fields] = await conn.query(sql); + console.log(results, fields); + } + + { + /** Overload: query(sql, values) */ + const [results, fields] = await conn.query(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) I */ + const [results, fields] = await conn.query({ sql }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) II */ + const [results, fields] = await conn.query({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions, values) */ + const [results, fields] = await conn.query({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** Checking `PoolConnection` */ + conn.release(); +})(); diff --git a/test/tsc-build/promise/createPoolCluster/of/of.ts b/test/tsc-build/promise/createPoolCluster/of/of.ts new file mode 100644 index 0000000000..78325ec9fe --- /dev/null +++ b/test/tsc-build/promise/createPoolCluster/of/of.ts @@ -0,0 +1,83 @@ +import { mysqlp as mysql } from '../../../index.js'; +import { access, uriAccess, sql, sqlPS, values } from '../../baseConnection.js'; + +const poolCluster = mysql.createPoolCluster(); + +poolCluster.add('cluster1', uriAccess); +poolCluster.add('cluster2', access); + +/** execute */ +(async () => { + const conn = poolCluster.of('cluster1'); + + { + /** Overload: execute(sql) */ + const [results, fields] = await conn.execute(sql); + console.log(results, fields); + } + + { + /** Overload: execute(sql, values) */ + const [results, fields] = await conn.execute(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) I */ + const [results, fields] = await conn.execute({ sql }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions) II */ + const [results, fields] = await conn.execute({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: execute(QueryOptions, values) */ + const [results, fields] = await conn.execute({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** @ts-expect-error: PoolNamespace can't be a `PoolConnection` */ + conn.release(); +})(); + +/** query */ +(async () => { + const conn = poolCluster.of('cluster2'); + + { + /** Overload: query(sql) */ + const [results, fields] = await conn.query(sql); + console.log(results, fields); + } + + { + /** Overload: query(sql, values) */ + const [results, fields] = await conn.query(sqlPS, values); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) I */ + const [results, fields] = await conn.query({ sql }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions) II */ + const [results, fields] = await conn.query({ sql: sqlPS, values }); + console.log(results, fields); + } + + { + /** Overload: query(QueryOptions, values) */ + const [results, fields] = await conn.query({ sql: sqlPS }, values); + console.log(results, fields); + } + + /** @ts-expect-error: PoolNamespace can't be a `PoolConnection` */ + conn.release(); +})();