-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDatabaseModule.ts
62 lines (60 loc) · 2.79 KB
/
DatabaseModule.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
50
51
52
53
54
55
56
57
58
59
60
61
62
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import DatabaseConfig from '@/common/persistence/DatabaseConfig';
import { ConfigModule, ConfigService } from '@nestjs/config';
import DatabaseNamingStrategy from '@/common/persistence/DatabaseNamingStrategy';
import Android from '@/android/domains/Android';
import Cohort from '@/user/domains/Cohort';
import Definition from '@/vocabulary/domains/Definition';
import LeitnerSystems from '@/vocabulary/domains/LeitnerSystems';
import User from '@/user/domains/User';
import Vocabulary from '@/vocabulary/domains/Vocabulary';
import AndroidRepository from '@/android/repositories/AndroidRepository';
import CohortRepository from '@/user/repositories/CohortRepository';
import DefinitionRepository from '@/vocabulary/repositories/DefinitionRepository';
import LeitnerSystemsRepository from '@/vocabulary/repositories/LeitnerSystemsRepository';
import UserRepository from '@/user/repositories/UserRepository';
import VocabularyRepository from '@/vocabulary/repositories/VocabularyRepository';
@Module({
imports: [
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (): TypeOrmModuleOptions => {
// do we need it?
// https://typeorm.io/#/using-ormconfig/which-configuration-file-is-used-by-typeorm
// Which configuration file is used by Typeorm?
// From the environment variables. Typeorm will attempt to load the .env file using dotEnv if it exists.
// ...
const databaseConfig = new DatabaseConfig();
const { host, port, username, password, database, connection, logging } = databaseConfig;
return {
retryAttempts: 1,
type: connection,
host,
port,
username,
password,
database,
// do not use the environment variable TYPEORM_ENTITIES
// as it won't work with npm run start:prod
// as directory is ***/dist/***
entities: [Android, Cohort, Definition, LeitnerSystems, User, Vocabulary],
synchronize: false,
logging,
namingStrategy: new DatabaseNamingStrategy(),
} as TypeOrmModuleOptions;
},
inject: [ConfigService],
}),
TypeOrmModule.forFeature([
AndroidRepository,
CohortRepository,
DefinitionRepository,
LeitnerSystemsRepository,
UserRepository,
VocabularyRepository,
]),
],
exports: [TypeOrmModule],
})
export default class DatabaseModule {}