Skip to content

Commit efa21a2

Browse files
authored
Fix mysql build error (#45)
* use require for mysql2 to fix compile error * fix mysql build error
1 parent 118e90b commit efa21a2

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

packages/server/rollup.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ export default {
1616
typescript({ tsconfig: 'tsconfig.cli.json' }),
1717
json(),
1818
resolve({
19-
preferBuiltins: false
19+
preferBuiltins: false,
2020
}),
2121
replace({
2222
delimiters: ['', ''],
2323
values: {
2424
'require(\'readable-stream/transform\')': 'require(\'stream\').Transform',
2525
'require("readable-stream/transform")': 'require("stream").Transform',
26-
'readable-stream': 'stream'
26+
'readable-stream': 'stream',
27+
"require('./lib/pool.js')": 'class FakePool {}',
28+
"require('./lib/pool_connection')": 'class FakePoolConnection {}'
2729
}
2830
}),
2931
commonjs({
30-
ignore: ['pg-native' , './native']
32+
ignore: ['pg-native' , './native', './lib/pool_cluster.js', './pool.js', './lib/pool.js', './lib/pool_connection', './lib/pool_connection.js', './pool_connection.js']
3133
})
3234
]
3335
};

packages/server/src/ambient.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
declare module 'yargs'
2-
declare module 'mysql2'
2+
declare module 'mysql2/promise'

packages/server/src/database_libs/AbstractClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default abstract class AbstractClient {
2727

2828
constructor(protected settings: Settings) {}
2929

30-
abstract connect(): boolean
30+
abstract connect(): Promise<boolean> | boolean
3131
abstract disconnect(): void
3232
abstract getTables(): Promise<string[]>
3333
abstract getColumns(tableName: string): Promise<RawField[]>
@@ -57,7 +57,7 @@ export default abstract class AbstractClient {
5757
return []
5858
})
5959
}
60-
if (!this.connect()) {
60+
if (!(await this.connect())) {
6161
logger.error('AbstractClinet.getSchema: failed to connect database')
6262
return []
6363
}

packages/server/src/database_libs/MysqlClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as mysql from 'mysql2'
1+
import * as mysql from 'mysql2/promise'
22
import * as mysqlType from 'mysql'
33
import { Settings } from '../SettingStore'
44
import AbstractClient, { RawField } from './AbstractClient'
@@ -14,8 +14,8 @@ export default class MysqlClient extends AbstractClient {
1414
get DefaultHost() { return '127.0.0.1' }
1515
get DefaultUser() { return 'root' }
1616

17-
connect() {
18-
this.connection = mysql.createConnection({
17+
async connect() {
18+
this.connection = await mysql.createConnection({
1919
host: this.settings.host || this.DefaultHost,
2020
password: this.settings.password || '',
2121
user: this.settings.user || this.DefaultUser,

0 commit comments

Comments
 (0)