Skip to main content
Module

x/typeorm/src/index.ts>BaseEntity

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

Base abstract entity for all entities, used in ActiveRecord patterns.

Methods

hasId(): boolean

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

reload(): Promise<void>

Reloads entity data from the database.

remove(options?: RemoveOptions): Promise<this>

Removes current entity from the database.

save(options?: SaveOptions): Promise<this>

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

Static Properties

private
optional
usedConnection: Connection

Connection used in all static methods of the BaseEntity.

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.

Static Methods

clear<T extends BaseEntity>(this: ObjectType<T>): Promise<void>

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

count<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<number>

Counts entities that match given options.

count<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<number>

Counts entities that match given conditions.

create<T extends BaseEntity>(this: ObjectType<T>): T

Creates a new entity instance.

create<T extends BaseEntity>(this: ObjectType<T>, entityLikeArray: DeepPartial<T>[]): T

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<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): T

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<T extends BaseEntity>(this: ObjectType<T>, alias?: string): SelectQueryBuilder<T>

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

delete<T extends BaseEntity>(
this: ObjectType<T>,
criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<T>
,
options?: RemoveOptions,
): Promise<DeleteResult>

Deletes entities by a given criteria. Unlike remove 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<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<T[]>

Finds entities that match given options.

find<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<T[]>

Finds entities that match given conditions.

findAndCount<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<[T[], 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<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<[T[], number]>

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

findByIds<T extends BaseEntity>(
this: ObjectType<T>,
ids: any[],
options?: FindManyOptions<T>,
): Promise<T[]>

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

findByIds<T extends BaseEntity>(
this: ObjectType<T>,
ids: any[],
conditions?: FindConditions<T>,
): Promise<T[]>

Finds entities by ids. Optionally conditions can be applied.

findOne<T extends BaseEntity>(
this: ObjectType<T>,
id?:
| string
| number
| Date
| ObjectID
,
options?: FindOneOptions<T>,
): Promise<T | undefined>

Finds first entity that matches given options.

findOne<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T | undefined>

Finds first entity that matches given options.

findOne<T extends BaseEntity>(
this: ObjectType<T>,
conditions?: FindConditions<T>,
options?: FindOneOptions<T>,
): Promise<T | undefined>

Finds first entity that matches given conditions.

findOneOrFail<T extends BaseEntity>(
this: ObjectType<T>,
id?:
| string
| number
| Date
| ObjectID
,
options?: FindOneOptions<T>,
): Promise<T>

Finds first entity that matches given options.

findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T>

Finds first entity that matches given options.

findOneOrFail<T extends BaseEntity>(
this: ObjectType<T>,
conditions?: FindConditions<T>,
options?: FindOneOptions<T>,
): Promise<T>

Finds first entity that matches given conditions.

getId<T extends BaseEntity>(this: ObjectType<T>, entity: T): any

Gets entity mixed id.

getRepository<T extends BaseEntity>(this: ObjectType<T>): Repository<T>

Gets current entity's Repository.

hasId(entity: BaseEntity): boolean

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

insert<T extends BaseEntity>(
this: ObjectType<T>,
entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],
options?: SaveOptions,
): 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<T extends BaseEntity>(
this: ObjectType<T>,
mergeIntoEntity: T,
...entityLikes: DeepPartial<T>[],
): T

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

preload<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): Promise<T | 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<T extends BaseEntity>(
this: ObjectType<T>,
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<T extends BaseEntity>(
this: ObjectType<T>,
entities: T[],
options?: RemoveOptions,
): Promise<T[]>

Removes a given entities from the database.

remove<T extends BaseEntity>(
this: ObjectType<T>,
entity: T,
options?: RemoveOptions,
): Promise<T>

Removes a given entity from the database.

save<T extends BaseEntity>(
this: ObjectType<T>,
entities: T[],
options?: SaveOptions,
): Promise<T[]>

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

save<T extends BaseEntity>(
this: ObjectType<T>,
entity: T,
options?: SaveOptions,
): Promise<T>

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

update<T extends BaseEntity>(
this: ObjectType<T>,
criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<T>
,
partialEntity: QueryDeepPartialEntity<T>,
options?: SaveOptions,
): 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.

useConnection(connection: Connection)

Sets connection to be used by entity.

Methods

hasId(): boolean

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

reload(): Promise<void>

Reloads entity data from the database.

remove(options?: RemoveOptions): Promise<this>

Removes current entity from the database.

save(options?: SaveOptions): Promise<this>

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

Static Properties

private
optional
usedConnection: Connection

Connection used in all static methods of the BaseEntity.

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.

Static Methods

clear<T extends BaseEntity>(this: ObjectType<T>): Promise<void>

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

count<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<number>

Counts entities that match given options.

count<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<number>

Counts entities that match given conditions.

create<T extends BaseEntity>(this: ObjectType<T>): T

Creates a new entity instance.

create<T extends BaseEntity>(this: ObjectType<T>, entityLikeArray: DeepPartial<T>[]): T

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<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): T

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<T extends BaseEntity>(this: ObjectType<T>, alias?: string): SelectQueryBuilder<T>

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

delete<T extends BaseEntity>(
this: ObjectType<T>,
criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<T>
,
options?: RemoveOptions,
): Promise<DeleteResult>

Deletes entities by a given criteria. Unlike remove 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<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<T[]>

Finds entities that match given options.

find<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<T[]>

Finds entities that match given conditions.

findAndCount<T extends BaseEntity>(this: ObjectType<T>, options?: FindManyOptions<T>): Promise<[T[], 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<T extends BaseEntity>(this: ObjectType<T>, conditions?: FindConditions<T>): Promise<[T[], number]>

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

findByIds<T extends BaseEntity>(
this: ObjectType<T>,
ids: any[],
options?: FindManyOptions<T>,
): Promise<T[]>

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

findByIds<T extends BaseEntity>(
this: ObjectType<T>,
ids: any[],
conditions?: FindConditions<T>,
): Promise<T[]>

Finds entities by ids. Optionally conditions can be applied.

findOne<T extends BaseEntity>(
this: ObjectType<T>,
id?:
| string
| number
| Date
| ObjectID
,
options?: FindOneOptions<T>,
): Promise<T | undefined>

Finds first entity that matches given options.

findOne<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T | undefined>

Finds first entity that matches given options.

findOne<T extends BaseEntity>(
this: ObjectType<T>,
conditions?: FindConditions<T>,
options?: FindOneOptions<T>,
): Promise<T | undefined>

Finds first entity that matches given conditions.

findOneOrFail<T extends BaseEntity>(
this: ObjectType<T>,
id?:
| string
| number
| Date
| ObjectID
,
options?: FindOneOptions<T>,
): Promise<T>

Finds first entity that matches given options.

findOneOrFail<T extends BaseEntity>(this: ObjectType<T>, options?: FindOneOptions<T>): Promise<T>

Finds first entity that matches given options.

findOneOrFail<T extends BaseEntity>(
this: ObjectType<T>,
conditions?: FindConditions<T>,
options?: FindOneOptions<T>,
): Promise<T>

Finds first entity that matches given conditions.

getId<T extends BaseEntity>(this: ObjectType<T>, entity: T): any

Gets entity mixed id.

getRepository<T extends BaseEntity>(this: ObjectType<T>): Repository<T>

Gets current entity's Repository.

hasId(entity: BaseEntity): boolean

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

insert<T extends BaseEntity>(
this: ObjectType<T>,
entity: QueryDeepPartialEntity<T> | QueryDeepPartialEntity<T>[],
options?: SaveOptions,
): 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<T extends BaseEntity>(
this: ObjectType<T>,
mergeIntoEntity: T,
...entityLikes: DeepPartial<T>[],
): T

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

preload<T extends BaseEntity>(this: ObjectType<T>, entityLike: DeepPartial<T>): Promise<T | 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<T extends BaseEntity>(
this: ObjectType<T>,
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<T extends BaseEntity>(
this: ObjectType<T>,
entities: T[],
options?: RemoveOptions,
): Promise<T[]>

Removes a given entities from the database.

remove<T extends BaseEntity>(
this: ObjectType<T>,
entity: T,
options?: RemoveOptions,
): Promise<T>

Removes a given entity from the database.

save<T extends BaseEntity>(
this: ObjectType<T>,
entities: T[],
options?: SaveOptions,
): Promise<T[]>

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

save<T extends BaseEntity>(
this: ObjectType<T>,
entity: T,
options?: SaveOptions,
): Promise<T>

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

update<T extends BaseEntity>(
this: ObjectType<T>,
criteria:
| string
| string[]
| number
| number[]
| Date
| Date[]
| ObjectID
| ObjectID[]
| FindConditions<T>
,
partialEntity: QueryDeepPartialEntity<T>,
options?: SaveOptions,
): 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.

useConnection(connection: Connection)

Sets connection to be used by entity.