数据库操作上下文是基于请求上下文实现,所以数据库操作上下文也是请求级别的。在数据库上下文中主要提供了与数据库操作相关的方法。
定义
export namespace OrmContext {
export function getEntityManager(name = DEFAULT_CONNECTION_NAME): EntityManager {
...
}
export function getRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): Repository<Entity> {
...
}
export function getTreeRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): TreeRepository<Entity> {
...
}
export function getMongoRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): MongoRepository<Entity> {
...
}
export function getCustomRepository<T>(customRepository: ObjectType<T>, name?: string): T {
...
}
export function pushEntityManager(name: string, entityManager: EntityManager): void {
...
}
export function popEntityManager(name: string): EntityManager | undefined {
...
}
}