Skip to content

Commit

Permalink
chore(utils/typeCast): use patched type
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Jun 17, 2024
1 parent 75b5e45 commit 9ee0f62
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/database/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/utils/typeCast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 9ee0f62

Please sign in to comment.