-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
MySqlConnection.ts
49 lines (36 loc) · 1.16 KB
/
MySqlConnection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { MySqlConnectionConfig } from 'knex';
import { AbstractSqlConnection } from './AbstractSqlConnection';
export class MySqlConnection extends AbstractSqlConnection {
async connect(): Promise<void> {
this.client = this.createKnexClient('mysql2');
}
getDefaultClientUrl(): string {
return 'mysql://root@127.0.0.1:3306';
}
getConnectionOptions(): MySqlConnectionConfig {
const ret: MySqlConnectionConfig = super.getConnectionOptions();
if (this.config.get('multipleStatements')) {
ret.multipleStatements = this.config.get('multipleStatements');
}
if (this.config.get('forceUtcTimezone')) {
ret.timezone = 'Z';
}
if (this.config.get('timezone')) {
ret.timezone = this.config.get('timezone');
}
ret.supportBigNumbers = true;
return ret;
}
protected transformRawResult<T>(res: any, method: 'all' | 'get' | 'run'): T {
if (method === 'run' && res[0].constructor.name === 'ResultSetHeader') {
return {
insertId: res[0].insertId,
affectedRows: res[0].affectedRows,
} as unknown as T;
}
if (method === 'get') {
return res[0][0];
}
return res[0];
}
}