数据库操作上下文是基于请求上下文实现,所以数据库操作上下文也是请求级别的。在数据库上下文中主要提供了与数据库操作相关的方法。

定义

  1. export namespace OrmContext {
  2. export function getEntityManager(name = DEFAULT_CONNECTION_NAME): EntityManager {
  3. ...
  4. }
  5. export function getRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): Repository<Entity> {
  6. ...
  7. }
  8. export function getTreeRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): TreeRepository<Entity> {
  9. ...
  10. }
  11. export function getMongoRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string, name?: string): MongoRepository<Entity> {
  12. ...
  13. }
  14. export function getCustomRepository<T>(customRepository: ObjectType<T>, name?: string): T {
  15. ...
  16. }
  17. export function pushEntityManager(name: string, entityManager: EntityManager): void {
  18. ...
  19. }
  20. export function popEntityManager(name: string): EntityManager | undefined {
  21. ...
  22. }
  23. }