Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TreeRepository<Entity>

Repository with additional functions to work with trees.

see

Repository

Type parameters

  • Entity

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

Protected buildChildrenEntityTree

  • buildChildrenEntityTree(entity: any, entities: any[], relationMaps: object[]): void

Protected buildParentEntityTree

  • buildParentEntityTree(entity: any, entities: any[], relationMaps: object[]): void

clear

  • clear(): Promise<void>

count

countAncestors

  • countAncestors(entity: Entity): Promise<number>

countDescendants

  • countDescendants(entity: Entity): Promise<number>

create

  • create(): Entity
  • create(entityLikeArray: DeepPartial<Entity>[]): Entity[]
  • create(entityLike: DeepPartial<Entity>): Entity

createAncestorsQueryBuilder

  • createAncestorsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity>

createDescendantsQueryBuilder

  • createDescendantsQueryBuilder(alias: string, closureTableAlias: string, entity: Entity): SelectQueryBuilder<Entity>

createQueryBuilder

Protected createRelationMaps

  • createRelationMaps(alias: string, rawResults: any[]): object[]
  • Moves entity to the children of then given entity.

    move(entity: Entity, to: Entity): Promise { return Promise.resolve(); }

    Parameters

    • alias: string
    • rawResults: any[]

    Returns object[]

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

findAncestors

  • findAncestors(entity: Entity): Promise<Entity[]>
  • Gets all parents (ancestors) of the given entity. Returns them all in a flat array.

    Parameters

    • entity: Entity

    Returns Promise<Entity[]>

findAncestorsTree

  • findAncestorsTree(entity: Entity): Promise<Entity>
  • Gets all parents (ancestors) of the given entity. Returns them in a tree - nested into each other.

    Parameters

    • entity: Entity

    Returns Promise<Entity>

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[]>

findDescendants

  • findDescendants(entity: Entity): Promise<Entity[]>
  • Gets all children (descendants) of the given entity. Returns them all in a flat array.

    Parameters

    • entity: Entity

    Returns Promise<Entity[]>

findDescendantsTree

  • findDescendantsTree(entity: Entity): Promise<Entity>
  • Gets all children (descendants) of the given entity. Returns them in a tree - nested into each other.

    Parameters

    • entity: Entity

    Returns Promise<Entity>

findOne

findOneOrFail

findRoots

  • findRoots(): Promise<Entity[]>

findTrees

  • findTrees(): Promise<Entity[]>

getId

  • getId(entity: Entity): any

hasId

  • hasId(entity: Entity): 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

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>

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