Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
258 lines (238 loc) · 12.1 KB
/
Copy pathindex.ts
File metadata and controls
258 lines (238 loc) · 12.1 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*!
*/
import {ConnectionManager} from "./connection/ConnectionManager";
import {Connection} from "./connection/Connection";
import {MetadataArgsStorage} from "./metadata-args/MetadataArgsStorage";
import {ConnectionOptions} from "./connection/ConnectionOptions";
import {getFromContainer} from "./container";
import {ObjectType} from "./common/ObjectType";
import {Repository} from "./repository/Repository";
import {EntityManager} from "./entity-manager/EntityManager";
import {PlatformTools} from "./platform/PlatformTools";
import {TreeRepository} from "./repository/TreeRepository";
import {MongoRepository} from "./repository/MongoRepository";
import {ConnectionOptionsReader} from "./connection/ConnectionOptionsReader";
import {PromiseUtils} from "./util/PromiseUtils";
import {MongoEntityManager} from "./entity-manager/MongoEntityManager";
import {SqljsEntityManager} from "./entity-manager/SqljsEntityManager";
// -------------------------------------------------------------------------
// Commonly Used exports
// -------------------------------------------------------------------------
export * from "./container";
export * from "./common/ObjectType";
export * from "./common/ObjectLiteral";
export * from "./common/DeepPartial";
export * from "./error/QueryFailedError";
export * from "./decorator/columns/Column";
export * from "./decorator/columns/CreateDateColumn";
export * from "./decorator/columns/DiscriminatorColumn";
export * from "./decorator/columns/PrimaryGeneratedColumn";
export * from "./decorator/columns/PrimaryColumn";
export * from "./decorator/columns/UpdateDateColumn";
export * from "./decorator/columns/VersionColumn";
export * from "./decorator/columns/ObjectIdColumn";
export * from "./decorator/listeners/AfterInsert";
export * from "./decorator/listeners/AfterLoad";
export * from "./decorator/listeners/AfterRemove";
export * from "./decorator/listeners/AfterUpdate";
export * from "./decorator/listeners/BeforeInsert";
export * from "./decorator/listeners/BeforeRemove";
export * from "./decorator/listeners/BeforeUpdate";
export * from "./decorator/listeners/EventSubscriber";
export * from "./decorator/options/ColumnOptions";
export * from "./decorator/options/IndexOptions";
export * from "./decorator/options/JoinColumnOptions";
export * from "./decorator/options/JoinTableOptions";
export * from "./decorator/options/RelationOptions";
export * from "./decorator/options/EntityOptions";
export * from "./decorator/relations/RelationCount";
export * from "./decorator/relations/JoinColumn";
export * from "./decorator/relations/JoinTable";
export * from "./decorator/relations/ManyToMany";
export * from "./decorator/relations/ManyToOne";
export * from "./decorator/relations/OneToMany";
export * from "./decorator/relations/OneToOne";
export * from "./decorator/relations/RelationCount";
export * from "./decorator/relations/RelationId";
export * from "./decorator/entity/Entity";
export * from "./decorator/entity/ClassEntityChild";
export * from "./decorator/entity/ClosureEntity";
export * from "./decorator/entity/SingleEntityChild";
export * from "./decorator/entity/TableInheritance";
export * from "./decorator/transaction/Transaction";
export * from "./decorator/transaction/TransactionManager";
export * from "./decorator/transaction/TransactionRepository";
export * from "./decorator/tree/TreeLevelColumn";
export * from "./decorator/tree/TreeParent";
export * from "./decorator/tree/TreeChildren";
export * from "./decorator/Index";
export * from "./decorator/Generated";
export * from "./decorator/DiscriminatorValue";
export * from "./decorator/EntityRepository";
export * from "./find-options/FindOneOptions";
export * from "./find-options/FindManyOptions";
export * from "./logger/Logger";
export * from "./logger/AdvancedConsoleLogger";
export * from "./logger/SimpleConsoleLogger";
export * from "./logger/FileLogger";
export * from "./metadata/EntityMetadataUtils";
export * from "./entity-manager/EntityManager";
export * from "./repository/AbstractRepository";
export * from "./repository/Repository";
export * from "./repository/BaseEntity";
export * from "./repository/TreeRepository";
export * from "./repository/MongoRepository";
export * from "./repository/RemoveOptions";
export * from "./repository/SaveOptions";
export * from "./schema-builder/schema/TableColumn";
export * from "./schema-builder/schema/TableForeignKey";
export * from "./schema-builder/schema/TableIndex";
export * from "./schema-builder/schema/TablePrimaryKey";
export * from "./schema-builder/schema/Table";
export * from "./driver/mongodb/typings";
export * from "./driver/types/DatabaseType";
export * from "./driver/sqlserver/MssqlParameter";
export {ConnectionOptionsReader} from "./connection/ConnectionOptionsReader";
export {Connection} from "./connection/Connection";
export {ConnectionManager} from "./connection/ConnectionManager";
export {ConnectionOptions} from "./connection/ConnectionOptions";
export {Driver} from "./driver/Driver";
export {QueryBuilder} from "./query-builder/QueryBuilder";
export {SelectQueryBuilder} from "./query-builder/SelectQueryBuilder";
export {DeleteQueryBuilder} from "./query-builder/DeleteQueryBuilder";
export {InsertQueryBuilder} from "./query-builder/InsertQueryBuilder";
export {UpdateQueryBuilder} from "./query-builder/UpdateQueryBuilder";
export {RelationQueryBuilder} from "./query-builder/RelationQueryBuilder";
export {Brackets} from "./query-builder/Brackets";
export {WhereExpression} from "./query-builder/WhereExpression";
export {QueryRunner} from "./query-runner/QueryRunner";
export {EntityManager} from "./entity-manager/EntityManager";
export {MongoEntityManager} from "./entity-manager/MongoEntityManager";
export {MigrationInterface} from "./migration/MigrationInterface";
export {DefaultNamingStrategy} from "./naming-strategy/DefaultNamingStrategy";
export {NamingStrategyInterface} from "./naming-strategy/NamingStrategyInterface";
export {Repository} from "./repository/Repository";
export {TreeRepository} from "./repository/TreeRepository";
export {MongoRepository} from "./repository/MongoRepository";
export {FindOneOptions} from "./find-options/FindOneOptions";
export {FindManyOptions} from "./find-options/FindManyOptions";
export {InsertEvent} from "./subscriber/event/InsertEvent";
export {UpdateEvent} from "./subscriber/event/UpdateEvent";
export {RemoveEvent} from "./subscriber/event/RemoveEvent";
export {EntitySubscriberInterface} from "./subscriber/EntitySubscriberInterface";
export {BaseEntity} from "./repository/BaseEntity";
export {EntitySchema} from "./entity-schema/EntitySchema";
export {EntitySchemaTable} from "./entity-schema/EntitySchemaTable";
export {EntitySchemaColumn} from "./entity-schema/EntitySchemaColumn";
export {EntitySchemaIndex} from "./entity-schema/EntitySchemaIndex";
export {EntitySchemaRelation} from "./entity-schema/EntitySchemaRelation";
export {ColumnType} from "./driver/types/ColumnTypes";
export {PromiseUtils} from "./util/PromiseUtils";
// -------------------------------------------------------------------------
// Deprecated
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Commonly used functionality
// -------------------------------------------------------------------------
/**
* Gets metadata args storage.
*/
export function getMetadataArgsStorage(): MetadataArgsStorage {
// we should store metadata storage in a global variable otherwise it brings too much problems
// one of the problem is that if any entity (or any other) will be imported before consumer will call
// useContainer method with his own container implementation, that entity will be registered in the
// old old container (default one post probably) and consumer will his entity.
// calling useContainer before he imports any entity (or any other) is not always convenient.
// another reason is that when we run migrations typeorm is being called from a global package
// and it may load entities which register decorators in typeorm of local package
// this leads to impossibility of usage of entities in migrations and cli related operations
const globalScope = PlatformTools.getGlobalVariable();
if (!globalScope.typeormMetadataArgsStorage)
globalScope.typeormMetadataArgsStorage = new MetadataArgsStorage();
return globalScope.typeormMetadataArgsStorage;
}
/**
* Reads connection options stored in ormconfig configuration file.
*/
export async function getConnectionOptions(connectionName: string = "default"): Promise<ConnectionOptions> {
return new ConnectionOptionsReader().get(connectionName);
}
/**
* Gets a ConnectionManager which creates connections.
*/
export function getConnectionManager(): ConnectionManager {
return getFromContainer(ConnectionManager);
}
/**
* Creates a new connection and registers it in the manager.
*
* If connection options were not specified, then it will try to create connection automatically,
* based on content of ormconfig (json/js/yml/xml/env) file or environment variables.
* Only one connection from ormconfig will be created (name "default" or connection without name).
*/
export async function createConnection(options?: ConnectionOptions): Promise<Connection> {
if (!options)
options = await getConnectionOptions();
return getConnectionManager().create(options).connect();
}
/**
* Creates new connections and registers them in the manager.
*
* If connection options were not specified, then it will try to create connection automatically,
* based on content of ormconfig (json/js/yml/xml/env) file or environment variables.
* All connections from the ormconfig will be created.
*/
export async function createConnections(options?: ConnectionOptions[]): Promise<Connection[]> {
if (!options)
options = await new ConnectionOptionsReader().all();
const connections = options.map(options => getConnectionManager().create(options));
return PromiseUtils.runInSequence(connections, connection => connection.connect());
}
/**
* Gets connection from the connection manager.
* If connection name wasn't specified, then "default" connection will be retrieved.
*/
export function getConnection(connectionName: string = "default"): Connection {
return getConnectionManager().get(connectionName);
}
/**
* Gets entity manager from the connection.
* If connection name wasn't specified, then "default" connection will be retrieved.
*/
export function getManager(connectionName: string = "default"): EntityManager {
return getConnectionManager().get(connectionName).manager;
}
/**
* Gets MongoDB entity manager from the connection.
* If connection name wasn't specified, then "default" connection will be retrieved.
*/
export function getMongoManager(connectionName: string = "default"): MongoEntityManager {
return getConnectionManager().get(connectionName).manager as MongoEntityManager;
}
export function getSqljsManager(connectionName: string = "default"): SqljsEntityManager {
return getConnectionManager().get(connectionName).manager as SqljsEntityManager;
}
/**
* Gets repository for the given entity class.
*/
export function getRepository<Entity>(entityClass: ObjectType<Entity>|string, connectionName: string = "default"): Repository<Entity> {
return getConnectionManager().get(connectionName).getRepository<Entity>(entityClass);
}
/**
* Gets tree repository for the given entity class.
*/
export function getTreeRepository<Entity>(entityClass: ObjectType<Entity>|string, connectionName: string = "default"): TreeRepository<Entity> {
return getConnectionManager().get(connectionName).getTreeRepository<Entity>(entityClass);
}
/**
* Gets tree repository for the given entity class.
*/
export function getCustomRepository<T>(customRepository: ObjectType<T>, connectionName: string = "default"): T {
return getConnectionManager().get(connectionName).getCustomRepository(customRepository);
}
/**
* Gets mongodb repository for the given entity class or name.
*/
export function getMongoRepository<Entity>(entityClass: ObjectType<Entity>|string, connectionName: string = "default"): MongoRepository<Entity> {
return getConnectionManager().get(connectionName).getMongoRepository<Entity>(entityClass);
}