API 参考
    正在准备搜索索引...

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

    层级 (查看层级一览)

    索引

    构造函数

    • 参数

      返回 EntityManager

    属性

    "@instanceof": symbol
    connection: DataSource

    Connection used by this entity manager.

    plainObjectToEntityTransformer: PlainObjectToNewEntityTransformer

    Plain to object transformer used in create and merge operations.

    queryRunner?: QueryRunner

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

    repositories: Map<EntityTarget<any>, Repository<any>>

    Once created and then reused by repositories. Created as a future replacement for the #repositories to provide a bit more perf optimization.

    treeRepositories: TreeRepository<any>[]

    Once created and then reused by repositories.

    方法

    • Clears all the data from the given table (truncates/drops it).

      Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.

      类型参数

      • Entity

      参数

      返回 Promise<void>

    • Counts entities that match given options. Useful for pagination.

      类型参数

      参数

      返回 Promise<number>

    • 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.

      类型参数

      • Entity
      • EntityLike

      参数

      返回 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.

      类型参数

      • Entity
      • EntityLike

      参数

      返回 Entity[]

    • Creates a new query builder that can be used to build a SQL query.

      类型参数

      参数

      返回 SelectQueryBuilder<Entity>

    • Creates a new query builder that can be used to build a SQL query.

      参数

      返回 SelectQueryBuilder<any>

    • Decrements some column by provided value of the entities matched given conditions.

      类型参数

      参数

      • entityClass: EntityTarget<Entity>
      • conditions: any
      • propertyPath: string
      • value: string | number

      返回 Promise<UpdateResult>

    • 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.

      类型参数

      参数

      返回 Promise<DeleteResult>

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

      类型参数

      参数

      返回 Promise<[Entity[], number]>

    • Finds entities with ids. Optionally find options or conditions can be applied.

      类型参数

      参数

      返回 Promise<Entity[]>

      use findBy method instead in conjunction with In operator, for example:

      .findBy({ id: In([1, 2, 3]) })

    • Finds first entity that matches given id. If entity was not found in the database - returns null.

      类型参数

      参数

      返回 Promise<null | Entity>

      use findOneBy method instead in conjunction with In operator, for example:

      .findOneBy({ id: 1 // where "id" is your primary column name })

    • Gets custom entity repository marked with

      类型参数

      • T

      参数

      返回 T

      decorator.

      use Repository.extend to create custom repositories

    • Gets entity mixed id.

      参数

      • entity: any

      返回 any

    • Gets entity mixed id.

      参数

      返回 any

    • 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.

      类型参数

      参数

      返回 Repository<Entity>

    • 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.

      类型参数

      参数

      返回 TreeRepository<Entity>

    • Checks if entity has an id.

      参数

      • entity: any

      返回 boolean

    • Checks if entity of given schema name has an id.

      参数

      • target: string | Function
      • entity: any

      返回 boolean

    • Increments some column by provided value of the entities matched given conditions.

      类型参数

      参数

      • entityClass: EntityTarget<Entity>
      • conditions: any
      • propertyPath: string
      • value: string | number

      返回 Promise<UpdateResult>

    • 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.

      类型参数

      参数

      返回 Promise<InsertResult>

    • Creates a new entity from the given plain 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.

      类型参数

      参数

      返回 Promise<undefined | Entity>

    • Executes raw SQL query and returns raw database results.

      类型参数

      • T = any

      参数

      • query: string
      • 可选parameters: any[]

      返回 Promise<T>

      Official docs for examples.

    • Recovers all given entities.

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Recovers a given entity.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Recovers all given entities.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

    • Recovers a given entity.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

    • 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.

      返回 Promise<void>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Removes a given entity from the database.

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Restores 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.

      类型参数

      参数

      返回 Promise<UpdateResult>

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

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

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

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

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

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

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

      类型参数

      • Entity
      • T

      参数

      返回 Promise<(T & Entity)[]>

    • Saves a given entity in the database. If entity does not exist in the database then inserts, otherwise updates.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

    • Saves a given entity in the database. If entity does not exist in the database then inserts, otherwise updates.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T & Entity>

    • Records the delete date of 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.

      类型参数

      参数

      返回 Promise<UpdateResult>

    • Records the delete date of all given entities.

      类型参数

      • Entity

      参数

      返回 Promise<Entity[]>

    • Records the delete date of a given entity.

      类型参数

      • Entity

      参数

      返回 Promise<Entity>

    • Records the delete date of all given entities.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T[]>

    • Records the delete date of a given entity.

      类型参数

      • Entity
      • T

      参数

      返回 Promise<T>

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

      类型参数

      • T

      参数

      返回 Promise<T>

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

      类型参数

      • T

      参数

      • isolationLevel: IsolationLevel
      • runInTransaction: (entityManager: EntityManager) => Promise<T>

      返回 Promise<T>

    • 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.

      类型参数

      参数

      返回 Promise<UpdateResult>

    • Creates a new repository instance out of a given Repository and sets current EntityManager instance to it. Used to work with custom repositories in transactions.

      类型参数

      参数

      返回 R