-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.ts
42 lines (38 loc) · 1.06 KB
/
database.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
import { TranslationConfig } from 'typeorm-translatable';
import { DataSourceOptions, DataSource } from 'typeorm';
import { PostWithDecorators } from './post-with-decorators/post-with-decorators.entity';
import { PostTranslation } from './post/post-translation.entity';
import { Post } from './post/post.entity';
import { MyPost } from './post/my-post';
const {
DATABASE_HOST,
DATABASE_PORT,
DATABASE_USER,
DATABASE_PASSWORD,
DATABASE_NAME,
} = process.env;
const dataSourceOptions: DataSourceOptions = (() => {
const commonOptions: DataSourceOptions = {
type: 'mysql',
host: DATABASE_HOST,
port: parseInt(DATABASE_PORT || '3306'),
username: DATABASE_USER,
password: DATABASE_PASSWORD,
database: DATABASE_NAME,
synchronize: true,
entities: [
Post,
PostTranslation,
PostWithDecorators,
MyPost,
...TranslationConfig.generate(),
],
migrations: [],
subscribers: [],
};
return {
...commonOptions,
logging: true,
};
})();
export const appDataSource = new DataSource(dataSourceOptions);