-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
BaseConnectionOptions.ts
178 lines (147 loc) · 5.59 KB
/
BaseConnectionOptions.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import {EntitySchema} from "../entity-schema/EntitySchema";
import {LoggerOptions} from "../logger/LoggerOptions";
import {NamingStrategyInterface} from "../naming-strategy/NamingStrategyInterface";
import {DatabaseType} from "../driver/types/DatabaseType";
import {Logger} from "../logger/Logger";
import {Connection} from "./Connection";
import {QueryResultCache} from "../cache/QueryResultCache";
/**
* BaseConnectionOptions is set of connection options shared by all database types.
*/
export interface BaseConnectionOptions {
/**
* Database type. This value is required.
*/
readonly type: DatabaseType;
/**
* Connection name. If connection name is not given then it will be called "default".
* Different connections must have different names.
*/
readonly name?: string;
/**
* Entities to be loaded for this connection.
* Accepts both entity classes and directories where from entities need to be loaded.
* Directories support glob patterns.
*/
readonly entities?: ((Function|string|EntitySchema<any>))[];
/**
* Subscribers to be loaded for this connection.
* Accepts both subscriber classes and directories where from subscribers need to be loaded.
* Directories support glob patterns.
*/
readonly subscribers?: (Function|string)[];
/**
* Migrations to be loaded for this connection.
* Accepts both migration classes and directories where from migrations need to be loaded.
* Directories support glob patterns.
*/
readonly migrations?: (Function|string)[];
/**
* Migrations table name, in case of different name from "migrations".
* Accepts single string name.
*/
readonly migrationsTableName?: string;
/**
* Transaction mode for migrations to run in
*/
readonly migrationsTransactionMode?: "all" | "none" | "each";
/**
* Naming strategy to be used to name tables and columns in the database.
*/
readonly namingStrategy?: NamingStrategyInterface;
/**
* Logging options.
*/
readonly logging?: LoggerOptions;
/**
* Logger instance used to log queries and events in the ORM.
*/
readonly logger?: "advanced-console"|"simple-console"|"file"|"debug"|Logger;
/**
* Maximum number of milliseconds query should be executed before logger log a warning.
*/
readonly maxQueryExecutionTime?: number;
/**
* Indicates if database schema should be auto created on every application launch.
* Be careful with this option and don't use this in production - otherwise you can lose production data.
* This option is useful during debug and development.
* Alternative to it, you can use CLI and run schema:sync command.
*
* Note that for MongoDB database it does not create schema, because MongoDB is schemaless.
* Instead, it syncs just by creating indices.
*/
readonly synchronize?: boolean;
/**
* Indicates if migrations should be auto run on every application launch.
* Alternative to it, you can use CLI and run migrations:run command.
*/
readonly migrationsRun?: boolean;
/**
* Drops the schema each time connection is being established.
* Be careful with this option and don't use this in production - otherwise you'll lose all production data.
* This option is useful during debug and development.
*/
readonly dropSchema?: boolean;
/**
* Prefix to use on all tables (collections) of this connection in the database.
*/
readonly entityPrefix?: string;
/**
* Extra connection options to be passed to the underlying driver.
*
* todo: deprecate this and move all database-specific types into hts own connection options object.
*/
readonly extra?: any;
/**
* Allows to setup cache options.
*/
readonly cache?: boolean|{
/**
* Type of caching.
*
* - "database" means cached values will be stored in the separate table in database. This is default value.
* - "redis" means cached values will be stored inside redis. You must provide redis connection options.
*/
readonly type?: "database" | "redis" | "ioredis" | "ioredis/cluster"; // todo: add mongodb and other cache providers as well in the future
/**
* Factory function for custom cache providers that implement QueryResultCache.
*/
readonly provider?: (connection: Connection) => QueryResultCache;
/**
* Configurable table name for "database" type cache.
* Default value is "query-result-cache"
*/
readonly tableName?: string;
/**
* Used to provide redis connection options.
*/
readonly options?: any;
/**
* If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.
*/
readonly alwaysEnabled?: boolean;
/**
* Time in milliseconds in which cache will expire.
* This can be setup per-query.
* Default value is 1000 which is equivalent to 1 second.
*/
readonly duration?: number;
};
/**
* CLI settings.
*/
readonly cli?: {
/**
* Directory where entities should be created by default.
*/
readonly entitiesDir?: string;
/**
* Directory where migrations should be created by default.
*/
readonly migrationsDir?: string;
/**
* Directory where subscribers should be created by default.
*/
readonly subscribersDir?: string;
};
}