UNPKG

12.8 kBJavaScriptView Raw
1import * as tslib_1 from "tslib";
2/*!
3 */
4import "reflect-metadata";
5import { ConnectionManager } from "./connection/ConnectionManager";
6import { MetadataArgsStorage } from "./metadata-args/MetadataArgsStorage";
7import { getFromContainer } from "./container";
8import { PlatformTools } from "./platform/PlatformTools";
9import { ConnectionOptionsReader } from "./connection/ConnectionOptionsReader";
10import { PromiseUtils } from "./util/PromiseUtils";
11// -------------------------------------------------------------------------
12// Commonly Used exports
13// -------------------------------------------------------------------------
14export * from "./container";
15export * from "./error/QueryFailedError";
16export * from "./decorator/columns/Column";
17export * from "./decorator/columns/CreateDateColumn";
18export * from "./decorator/columns/PrimaryGeneratedColumn";
19export * from "./decorator/columns/PrimaryColumn";
20export * from "./decorator/columns/UpdateDateColumn";
21export * from "./decorator/columns/VersionColumn";
22export * from "./decorator/columns/ViewColumn";
23export * from "./decorator/columns/ObjectIdColumn";
24export * from "./decorator/listeners/AfterInsert";
25export * from "./decorator/listeners/AfterLoad";
26export * from "./decorator/listeners/AfterRemove";
27export * from "./decorator/listeners/AfterUpdate";
28export * from "./decorator/listeners/BeforeInsert";
29export * from "./decorator/listeners/BeforeRemove";
30export * from "./decorator/listeners/BeforeUpdate";
31export * from "./decorator/listeners/EventSubscriber";
32export * from "./decorator/relations/JoinColumn";
33export * from "./decorator/relations/JoinTable";
34export * from "./decorator/relations/ManyToMany";
35export * from "./decorator/relations/ManyToOne";
36export * from "./decorator/relations/OneToMany";
37export * from "./decorator/relations/OneToOne";
38export * from "./decorator/relations/RelationCount";
39export * from "./decorator/relations/RelationId";
40export * from "./decorator/entity/Entity";
41export * from "./decorator/entity/ChildEntity";
42export * from "./decorator/entity/TableInheritance";
43export * from "./decorator/entity-view/ViewEntity";
44export * from "./decorator/transaction/Transaction";
45export * from "./decorator/transaction/TransactionManager";
46export * from "./decorator/transaction/TransactionRepository";
47export * from "./decorator/tree/TreeLevelColumn";
48export * from "./decorator/tree/TreeParent";
49export * from "./decorator/tree/TreeChildren";
50export * from "./decorator/tree/Tree";
51export * from "./decorator/Index";
52export * from "./decorator/Unique";
53export * from "./decorator/Check";
54export * from "./decorator/Exclusion";
55export * from "./decorator/Generated";
56export * from "./decorator/EntityRepository";
57export * from "./find-options/operator/Any";
58export * from "./find-options/operator/Between";
59export * from "./find-options/operator/Equal";
60export * from "./find-options/operator/In";
61export * from "./find-options/operator/IsNull";
62export * from "./find-options/operator/LessThan";
63export * from "./find-options/operator/LessThanOrEqual";
64export * from "./find-options/operator/Like";
65export * from "./find-options/operator/MoreThan";
66export * from "./find-options/operator/MoreThanOrEqual";
67export * from "./find-options/operator/Not";
68export * from "./find-options/operator/Raw";
69export * from "./find-options/FindOperator";
70export * from "./logger/AdvancedConsoleLogger";
71export * from "./logger/SimpleConsoleLogger";
72export * from "./logger/FileLogger";
73export * from "./metadata/EntityMetadata";
74export * from "./entity-manager/EntityManager";
75export * from "./repository/AbstractRepository";
76export * from "./repository/Repository";
77export * from "./repository/BaseEntity";
78export * from "./repository/TreeRepository";
79export * from "./repository/MongoRepository";
80export * from "./schema-builder/table/TableColumn";
81export * from "./schema-builder/table/TableForeignKey";
82export * from "./schema-builder/table/TableIndex";
83export * from "./schema-builder/table/Table";
84export * from "./driver/mongodb/typings";
85export * from "./driver/sqlserver/MssqlParameter";
86export { ConnectionOptionsReader } from "./connection/ConnectionOptionsReader";
87export { Connection } from "./connection/Connection";
88export { ConnectionManager } from "./connection/ConnectionManager";
89export { QueryBuilder } from "./query-builder/QueryBuilder";
90export { SelectQueryBuilder } from "./query-builder/SelectQueryBuilder";
91export { DeleteQueryBuilder } from "./query-builder/DeleteQueryBuilder";
92export { InsertQueryBuilder } from "./query-builder/InsertQueryBuilder";
93export { UpdateQueryBuilder } from "./query-builder/UpdateQueryBuilder";
94export { RelationQueryBuilder } from "./query-builder/RelationQueryBuilder";
95export { Brackets } from "./query-builder/Brackets";
96export { InsertResult } from "./query-builder/result/InsertResult";
97export { UpdateResult } from "./query-builder/result/UpdateResult";
98export { DeleteResult } from "./query-builder/result/DeleteResult";
99export { EntityManager } from "./entity-manager/EntityManager";
100export { MongoEntityManager } from "./entity-manager/MongoEntityManager";
101export { DefaultNamingStrategy } from "./naming-strategy/DefaultNamingStrategy";
102export { Repository } from "./repository/Repository";
103export { TreeRepository } from "./repository/TreeRepository";
104export { MongoRepository } from "./repository/MongoRepository";
105export { BaseEntity } from "./repository/BaseEntity";
106export { EntitySchema } from "./entity-schema/EntitySchema";
107export { PromiseUtils } from "./util/PromiseUtils";
108// -------------------------------------------------------------------------
109// Deprecated
110// -------------------------------------------------------------------------
111// -------------------------------------------------------------------------
112// Commonly used functionality
113// -------------------------------------------------------------------------
114/**
115 * Gets metadata args storage.
116 */
117export function getMetadataArgsStorage() {
118 // we should store metadata storage in a global variable otherwise it brings too much problems
119 // one of the problem is that if any entity (or any other) will be imported before consumer will call
120 // useContainer method with his own container implementation, that entity will be registered in the
121 // old old container (default one post probably) and consumer will his entity.
122 // calling useContainer before he imports any entity (or any other) is not always convenient.
123 // another reason is that when we run migrations typeorm is being called from a global package
124 // and it may load entities which register decorators in typeorm of local package
125 // this leads to impossibility of usage of entities in migrations and cli related operations
126 var globalScope = PlatformTools.getGlobalVariable();
127 if (!globalScope.typeormMetadataArgsStorage)
128 globalScope.typeormMetadataArgsStorage = new MetadataArgsStorage();
129 return globalScope.typeormMetadataArgsStorage;
130}
131/**
132 * Reads connection options stored in ormconfig configuration file.
133 */
134export function getConnectionOptions(connectionName) {
135 if (connectionName === void 0) { connectionName = "default"; }
136 return tslib_1.__awaiter(this, void 0, void 0, function () {
137 return tslib_1.__generator(this, function (_a) {
138 return [2 /*return*/, new ConnectionOptionsReader().get(connectionName)];
139 });
140 });
141}
142/**
143 * Gets a ConnectionManager which creates connections.
144 */
145export function getConnectionManager() {
146 return getFromContainer(ConnectionManager);
147}
148/**
149 * Creates a new connection and registers it in the manager.
150 *
151 * If connection options were not specified, then it will try to create connection automatically,
152 * based on content of ormconfig (json/js/yml/xml/env) file or environment variables.
153 * Only one connection from ormconfig will be created (name "default" or connection without name).
154 */
155export function createConnection(optionsOrName) {
156 return tslib_1.__awaiter(this, void 0, void 0, function () {
157 var connectionName, options, _a;
158 return tslib_1.__generator(this, function (_b) {
159 switch (_b.label) {
160 case 0:
161 connectionName = typeof optionsOrName === "string" ? optionsOrName : "default";
162 if (!(optionsOrName instanceof Object)) return [3 /*break*/, 1];
163 _a = optionsOrName;
164 return [3 /*break*/, 3];
165 case 1: return [4 /*yield*/, getConnectionOptions(connectionName)];
166 case 2:
167 _a = _b.sent();
168 _b.label = 3;
169 case 3:
170 options = _a;
171 return [2 /*return*/, getConnectionManager().create(options).connect()];
172 }
173 });
174 });
175}
176/**
177 * Creates new connections and registers them in the manager.
178 *
179 * If connection options were not specified, then it will try to create connection automatically,
180 * based on content of ormconfig (json/js/yml/xml/env) file or environment variables.
181 * All connections from the ormconfig will be created.
182 */
183export function createConnections(options) {
184 return tslib_1.__awaiter(this, void 0, void 0, function () {
185 var connections;
186 return tslib_1.__generator(this, function (_a) {
187 switch (_a.label) {
188 case 0:
189 if (!!options) return [3 /*break*/, 2];
190 return [4 /*yield*/, new ConnectionOptionsReader().all()];
191 case 1:
192 options = _a.sent();
193 _a.label = 2;
194 case 2:
195 connections = options.map(function (options) { return getConnectionManager().create(options); });
196 return [2 /*return*/, PromiseUtils.runInSequence(connections, function (connection) { return connection.connect(); })];
197 }
198 });
199 });
200}
201/**
202 * Gets connection from the connection manager.
203 * If connection name wasn't specified, then "default" connection will be retrieved.
204 */
205export function getConnection(connectionName) {
206 if (connectionName === void 0) { connectionName = "default"; }
207 return getConnectionManager().get(connectionName);
208}
209/**
210 * Gets entity manager from the connection.
211 * If connection name wasn't specified, then "default" connection will be retrieved.
212 */
213export function getManager(connectionName) {
214 if (connectionName === void 0) { connectionName = "default"; }
215 return getConnectionManager().get(connectionName).manager;
216}
217/**
218 * Gets MongoDB entity manager from the connection.
219 * If connection name wasn't specified, then "default" connection will be retrieved.
220 */
221export function getMongoManager(connectionName) {
222 if (connectionName === void 0) { connectionName = "default"; }
223 return getConnectionManager().get(connectionName).manager;
224}
225/**
226 * Gets Sqljs entity manager from connection name.
227 * "default" connection is used, when no name is specified.
228 * Only works when Sqljs driver is used.
229 */
230export function getSqljsManager(connectionName) {
231 if (connectionName === void 0) { connectionName = "default"; }
232 return getConnectionManager().get(connectionName).manager;
233}
234/**
235 * Gets repository for the given entity class.
236 */
237export function getRepository(entityClass, connectionName) {
238 if (connectionName === void 0) { connectionName = "default"; }
239 return getConnectionManager().get(connectionName).getRepository(entityClass);
240}
241/**
242 * Gets tree repository for the given entity class.
243 */
244export function getTreeRepository(entityClass, connectionName) {
245 if (connectionName === void 0) { connectionName = "default"; }
246 return getConnectionManager().get(connectionName).getTreeRepository(entityClass);
247}
248/**
249 * Gets tree repository for the given entity class.
250 */
251export function getCustomRepository(customRepository, connectionName) {
252 if (connectionName === void 0) { connectionName = "default"; }
253 return getConnectionManager().get(connectionName).getCustomRepository(customRepository);
254}
255/**
256 * Gets mongodb repository for the given entity class or name.
257 */
258export function getMongoRepository(entityClass, connectionName) {
259 if (connectionName === void 0) { connectionName = "default"; }
260 return getConnectionManager().get(connectionName).getMongoRepository(entityClass);
261}
262/**
263 * Creates a new query builder.
264 */
265export function createQueryBuilder(entityClass, alias, connectionName) {
266 if (connectionName === void 0) { connectionName = "default"; }
267 if (entityClass) {
268 return getRepository(entityClass, connectionName).createQueryBuilder(alias);
269 }
270 return getConnection(connectionName).createQueryBuilder();
271}
272
273//# sourceMappingURL=index.js.map