diff --git a/src/config.ts b/src/config.ts index 0c2cea5..4f73fd1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -106,6 +106,7 @@ export function getConnectionOptions(): ConnectionOptions { connectTimeout: 60000, trace: false, supportBigNumbers: true, + jsonStrings: true, ...options, typeCast, namedPlaceholders: false, // we use our own named-placeholders patch, disable mysql2s diff --git a/src/database/connection.ts b/src/database/connection.ts index 92c8380..5233569 100644 --- a/src/database/connection.ts +++ b/src/database/connection.ts @@ -38,7 +38,7 @@ export class MySql { const [result] = await this.connection.execute({ sql: query, values: values, - typeCast: typeCastExecute as TypeCast, + typeCast: typeCastExecute, }); return result; } diff --git a/src/utils/typeCast.ts b/src/utils/typeCast.ts index 9ad8fa9..456ecfe 100644 --- a/src/utils/typeCast.ts +++ b/src/utils/typeCast.ts @@ -2,21 +2,17 @@ import type { TypeCastField, TypeCastNext } from 'mysql2/promise'; const BINARY_CHARSET = 63; -interface Field extends TypeCastField { - charset: number; -} - /** * node-mysql2 v3.9.0 introduced (breaking) typecasting for execute methods. */ -export function typeCastExecute(field: Field, next: TypeCastNext) { +export function typeCastExecute(field: TypeCastField, next: TypeCastNext) { return next(); } /** * mysql-async compatible typecasting. */ -export function typeCast(field: Field, next: TypeCastNext) { +export function typeCast(field: TypeCastField, next: TypeCastNext) { switch (field.type) { case 'DATETIME': case 'DATETIME2':