Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Repository<Entity>

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

Type parameters

Hierarchy

Index

Properties

manager

manager: EntityManager

Entity Manager used by this repository.

metadata

metadata: EntityMetadata

Entity metadata of the entity current repository manages.

Optional queryRunner

queryRunner: QueryRunner

Query runner provider used for this repository.

Accessors

target

  • get target(): Function | string
  • Returns object that is managed by this repository. If this repository manages entity from schema, then it returns a name of that schema instead.

    Returns Function | string

Methods

clear

  • clear(): Promise<void>

count

create

  • create(): Entity
  • create(entityLikeArray: DeepPartial<Entity>[]): Entity[]
  • create(entityLike: DeepPartial<Entity>): Entity
  • Creates a new entity instance.

    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.

    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.

    Parameters

    Returns Entity

createQueryBuilder

decrement

delete

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

    Parameters

    Returns Promise<DeleteResult>

find

findAndCount

  • findAndCount(options?: FindManyOptions<Entity>): Promise<[Entity[], number]>
  • findAndCount(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).

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

    Parameters

    Returns Promise<[Entity[], number]>

findByIds

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

findOne

findOneOrFail

getId

  • getId(entity: Entity): any

hasId

  • hasId(entity: Entity): boolean
  • Checks if entity has an id. If entity composite compose ids, it will check them all.

    Parameters

    • entity: Entity

    Returns boolean

increment

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.

    Parameters

    Returns Promise<InsertResult>

merge

  • merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity
  • Merges multiple entities (or entity-like objects) into a given entity.

    Parameters

    • mergeIntoEntity: Entity
    • Rest ...entityLikes: DeepPartial<Entity>[]

    Returns Entity

preload

  • preload(entityLike: DeepPartial<Entity>): 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.

    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.

    Parameters

    Returns Promise<Entity | undefined>

query

  • query(query: string, parameters?: any[]): Promise<any>
  • Executes a raw SQL query and returns a raw database results. Raw query execution is supported only by relational databases (MongoDB is not supported).

    Parameters

    • query: string
    • Optional parameters: any[]

    Returns Promise<any>

remove

  • remove(entities: Entity[], options?: RemoveOptions): Promise<Entity[]>
  • remove(entity: Entity, options?: RemoveOptions): Promise<Entity>

save

  • save<T>(entities: T[], options: SaveOptions & object): Promise<T[]>
  • save<T>(entities: T[], options?: SaveOptions): Promise<(T & Entity)[]>
  • save<T>(entity: T, options: SaveOptions & object): Promise<T>
  • save<T>(entity: T, options?: SaveOptions): Promise<T & 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 & Entity)[]>

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

    Type parameters

    Parameters

    Returns Promise<T>

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

    Type parameters

    Parameters

    Returns Promise<T & Entity>

update

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

    Parameters

    Returns Promise<UpdateResult>

Generated using TypeDoc