This repository has been archived by the owner on Aug 22, 2020. It is now read-only.
forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.ts
224 lines (204 loc) · 12.5 KB
/
index.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
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
/*!
*/
import {ConnectionManager} from "./src/connection/ConnectionManager";
import {Connection} from "./src/connection/Connection";
import {ConnectionOptions} from "./src/connection/ConnectionOptions";
import {defaultContainer, getFromContainer} from "./src/container";
import {ObjectType} from "./src/common/ObjectType";
import {MetadataArgsStorage} from "./src/metadata-args/MetadataArgsStorage";
export {defaultContainer, getFromContainer, useContainer, UseContainerOptions} from "./src/container";
export {Connection} from "./src/connection/Connection";
export {ConnectionManager} from "./src/connection/ConnectionManager";
export {ConnectionOptions} from "./src/connection/ConnectionOptions";
export {Column} from "./src/decorator/columns/Column";
export {CreateDateColumn} from "./src/decorator/columns/CreateDateColumn";
export {DiscriminatorColumn} from "./src/decorator/columns/DiscriminatorColumn";
export {PrimaryGeneratedColumn} from "./src/decorator/columns/PrimaryGeneratedColumn";
export {PrimaryColumn} from "./src/decorator/columns/PrimaryColumn";
export {UpdateDateColumn} from "./src/decorator/columns/UpdateDateColumn";
export {VersionColumn} from "./src/decorator/columns/VersionColumn";
export {AfterInsert} from "./src/decorator/listeners/AfterInsert";
export {AfterLoad} from "./src/decorator/listeners/AfterLoad";
export {AfterRemove} from "./src/decorator/listeners/AfterRemove";
export {AfterUpdate} from "./src/decorator/listeners/AfterUpdate";
export {BeforeInsert} from "./src/decorator/listeners/BeforeInsert";
export {BeforeRemove} from "./src/decorator/listeners/BeforeRemove";
export {BeforeUpdate} from "./src/decorator/listeners/BeforeUpdate";
export {EventSubscriber} from "./src/decorator/listeners/EventSubscriber";
export {ColumnOptions} from "./src/decorator/options/ColumnOptions";
export {IndexOptions} from "./src/decorator/options/IndexOptions";
export {JoinColumnOptions} from "./src/decorator/options/JoinColumnOptions";
export {JoinTableOptions} from "./src/decorator/options/JoinTableOptions";
export {RelationOptions} from "./src/decorator/options/RelationOptions";
export {TableOptions} from "./src/decorator/options/TableOptions";
export {JoinColumn} from "./src/decorator/relations/JoinColumn";
export {JoinTable} from "./src/decorator/relations/JoinTable";
export {ManyToMany} from "./src/decorator/relations/ManyToMany";
export {ManyToOne} from "./src/decorator/relations/ManyToOne";
export {OneToMany} from "./src/decorator/relations/OneToMany";
export {OneToOne} from "./src/decorator/relations/OneToOne";
export {RelationCount} from "./src/decorator/relations/RelationCount";
export {RelationId} from "./src/decorator/relations/RelationId";
export {Table} from "./src/decorator/tables/Table";
export {AbstractTable} from "./src/decorator/tables/AbstractTable";
export {ClassTableChild} from "./src/decorator/tables/ClassTableChild";
export {ClosureTable} from "./src/decorator/tables/ClosureTable";
export {EmbeddableTable} from "./src/decorator/tables/EmbeddableTable";
export {SingleTableChild} from "./src/decorator/tables/SingleTableChild";
export {TreeLevelColumn} from "./src/decorator/tree/TreeLevelColumn";
export {TreeParent} from "./src/decorator/tree/TreeParent";
export {Index} from "./src/decorator/Index";
export {NamingStrategy} from "./src/decorator/NamingStrategy";
export {TableInheritance} from "./src/decorator/tables/TableInheritance";
export {Embedded} from "./src/decorator/Embedded";
export {DiscriminatorValue} from "./src/decorator/DiscriminatorValue";
// -------------------------------------------------------------------------
// Commonly used functionality
// -------------------------------------------------------------------------
/**
* Gets metadata args storage.
*/
export function getMetadataArgsStorage(): MetadataArgsStorage {
// we should not get MetadataArgsStorage from the consumer's container because it brings too much problems
// the main 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.
return defaultContainer.get(MetadataArgsStorage);
}
/**
* 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.
*
* First, it will try to find a "default" configuration from ormconfig.json.
* You can also specify a connection name to use from ormconfig.json,
* and you even can specify a path to your custom ormconfig.json.
*
* In the case if options were not specified, and ormconfig.json file also wasn't found,
* it will try to create connection from environment variables.
* There are several environment variables you can set:
*
* - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "mysql2", "postgres", "mariadb", "websql", "oracle" or "mssql".
* - TYPEORM_URL - database connection url. Should be a string.
* - TYPEORM_HOST - database host. Should be a string.
* - TYPEORM_PORT - database access port. Should be a number.
* - TYPEORM_USERNAME - database username. Should be a string.
* - TYPEORM_PASSWORD - database user's password. Should be a string.
* - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string.
* - TYPEORM_STORAGE - database's storage url. Used only for websql databases. Should be a string.
* - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value.
* - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options.
* - TYPEORM_AUTO_SCHEMA_SYNC - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value.
* - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value.
* - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value.
* - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value.
*
* TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too.
*/
// export function createConnection(): Promise<Connection>;
/**
* Creates connection from the given connection options and registers it in the manager.
*/
export function createConnection(options: ConnectionOptions): Promise<Connection> {
return getConnectionManager().createAndConnect(options);
};
/**
* Creates connection with the given connection name from the ormconfig.json file and registers it in the manager.
* Optionally you can specify a path to custom ormconfig.json file.
*/
// export function createConnection(connectionNameFromConfig: string, ormConfigPath?: string): Promise<Connection>;
/**
* Creates connection and and registers it in the manager.
*/
/*export function createConnection(optionsOrConnectionNameFromConfig?: ConnectionOptions|string, ormConfigPath?: string): Promise<Connection> {
return getConnectionManager().createAndConnect(optionsOrConnectionNameFromConfig as any, ormConfigPath);
}*/
/**
* Creates new connections and registers them in the manager.
*
* If array of connection options were not specified, then it will try to create them automatically
* from ormconfig.json. You can also specify path to your custom ormconfig.json.
*
* In the case if options were not specified, and ormconfig.json file also wasn't found,
* it will try to create connection from environment variables.
* There are several environment variables you can set:
*
* - TYPEORM_DRIVER_TYPE - driver type. Can be "mysql", "mysql2", "postgres", "mariadb", "websql", "oracle" or "mssql".
* - TYPEORM_URL - database connection url. Should be a string.
* - TYPEORM_HOST - database host. Should be a string.
* - TYPEORM_PORT - database access port. Should be a number.
* - TYPEORM_USERNAME - database username. Should be a string.
* - TYPEORM_PASSWORD - database user's password. Should be a string.
* - TYPEORM_SID - database's SID. Used only for oracle databases. Should be a string.
* - TYPEORM_STORAGE - database's storage url. Used only for websql databases. Should be a string.
* - TYPEORM_USE_POOL - indicates if connection pooling should be enabled. By default its enabled. Should be boolean-like value.
* - TYPEORM_DRIVER_EXTRA - extra options to be passed to the driver. Should be a serialized json string of options.
* - TYPEORM_AUTO_SCHEMA_SYNC - indicates if automatic schema synchronization will be performed on each application run. Should be boolean-like value.
* - TYPEORM_ENTITIES - list of directories containing entities to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_SUBSCRIBERS - list of directories containing subscribers to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_ENTITY_SCHEMAS - list of directories containing entity schemas to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_NAMING_STRATEGIES - list of directories containing custom naming strategies to load. Should be string - directory names (can be patterns) split by a comma.
* - TYPEORM_LOGGING_QUERIES - indicates if each executed query must be logged. Should be boolean-like value.
* - TYPEORM_LOGGING_FAILED_QUERIES - indicates if logger should log failed query's error. Should be boolean-like value.
* - TYPEORM_LOGGING_ONLY_FAILED_QUERIES - indicates if only failed queries must be logged. Should be boolean-like value.
*
* TYPEORM_DRIVER_TYPE variable is required. Depend on the driver type some other variables may be required too.
*/
export function createConnections(): Promise<Connection[]>;
/**
* Creates connections from the given connection options and registers them in the manager.
*/
export function createConnections(options?: ConnectionOptions[]): Promise<Connection[]>;
/**
* Creates connection with the given connection name from the ormconfig.json file and registers it in the manager.
* Optionally you can specify a path to custom ormconfig.json file.
*/
export function createConnections(ormConfigPath?: string): Promise<Connection[]>;
/**
* Creates connections and and registers them in the manager.
*/
export function createConnections(optionsOrOrmConfigFilePath?: ConnectionOptions[]|string): Promise<Connection[]> {
return getConnectionManager().createAndConnectToAll(optionsOrOrmConfigFilePath as any);
}
/**
* 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 getEntityManager(connectionName: string = "default"): EntityManager {
return getConnectionManager().get(connectionName).entityManager;
}
*/
/**
* Gets repository for the given entity class.
*/
// export function getRepository<Entity>(entityClass: ObjectType<Entity>, connectionName: string): Repository<Entity>;
/**
* Gets repository for the given entity name.
*/
// export function getRepository<Entity>(entityName: string, connectionName: string): Repository<Entity>;
/**
* Gets repository for the given entity class or name.
*/
/*
export function getRepository<Entity>(entityClassOrName: ObjectType<Entity>|string, connectionName: string = "default"): Repository<Entity> {
return getConnectionManager().get(connectionName).getRepository<Entity>(entityClassOrName as any);
}*/