Class: EntityRepository<T>
#
Type parametersName | Type |
---|---|
T | AnyEntity<T> |
#
Hierarchy- EntityRepository
#
Constructors#
constructor+ new EntityRepository(_em
: EntityManager, entityName
: EntityName<T>): EntityRepository
Defined in packages/core/src/entity/EntityRepository.ts:7
#
Parameters:Name | Type |
---|---|
_em | EntityManager |
entityName | EntityName<T> |
Returns: EntityRepository
#
Properties#
_em• Protected
Readonly
_em: EntityManager
Defined in packages/core/src/entity/EntityRepository.ts:9
#
entityName• Protected
Readonly
entityName: EntityName<T>
Defined in packages/core/src/entity/EntityRepository.ts:10
#
Accessors#
em• Protected
get em(): EntityManager
Defined in packages/core/src/entity/EntityRepository.ts:278
Returns: EntityManager
#
Methods#
assignâ–¸ assign(entity
: T, data
: EntityData<T>): T
Defined in packages/core/src/entity/EntityRepository.ts:259
Shortcut for wrap(entity).assign(data, { em })
#
Parameters:Name | Type |
---|---|
entity | T |
data | EntityData<T> |
Returns: T
#
canPopulateâ–¸ canPopulate(property
: string): boolean
Defined in packages/core/src/entity/EntityRepository.ts:223
Checks whether given property can be populated on the entity.
#
Parameters:Name | Type |
---|---|
property | string |
Returns: boolean
#
countâ–¸ count(where?
: FilterQuery<T>, options?
: CountOptions<T>): Promise<number>
Defined in packages/core/src/entity/EntityRepository.ts:274
Returns total number of entities matching your where
query.
#
Parameters:Name | Type | Default value |
---|---|---|
where | FilterQuery<T> | {} |
options | CountOptions<T> | {} |
Returns: Promise<number>
#
createâ–¸ create<P>(data
: EntityData<T>): New<T, P>
Defined in packages/core/src/entity/EntityRepository.ts:252
Creates new instance of given entity and populates it with given data
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | string[] |
#
Parameters:Name | Type |
---|---|
data | EntityData<T> |
Returns: New<T, P>
#
findâ–¸ find<P>(where
: FilterQuery<T>, options?
: FindOptions<T, P>): Promise<Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:81
Finds all entities matching your where
query. You can pass additional options via the options
parameter.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
options? | FindOptions<T, P> |
Returns: Promise<Loaded<T, P>[]>
â–¸ find<P>(where
: FilterQuery<T>, populate?
: P, orderBy?
: QueryOrderMap, limit?
: number, offset?
: number): Promise<Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:86
Finds all entities matching your where
query.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | P |
orderBy? | QueryOrderMap |
limit? | number |
offset? | number |
Returns: Promise<Loaded<T, P>[]>
#
findAllâ–¸ findAll<P>(options?
: FindOptions<T, P>): Promise<Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:118
Finds all entities of given type. You can pass additional options via the options
parameter.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
options? | FindOptions<T, P> |
Returns: Promise<Loaded<T, P>[]>
â–¸ findAll<P>(populate?
: P, orderBy?
: QueryOrderMap, limit?
: number, offset?
: number): Promise<Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:123
Finds all entities of given type.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
populate? | P |
orderBy? | QueryOrderMap |
limit? | number |
offset? | number |
Returns: Promise<Loaded<T, P>[]>
#
findAndCountâ–¸ findAndCount<P>(where
: FilterQuery<T>, options?
: FindOptions<T>): Promise<[Loaded<T, P>[], number]>
Defined in packages/core/src/entity/EntityRepository.ts:99
Calls em.find()
and em.count()
with the same arguments (where applicable) and returns the results as tuple
where first element is the array of entities and the second is the count.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
options? | FindOptions<T> |
Returns: Promise<[Loaded<T, P>[], number]>
â–¸ findAndCount<P>(where
: FilterQuery<T>, populate?
: P, orderBy?
: QueryOrderMap, limit?
: number, offset?
: number): Promise<[Loaded<T, P>[], number]>
Defined in packages/core/src/entity/EntityRepository.ts:105
Calls em.find()
and em.count()
with the same arguments (where applicable) and returns the results as tuple
where first element is the array of entities and the second is the count.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | P |
orderBy? | QueryOrderMap |
limit? | number |
offset? | number |
Returns: Promise<[Loaded<T, P>[], number]>
#
findOneâ–¸ findOne<P>(where
: FilterQuery<T>, populate?
: P, orderBy?
: QueryOrderMap): Promise<Loaded<T, P> | null>
Defined in packages/core/src/entity/EntityRepository.ts:41
Finds first entity matching your where
query.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | P |
orderBy? | QueryOrderMap |
Returns: Promise<Loaded<T, P> | null>
â–¸ findOne<P>(where
: FilterQuery<T>, populate?
: FindOneOptions<T, P>, orderBy?
: QueryOrderMap): Promise<Loaded<T, P> | null>
Defined in packages/core/src/entity/EntityRepository.ts:46
Finds first entity matching your where
query.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | FindOneOptions<T, P> |
orderBy? | QueryOrderMap |
Returns: Promise<Loaded<T, P> | null>
#
findOneOrFailâ–¸ findOneOrFail<P>(where
: FilterQuery<T>, populate?
: P, orderBy?
: QueryOrderMap): Promise<Loaded<T, P>>
Defined in packages/core/src/entity/EntityRepository.ts:60
Finds first entity matching your where
query. If nothing found, it will throw an error.
You can override the factory for creating this method via options.failHandler
locally
or via Configuration.findOneOrFailHandler
globally.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | P |
orderBy? | QueryOrderMap |
Returns: Promise<Loaded<T, P>>
â–¸ findOneOrFail<P>(where
: FilterQuery<T>, populate?
: FindOneOrFailOptions<T, P>, orderBy?
: QueryOrderMap): Promise<Loaded<T, P>>
Defined in packages/core/src/entity/EntityRepository.ts:67
Finds first entity matching your where
query. If nothing found, it will throw an error.
You can override the factory for creating this method via options.failHandler
locally
or via Configuration.findOneOrFailHandler
globally.
#
Type parameters:Name | Type | Default |
---|---|---|
P | Populate<T> | any |
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
populate? | FindOneOrFailOptions<T, P> |
orderBy? | QueryOrderMap |
Returns: Promise<Loaded<T, P>>
#
flushâ–¸ flush(): Promise<void>
Defined in packages/core/src/entity/EntityRepository.ts:166
Flushes all changes to objects that have been queued up to now to the database.
This effectively synchronizes the in-memory state of managed objects with the database.
This method is a shortcut for em.flush()
, in other words, it will flush the whole UoW,
not just entities registered via this particular repository.
Returns: Promise<void>
#
getReferenceâ–¸ getReference<PK>(id
: Primary<T>, wrapped
: true): IdentifiedReference<T, PK>
Defined in packages/core/src/entity/EntityRepository.ts:201
Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
#
Type parameters:Name | Type |
---|---|
PK | keyof T |
#
Parameters:Name | Type |
---|---|
id | Primary<T> |
wrapped | true |
Returns: IdentifiedReference<T, PK>
â–¸ getReference<PK>(id
: Primary<T>): T
Defined in packages/core/src/entity/EntityRepository.ts:206
Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
#
Type parameters:Name | Type | Default |
---|---|---|
PK | keyof T | keyof T |
#
Parameters:Name | Type |
---|---|
id | Primary<T> |
Returns: T
â–¸ getReference<PK>(id
: Primary<T>, wrapped
: false): T
Defined in packages/core/src/entity/EntityRepository.ts:211
Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
#
Type parameters:Name | Type | Default |
---|---|---|
PK | keyof T | keyof T |
#
Parameters:Name | Type |
---|---|
id | Primary<T> |
wrapped | false |
Returns: T
#
mapâ–¸ map(result
: EntityData<T>): T
Defined in packages/core/src/entity/EntityRepository.ts:194
Maps raw database result to an entity and merges it to this EntityManager.
#
Parameters:Name | Type |
---|---|
result | EntityData<T> |
Returns: T
#
mergeâ–¸ merge(data
: T | EntityData<T>, refresh?
: boolean, convertCustomTypes?
: boolean): T
Defined in packages/core/src/entity/EntityRepository.ts:267
Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities via second parameter. By default it will return already loaded entities without modifying them.
#
Parameters:Name | Type |
---|---|
data | T | EntityData<T> |
refresh? | boolean |
convertCustomTypes? | boolean |
Returns: T
#
nativeDeleteâ–¸ nativeDelete(where
: FilterQuery<T> | any): Promise<number>
Defined in packages/core/src/entity/EntityRepository.ts:187
Fires native delete query. Calling this has no side effects on the context (identity map).
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> | any |
Returns: Promise<number>
#
nativeInsertâ–¸ nativeInsert(data
: EntityData<T>): Promise<Primary<T>>
Defined in packages/core/src/entity/EntityRepository.ts:173
Fires native insert query. Calling this has no side effects on the context (identity map).
#
Parameters:Name | Type |
---|---|
data | EntityData<T> |
Returns: Promise<Primary<T>>
#
nativeUpdateâ–¸ nativeUpdate(where
: FilterQuery<T>, data
: EntityData<T>): Promise<number>
Defined in packages/core/src/entity/EntityRepository.ts:180
Fires native update query. Calling this has no side effects on the context (identity map).
#
Parameters:Name | Type |
---|---|
where | FilterQuery<T> |
data | EntityData<T> |
Returns: Promise<number>
#
persistâ–¸ persist(entity
: AnyEntity | AnyEntity[]): EntityManager
Defined in packages/core/src/entity/EntityRepository.ts:16
Tells the EntityManager to make an instance managed and persistent. The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
#
Parameters:Name | Type |
---|---|
entity | AnyEntity | AnyEntity[] |
Returns: EntityManager
#
persistAndFlushâ–¸ persistAndFlush(entity
: AnyEntity | AnyEntity[]): Promise<void>
Defined in packages/core/src/entity/EntityRepository.ts:24
Persists your entity immediately, flushing all not yet persisted changes to the database too.
Equivalent to em.persist(e).flush()
.
#
Parameters:Name | Type |
---|---|
entity | AnyEntity | AnyEntity[] |
Returns: Promise<void>
#
persistLaterâ–¸ persistLater(entity
: AnyEntity | AnyEntity[]): void
Defined in packages/core/src/entity/EntityRepository.ts:34
Tells the EntityManager to make an instance managed and persistent. The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
deprecated
use persist()
#
Parameters:Name | Type |
---|---|
entity | AnyEntity | AnyEntity[] |
Returns: void
#
populateâ–¸ populate<P>(entities
: T, populate
: P, where?
: FilterQuery<T>, orderBy?
: QueryOrderMap, refresh?
: boolean, validate?
: boolean): Promise<Loaded<T, P>>
Defined in packages/core/src/entity/EntityRepository.ts:230
Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.
#
Type parameters:Name | Type |
---|---|
P | string | keyof T | Populate<T> |
#
Parameters:Name | Type |
---|---|
entities | T |
populate | P |
where? | FilterQuery<T> |
orderBy? | QueryOrderMap |
refresh? | boolean |
validate? | boolean |
Returns: Promise<Loaded<T, P>>
â–¸ populate<P>(entities
: T[], populate
: P, where?
: FilterQuery<T>, orderBy?
: QueryOrderMap, refresh?
: boolean, validate?
: boolean): Promise<Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:235
Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.
#
Type parameters:Name | Type |
---|---|
P | string | keyof T | Populate<T> |
#
Parameters:Name | Type |
---|---|
entities | T[] |
populate | P |
where? | FilterQuery<T> |
orderBy? | QueryOrderMap |
refresh? | boolean |
validate? | boolean |
Returns: Promise<Loaded<T, P>[]>
â–¸ populate<P>(entities
: T | T[], populate
: P, where?
: FilterQuery<T>, orderBy?
: QueryOrderMap, refresh?
: boolean, validate?
: boolean): Promise<Loaded<T, P> | Loaded<T, P>[]>
Defined in packages/core/src/entity/EntityRepository.ts:240
Loads specified relations in batch. This will execute one query for each relation, that will populate it on all of the specified entities.
#
Type parameters:Name | Type |
---|---|
P | string | keyof T | Populate<T> |
#
Parameters:Name | Type |
---|---|
entities | T | T[] |
populate | P |
where? | FilterQuery<T> |
orderBy? | QueryOrderMap |
refresh? | boolean |
validate? | boolean |
Returns: Promise<Loaded<T, P> | Loaded<T, P>[]>
#
removeâ–¸ remove(entity
: AnyEntity): EntityManager
Defined in packages/core/src/entity/EntityRepository.ts:138
Marks entity for removal. A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
To remove entities by condition, use em.nativeDelete()
.
#
Parameters:Name | Type |
---|---|
entity | AnyEntity |
Returns: EntityManager
#
removeAndFlushâ–¸ removeAndFlush(entity
: AnyEntity): Promise<void>
Defined in packages/core/src/entity/EntityRepository.ts:146
Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
Equivalent to em.remove(e).flush()
#
Parameters:Name | Type |
---|---|
entity | AnyEntity |
Returns: Promise<void>
#
removeLaterâ–¸ removeLater(entity
: AnyEntity): void
Defined in packages/core/src/entity/EntityRepository.ts:156
Marks entity for removal. A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
deprecated
use remove()
#
Parameters:Name | Type |
---|---|
entity | AnyEntity |
Returns: void