-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathTypeORMService.ts
More file actions
68 lines (66 loc) · 2.52 KB
/
TypeORMService.ts
File metadata and controls
68 lines (66 loc) · 2.52 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { DataSource } from "typeorm";
import { CloudStorageConfigsModel } from "../model/cloudStorage/CloudStorageConfigs";
import { CloudStorageFilesModel } from "../model/cloudStorage/CloudStorageFiles";
import { CloudStorageUserFilesModel } from "../model/cloudStorage/CloudStorageUserFiles";
import { isDev, isTest, MySQL } from "../constants/Config";
import { RoomModel } from "../model/room/Room";
import { RoomPeriodicModel } from "../model/room/RoomPeriodic";
import { RoomPeriodicConfigModel } from "../model/room/RoomPeriodicConfig";
import { RoomPeriodicUserModel } from "../model/room/RoomPeriodicUser";
import { RoomRecordModel } from "../model/room/RoomRecord";
import { RoomUserModel } from "../model/room/RoomUser";
import { UserModel } from "../model/user/User";
import { UserQQModel } from "../model/user/QQ";
import { UserWeChatModel } from "../model/user/WeChat";
import { UserGithubModel } from "../model/user/Github";
import { loggerServer, parseError } from "../logger";
import { UserAppleModel } from "../model/user/Apple";
import { UserAgoraModel } from "../model/user/Agora";
import { UserGoogleModel } from "../model/user/Google";
import { UserPhoneModel } from "../model/user/Phone";
import { OAuthInfosModel } from "../model/oauth/oauth-infos";
import { OAuthSecretsModel } from "../model/oauth/oauth-secrets";
import { OAuthUsersModel } from "../model/oauth/oauth-users";
export const dataSource = new DataSource({
type: "mysql",
host: MySQL.host,
username: MySQL.user,
password: MySQL.password,
database: MySQL.db,
port: MySQL.port,
entities: [
UserModel,
UserQQModel,
UserWeChatModel,
UserGithubModel,
UserAppleModel,
UserAgoraModel,
UserGoogleModel,
UserPhoneModel,
RoomModel,
RoomUserModel,
RoomPeriodicConfigModel,
RoomPeriodicModel,
RoomPeriodicUserModel,
RoomRecordModel,
CloudStorageConfigsModel,
CloudStorageFilesModel,
CloudStorageUserFilesModel,
OAuthInfosModel,
OAuthSecretsModel,
OAuthUsersModel,
],
extra: {
connectionLimit: isTest ? 50 : 10,
},
timezone: "Z",
logging: !isTest && isDev ? "all" : false,
maxQueryExecutionTime: !isTest && isDev ? 1 : 1000,
charset: "utf8mb4_unicode_ci",
});
export const orm = (): Promise<DataSource> => {
return dataSource.initialize().catch(err => {
loggerServer.error("unable to connect to the database", parseError(err));
process.exit(1);
});
};