Skip to main content
Module

x/typeorm/src/index.ts>Repository

Forked from https://github.com/typeorm/typeorm
Latest
class Repository
Re-export
import { Repository } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/index.ts";

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

Type Parameters

Entity extends ObjectLiteral

Properties

readonly
manager: EntityManager

Entity Manager used by this repository.

readonly
metadata: EntityMetadata

Entity metadata of the entity current repository manages.

readonly
optional
queryRunner: QueryRunner

Query runner provider used for this repository.

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

Methods

clear(): Promise<void>

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.

count(options?: FindManyOptions<Entity>): Promise<number>

Counts entities that match given options.

count(conditions?: FindConditions<Entity>): Promise<number>

Counts entities that match given conditions.

Creates a new entity instance.

create(entityLikeArray: DeepPartial<Entity>[]): 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.

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

createQueryBuilder(alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>

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

decrement(
conditions: FindConditions<Entity>,
propertyPath: string,
value: number | string,
): Promise<UpdateResult>

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

delete(criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<Entity>
): Promise<DeleteResult>

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.

find(options?: FindManyOptions<Entity>): Promise<Entity[]>

Finds entities that match given options.

find(conditions?: FindConditions<Entity>): Promise<Entity[]>

Finds entities that match given conditions.

findAndCount(options?: FindManyOptions<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).

findAndCount(conditions?: FindConditions<Entity>): 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).

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

Finds entities by ids. Optionally find options can be applied.

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

Finds entities by ids. Optionally conditions can be applied.

findOne(id?:
| string
| number
| Date
| ObjectID
, options?: FindOneOptions<Entity>
): Promise<Entity | undefined>

Finds first entity that matches given options.

findOne(options?: FindOneOptions<Entity>): Promise<Entity | undefined>

Finds first entity that matches given options.

findOne(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity | undefined>

Finds first entity that matches given conditions.

findOneOrFail(id?:
| string
| number
| Date
| ObjectID
, options?: FindOneOptions<Entity>
): Promise<Entity>

Finds first entity that matches given options.

findOneOrFail(options?: FindOneOptions<Entity>): Promise<Entity>

Finds first entity that matches given options.

findOneOrFail(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity>

Finds first entity that matches given conditions.

getId(entity: Entity): any

Gets entity mixed id.

hasId(entity: Entity): boolean

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

increment(
conditions: FindConditions<Entity>,
propertyPath: string,
value: number | string,
): Promise<UpdateResult>

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

insert(entity: QueryDeepPartialEntity<Entity> | (QueryDeepPartialEntity<Entity>[])): Promise<InsertResult>

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.

merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity

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

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.

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

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

Removes a given entities from the database.

remove(entity: Entity, options?: RemoveOptions): Promise<Entity>

Removes a given entity from the database.

save<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false; }): Promise<T[]>

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

save<T extends DeepPartial<Entity>>(entities: 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.

save<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false; }): Promise<T>

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

save<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>

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

update(criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<Entity>
, partialEntity: QueryDeepPartialEntity<Entity>
): Promise<UpdateResult>

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.

Type Parameters

Entity extends ObjectLiteral

Properties

readonly
manager: EntityManager

Entity Manager used by this repository.

readonly
metadata: EntityMetadata

Entity metadata of the entity current repository manages.

readonly
optional
queryRunner: QueryRunner

Query runner provider used for this repository.

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

Methods

clear(): Promise<void>

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.

count(options?: FindManyOptions<Entity>): Promise<number>

Counts entities that match given options.

count(conditions?: FindConditions<Entity>): Promise<number>

Counts entities that match given conditions.

Creates a new entity instance.

create(entityLikeArray: DeepPartial<Entity>[]): 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.

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

createQueryBuilder(alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>

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

decrement(
conditions: FindConditions<Entity>,
propertyPath: string,
value: number | string,
): Promise<UpdateResult>

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

delete(criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<Entity>
): Promise<DeleteResult>

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.

find(options?: FindManyOptions<Entity>): Promise<Entity[]>

Finds entities that match given options.

find(conditions?: FindConditions<Entity>): Promise<Entity[]>

Finds entities that match given conditions.

findAndCount(options?: FindManyOptions<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).

findAndCount(conditions?: FindConditions<Entity>): 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).

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

Finds entities by ids. Optionally find options can be applied.

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

Finds entities by ids. Optionally conditions can be applied.

findOne(id?:
| string
| number
| Date
| ObjectID
, options?: FindOneOptions<Entity>
): Promise<Entity | undefined>

Finds first entity that matches given options.

findOne(options?: FindOneOptions<Entity>): Promise<Entity | undefined>

Finds first entity that matches given options.

findOne(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity | undefined>

Finds first entity that matches given conditions.

findOneOrFail(id?:
| string
| number
| Date
| ObjectID
, options?: FindOneOptions<Entity>
): Promise<Entity>

Finds first entity that matches given options.

findOneOrFail(options?: FindOneOptions<Entity>): Promise<Entity>

Finds first entity that matches given options.

findOneOrFail(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>): Promise<Entity>

Finds first entity that matches given conditions.

getId(entity: Entity): any

Gets entity mixed id.

hasId(entity: Entity): boolean

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

increment(
conditions: FindConditions<Entity>,
propertyPath: string,
value: number | string,
): Promise<UpdateResult>

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

insert(entity: QueryDeepPartialEntity<Entity> | (QueryDeepPartialEntity<Entity>[])): Promise<InsertResult>

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.

merge(mergeIntoEntity: Entity, ...entityLikes: DeepPartial<Entity>[]): Entity

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

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.

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

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

Removes a given entities from the database.

remove(entity: Entity, options?: RemoveOptions): Promise<Entity>

Removes a given entity from the database.

save<T extends DeepPartial<Entity>>(entities: T[], options: SaveOptions & { reload: false; }): Promise<T[]>

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

save<T extends DeepPartial<Entity>>(entities: 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.

save<T extends DeepPartial<Entity>>(entity: T, options: SaveOptions & { reload: false; }): Promise<T>

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

save<T extends DeepPartial<Entity>>(entity: T, options?: SaveOptions): Promise<T & Entity>

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

update(criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<Entity>
, partialEntity: QueryDeepPartialEntity<Entity>
): Promise<UpdateResult>

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.