UNPKG

2.07 kBTypeScriptView Raw
1import { ModuleMetadata, Provider, Type } from '@nestjs/common';
2import { DataSource, DataSourceOptions } from 'typeorm';
3export type TypeOrmModuleOptions = {
4 /**
5 * Number of times to retry connecting
6 * Default: 10
7 */
8 retryAttempts?: number;
9 /**
10 * Delay between connection retry attempts (ms)
11 * Default: 3000
12 */
13 retryDelay?: number;
14 /**
15 * Function that determines whether the module should
16 * attempt to connect upon failure.
17 *
18 * @param err error that was thrown
19 * @returns whether to retry connection or not
20 */
21 toRetry?: (err: any) => boolean;
22 /**
23 * If `true`, entities will be loaded automatically.
24 */
25 autoLoadEntities?: boolean;
26 /**
27 * If `true`, connection will not be closed on application shutdown.
28 * @deprecated
29 */
30 keepConnectionAlive?: boolean;
31 /**
32 * If `true`, will show verbose error messages on each connection retry.
33 */
34 verboseRetryLog?: boolean;
35 /**
36 * If `true` database initialization will not be performed during module initialization.
37 * This means that database connection will not be established and migrations will not run.
38 * Database initialization will have to be performed manually using `DataSource.initialize`
39 * and it will have to implement own retry mechanism (if necessary).
40 */
41 manualInitialization?: boolean;
42} & Partial<DataSourceOptions>;
43export interface TypeOrmOptionsFactory {
44 createTypeOrmOptions(connectionName?: string): Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;
45}
46export type TypeOrmDataSourceFactory = (options?: DataSourceOptions) => Promise<DataSource>;
47export interface TypeOrmModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
48 name?: string;
49 useExisting?: Type<TypeOrmOptionsFactory>;
50 useClass?: Type<TypeOrmOptionsFactory>;
51 useFactory?: (...args: any[]) => Promise<TypeOrmModuleOptions> | TypeOrmModuleOptions;
52 dataSourceFactory?: TypeOrmDataSourceFactory;
53 inject?: any[];
54 extraProviders?: Provider[];
55}