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

    类 Repository<Entity>

    Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc.

    类型参数

    层级 (查看层级一览)

    索引

    构造函数

    属性

    manager: EntityManager

    Entity Manager used by this repository.

    queryRunner?: QueryRunner

    Query runner provider used for this repository.

    Entity target that is managed by this repository. If this repository manages entity from schema, then it returns a name of that schema instead.

    访问器

    • get metadata(): EntityMetadata

      Entity metadata of the entity current repository manages.

      返回 EntityMetadata

    方法

    • Return the AVG of a column

      参数

      返回 Promise<null | number>

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

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

      返回 Promise<void>

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

      参数

      返回 Promise<number>

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

      返回 Promise<number>

    • Creates a new entity instance.

      返回 Entity

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

      参数

      返回 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 are present in entity schema.

      参数

      返回 Entity

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

      参数

      返回 SelectQueryBuilder<Entity>

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

      参数

      返回 Promise<UpdateResult>

    • Deletes entities by a given criteria. 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.

      参数

      返回 Promise<DeleteResult>

    • Checks whether any entity exists that matches the given options.

      参数

      返回 Promise<boolean>

      use exists method instead, for example:

      .exists()

    • Checks whether any entity exists that matches the given options.

      参数

      返回 Promise<boolean>

    • Checks whether any entity exists that matches the given conditions.

      返回 Promise<boolean>

    • Finds entities that match given find options.

      参数

      返回 Promise<Entity[]>

    • 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 that match given WHERE conditions. 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.

      参数

      • ids: any[]

      返回 Promise<Entity[]>

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

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

    • Finds first entity by a given find options. If entity was not found in the database - returns null.

      参数

      返回 Promise<null | Entity>

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

      返回 Promise<null | Entity>

    • 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 })

    • Finds first entity that matches given where condition. If entity was not found in the database - rejects with error.

      返回 Promise<Entity>

    • Finds first entity by a given find options. If entity was not found in the database - rejects with error.

      参数

      返回 Promise<Entity>

    • Gets entity mixed id.

      参数

      返回 any

    • Checks if entity has an id. If entity composite compose ids, it will check them all.

      参数

      返回 boolean

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

      参数

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

      参数

      返回 Promise<InsertResult>

    • Return the MAX of a column

      参数

      返回 Promise<null | number>

    • Merges multiple entities (or entity-like objects) into a given entity.

      参数

      返回 Entity

    • Return the MIN of a column

      参数

      返回 Promise<null | number>

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

      Note that given entity-like object must have an entity id / primary key to find entity by. Returns undefined if entity with given id was not found.

      参数

      返回 Promise<undefined | Entity>

    • Executes a raw SQL query and returns a raw database results. Raw query execution is supported only by relational databases (MongoDB is not supported).

      参数

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

      返回 Promise<any>

      Official docs for examples.

    • Recovers all given entities in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

    • Recovers all given entities in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

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

    • Recovers a given entity in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

    • Recovers a given entity in the database.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

    • Removes a given entities from the database.

      参数

      返回 Promise<Entity[]>

    • Removes a given entity from the database.

      参数

      返回 Promise<Entity>

    • Restores entities by a given criteria. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient SOFT-DELETE query. Does not check if entity exist in the database.

      参数

      返回 Promise<UpdateResult>

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

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

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

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

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

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

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

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

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

    • Records the delete date of entities by a given criteria. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient SOFT-DELETE query. Does not check if entity exist in the database.

      参数

      返回 Promise<UpdateResult>

    • Records the delete date of all given entities.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T[]>

    • Records the delete date of all given entities.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

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

    • Records the delete date of a given entity.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T>

    • Records the delete date of a given entity.

      类型参数

      • T extends
            | ObjectLiteral
            | Map<unknown, unknown>
            | Set<unknown>
            | any[]
            | { [key: string]: any }

      参数

      返回 Promise<T & Entity>

    • Return the SUM of a column

      参数

      返回 Promise<null | number>

    • Updates entity partially. Entity can be found by a given conditions. 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.

      参数

      • criteria:
            | string
            | number
            | string[]
            | Date
            | ObjectId
            | number[]
            | Date[]
            | ObjectId[]
            | FindOptionsWhere<Entity>
      • partialEntity: QueryDeepPartialEntity<Entity>

      返回 Promise<UpdateResult>

    • Inserts a given entity into the database, unless a unique constraint conflicts then updates the entity Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient INSERT ... ON CONFLICT DO UPDATE/ON DUPLICATE KEY UPDATE query.

      参数

      返回 Promise<InsertResult>