Skip to content

Commit

Permalink
added getConnection and getRepository shortcut methods to main entry …
Browse files Browse the repository at this point in the history
…point
  • Loading branch information
Umed Khudoiberdiev committed Sep 28, 2016
1 parent 1b8ecee commit bc8b604
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {Connection} from "./connection/Connection";
import {MetadataArgsStorage} from "./metadata-args/MetadataArgsStorage";
import {ConnectionOptions} from "./connection/ConnectionOptions";
import {getFromContainer, defaultContainer} from "./container";
import {ObjectType} from "./common/ObjectType";
import {Repository} from "./repository/Repository";
import {EntityManager} from "./entity-manager/EntityManager";

// -------------------------------------------------------------------------
// Commonly Used exports
Expand Down Expand Up @@ -200,4 +203,37 @@ export function createConnections(ormConfigPath?: string): Promise<Connection[]>
*/
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);
}

0 comments on commit bc8b604

Please sign in to comment.