Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EntityManager

Entity manager supposed to work with any entity, automatically find its repository and call its methods, whatever entity type are you passing.

Hierarchy

Index

Constructors

constructor

Properties

connection

connection: Connection

Connection used by this entity manager.

Protected plainObjectToEntityTransformer

plainObjectToEntityTransformer: PlainObjectToNewEntityTransformer = new PlainObjectToNewEntityTransformer()

Plain to object transformer used in create and merge operations.

Optional queryRunner

queryRunner: QueryRunner

Custom query runner to be used for operations in this entity manager. Used only in non-global entity manager.

Protected repositories

repositories: Repository<any>[] = []

Once created and then reused by en repositories.

Methods

clear

count

create

  • Creates a new entity instance and copies all entity properties from this object into a new entity. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    Returns Entity

  • Creates a new entities and copies all entity properties from given objects into their new entities. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    Returns Entity[]

  • Creates a new entity instance and copies all entity properties from this object into a new entity. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    Returns Entity

  • Creates a new entities and copies all entity properties from given objects into their new entities. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    Returns Entity[]

  • Creates a new entity instance and copies all entity properties from this object into a new entity. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    • entityName: string
    • Optional plainObject: DeepPartial<Entity>

    Returns Entity

  • Creates a new entities and copies all entity properties from given objects into their new entities. Note that it copies only properties that present in entity schema.

    Type parameters

    • Entity

    Parameters

    • entityName: string
    • Optional plainObjects: DeepPartial<Entity>[]

    Returns Entity[]

createQueryBuilder

decrement

  • decrement<Entity>(entityClass: ObjectType<Entity> | EntitySchema<Entity> | string, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>

delete

  • Deletes entities by a given condition(s). Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient DELETE query. Does not check if entity exist in the database. Condition(s) cannot be empty.

    Type parameters

    • Entity

    Parameters

    Returns Promise<DeleteResult>

find

findAndCount

  • findAndCount<Entity>(entityClass: ObjectType<Entity>, options?: FindManyOptions<Entity>): Promise<[Entity[], number]>
  • findAndCount<Entity>(entityClass: EntitySchema<Entity>, options?: FindManyOptions<Entity>): Promise<[Entity[], number]>
  • findAndCount<Entity>(entityClass: string, options?: FindManyOptions<Entity>): Promise<[Entity[], number]>
  • findAndCount<Entity>(entityClass: ObjectType<Entity>, conditions?: FindConditions<Entity>): Promise<[Entity[], number]>
  • findAndCount<Entity>(entityClass: EntitySchema<Entity>, conditions?: FindConditions<Entity>): Promise<[Entity[], number]>
  • findAndCount<Entity>(entityClass: string, conditions?: FindConditions<Entity>): Promise<[Entity[], number]>
  • Finds entities that match given find options. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

  • Finds entities that match given find options. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

  • Finds entities that match given find options. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

  • Finds entities that match given conditions. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

  • Finds entities that match given conditions. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

  • Finds entities that match given conditions. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).

    Type parameters

    • Entity

    Parameters

    Returns Promise<[Entity[], number]>

findByIds

  • findByIds<Entity>(entityClass: ObjectType<Entity>, ids: any[], options?: FindManyOptions<Entity>): Promise<Entity[]>
  • findByIds<Entity>(entityClass: EntitySchema<Entity>, ids: any[], options?: FindManyOptions<Entity>): Promise<Entity[]>
  • findByIds<Entity>(entityClass: string, ids: any[], options?: FindManyOptions<Entity>): Promise<Entity[]>
  • findByIds<Entity>(entityClass: ObjectType<Entity>, ids: any[], conditions?: FindConditions<Entity>): Promise<Entity[]>
  • findByIds<Entity>(entityClass: EntitySchema<Entity>, ids: any[], conditions?: FindConditions<Entity>): Promise<Entity[]>
  • findByIds<Entity>(entityClass: string, ids: any[], conditions?: FindConditions<Entity>): Promise<Entity[]>

findOne

findOneOrFail

getCustomRepository

  • getCustomRepository<T>(customRepository: ObjectType<T>): T

getId

  • getId(entity: any): any
  • getId(target: Function | string, entity: any): any

getMongoRepository

getRepository

  • Gets repository for the given entity class or name. If single database connection mode is used, then repository is obtained from the repository aggregator, where each repository is individually created for this entity manager. When single database connection is not used, repository is being obtained from the connection.

    Type parameters

    • Entity

    Parameters

    Returns Repository<Entity>

getTreeRepository

  • Gets tree repository for the given entity class or name. If single database connection mode is used, then repository is obtained from the repository aggregator, where each repository is individually created for this entity manager. When single database connection is not used, repository is being obtained from the connection.

    Type parameters

    • Entity

    Parameters

    Returns TreeRepository<Entity>

hasId

  • hasId(entity: any): boolean
  • hasId(target: Function | string, entity: any): boolean

increment

  • increment<Entity>(entityClass: ObjectType<Entity> | EntitySchema<Entity> | string, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>

insert

  • Inserts a given entity into the database. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT query. Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted. You can execute bulk inserts using this method.

    Type parameters

    • Entity

    Parameters

    Returns Promise<InsertResult>

merge

  • merge<Entity>(entityClass: ObjectType<Entity>, mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity
  • merge<Entity>(entitySchema: EntitySchema<Entity>, mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity
  • merge<Entity>(entityName: string, mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity

preload

  • preload<Entity>(entityClass: ObjectType<Entity>, entityLike: DeepPartial<Entity>): Promise<Entity | undefined>
  • preload<Entity>(entitySchema: EntitySchema<Entity>, entityLike: DeepPartial<Entity>): Promise<Entity | undefined>
  • preload(entityName: string, entityLike: DeepPartial<any>): Promise<any | undefined>
  • Creates a new entity from the given plan javascript object. If entity already exist in the database, then it loads it (and everything related to it), replaces all values with the new ones from the given object and returns this new entity. This new entity is actually a loaded from the db entity with all properties replaced from the new object.

    Type parameters

    • Entity

    Parameters

    Returns Promise<Entity | undefined>

  • Creates a new entity from the given plan javascript object. If entity already exist in the database, then it loads it (and everything related to it), replaces all values with the new ones from the given object and returns this new entity. This new entity is actually a loaded from the db entity with all properties replaced from the new object.

    Type parameters

    • Entity

    Parameters

    Returns Promise<Entity | undefined>

  • Creates a new entity from the given plan javascript object. If entity already exist in the database, then it loads it (and everything related to it), replaces all values with the new ones from the given object and returns this new entity. This new entity is actually a loaded from the db entity with all properties replaced from the new object.

    Parameters

    Returns Promise<any | undefined>

query

  • query(query: string, parameters?: any[]): Promise<any>
  • Executes raw SQL query and returns raw database results.

    Parameters

    • query: string
    • Optional parameters: any[]

    Returns Promise<any>

release

  • release(): Promise<void>
  • Releases all resources used by entity manager. This is used when entity manager is created with a single query runner, and this single query runner needs to be released after job with entity manager is done.

    Returns Promise<void>

remove

  • remove<Entity>(entity: Entity, options?: RemoveOptions): Promise<Entity>
  • remove<Entity>(targetOrEntity: ObjectType<Entity>, entity: Entity, options?: RemoveOptions): Promise<Entity>
  • remove<Entity>(targetOrEntity: EntitySchema<Entity>, entity: Entity, options?: RemoveOptions): Promise<Entity>
  • remove<Entity>(targetOrEntity: string, entity: Entity, options?: RemoveOptions): Promise<Entity>
  • remove<Entity>(entity: Entity[], options?: RemoveOptions): Promise<Entity>
  • remove<Entity>(targetOrEntity: ObjectType<Entity>, entity: Entity[], options?: RemoveOptions): Promise<Entity[]>
  • remove<Entity>(targetOrEntity: EntitySchema<Entity>, entity: Entity[], options?: RemoveOptions): Promise<Entity[]>
  • remove<Entity>(targetOrEntity: string, entity: Entity[], options?: RemoveOptions): Promise<Entity[]>

save

  • save<Entity>(entities: Entity[], options?: SaveOptions): Promise<Entity[]>
  • save<Entity>(entity: Entity, options?: SaveOptions): Promise<Entity>
  • save<Entity, T>(targetOrEntity: ObjectType<Entity> | EntitySchema<Entity>, entities: T[], options?: SaveOptions): Promise<T[]>
  • save<Entity, T>(targetOrEntity: ObjectType<Entity> | EntitySchema<Entity>, entity: T, options?: SaveOptions): Promise<T>
  • save<T>(targetOrEntity: string, entities: T[], options?: SaveOptions): Promise<T[]>
  • save<T>(targetOrEntity: string, entity: T, options?: SaveOptions): Promise<T>
  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    • Entity

    Parameters

    Returns Promise<Entity[]>

  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    • Entity

    Parameters

    Returns Promise<Entity>

  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    Parameters

    Returns Promise<T[]>

  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    Parameters

    Returns Promise<T>

  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    • T

    Parameters

    • targetOrEntity: string
    • entities: T[]
    • Optional options: SaveOptions

    Returns Promise<T[]>

  • Saves all given entities in the database. If entities do not exist in the database then inserts, otherwise updates.

    Type parameters

    • T

    Parameters

    • targetOrEntity: string
    • entity: T
    • Optional options: SaveOptions

    Returns Promise<T>

transaction

  • transaction<T>(runInTransaction: function): Promise<T>
  • transaction<T>(isolationLevel: IsolationLevel, runInTransaction: function): Promise<T>
  • Wraps given function execution (and all operations made there) in a transaction. All database operations must be executed using provided entity manager.

    Type parameters

    • T

    Parameters

    • runInTransaction: function

    Returns Promise<T>

  • Wraps given function execution (and all operations made there) in a transaction. All database operations must be executed using provided entity manager.

    Type parameters

    • T

    Parameters

    Returns Promise<T>

update

  • Updates entity partially. Entity can be found by a given condition(s). Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient UPDATE query. Does not check if entity exist in the database. Condition(s) cannot be empty.

    Type parameters

    • Entity

    Parameters

    Returns Promise<UpdateResult>

Generated using TypeDoc