From b840d3dd6257fecb92d08f45335b215c43408015 Mon Sep 17 00:00:00 2001 From: joe-re Date: Sun, 19 Jul 2020 12:25:11 +0800 Subject: [PATCH] use mysql2 instead of mysql to support Mysql8 https://github.com/sidorares/node-mysql2/pull/1021 --- packages/server/package.json | 6 +++--- packages/server/src/ambient.d.ts | 1 + packages/server/src/database_libs/MysqlClient.ts | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index 465ccd03..ae90750a 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -24,15 +24,15 @@ "@types/pg": "^7.4.10", "jest": "^26.0.1", "log4js": "^6.2.1", - "mysql": "^2.15.0", + "mysql2": "^2.1.0", "node-ssh-forward": "^0.6.3", "pg": "^7.4.3", + "sqlint": "^0.9.2", "sqlite3": "^4.2.0", "vscode-languageclient": "^6.1.3", "vscode-languageserver": "^6.1.1", "vscode-languageserver-textdocument": "^1.0.1", - "yargs": "^12.0.1", - "sqlint": "^0.9.2" + "yargs": "^12.0.1" }, "devDependencies": { "@rollup/plugin-commonjs": "^11.1.0", diff --git a/packages/server/src/ambient.d.ts b/packages/server/src/ambient.d.ts index 2cb56338..dd1af31a 100644 --- a/packages/server/src/ambient.d.ts +++ b/packages/server/src/ambient.d.ts @@ -1 +1,2 @@ declare module 'yargs' +declare module 'mysql2' \ No newline at end of file diff --git a/packages/server/src/database_libs/MysqlClient.ts b/packages/server/src/database_libs/MysqlClient.ts index c4eb25e2..05e0a893 100644 --- a/packages/server/src/database_libs/MysqlClient.ts +++ b/packages/server/src/database_libs/MysqlClient.ts @@ -1,9 +1,10 @@ -import * as mysql from 'mysql' +import * as mysql from 'mysql2' +import * as mysqlType from 'mysql' import { Settings } from '../SettingStore' import AbstractClient, { RawField } from './AbstractClient' export default class MysqlClient extends AbstractClient { - connection: mysql.Connection | null = null + connection: mysqlType.Connection | null = null constructor(settings: Settings) { super(settings) @@ -47,7 +48,7 @@ export default class MysqlClient extends AbstractClient { reject(new Error(err.message)) return } - const tables = results.map((v: any) => v[`table_name`]) + const tables = results.map((v: any) => v['table_name'] || v['TABLE_NAME']) resolve(tables) }) })