Entity manager supposed to work with any entity, automatically find its repository and call its methods,
whatever entity type are you passing.
Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms.
https://stackoverflow.com/a/5972738/925151
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
Returns
Promise
<
void
>
count
count<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, options
?:
FindManyOptions
<
Entity
>
)
:
Promise
<
number
>
count<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, conditions
?:
FindConditions
<
Entity
>
)
:
Promise
<
number
>
create<Entity>
(
entityClass
:
ObjectType
<
Entity
>
)
:
Entity
create<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, plainObject
:
DeepPartial
<
Entity
>
)
:
Entity
create<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, plainObjects
:
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.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
plainObject:
DeepPartial
<
Entity
>
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.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
plainObjects:
DeepPartial
<
Entity
>
[]
Returns
Entity
[]
create
Query
Builder
create
Query
Builder<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
Function
|
string
, alias
:
string
, queryRunner
?:
QueryRunner
)
:
SelectQueryBuilder
<
Entity
>
create
Query
Builder
(
queryRunner
?:
QueryRunner
)
:
SelectQueryBuilder
<
any
>
Deletes entities by a given condition(s).
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.
Condition(s) cannot be empty.
Type parameters
Entity
Parameters
targetOrEntity:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
criteria:
string
|
string
[]
|
number
|
number
[]
|
Date
|
Date
[]
|
ObjectID
|
ObjectID
[]
|
FindConditions
<
Entity
>
find<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, options
?:
FindManyOptions
<
Entity
>
)
:
Promise
<
Entity
[]
>
find<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, conditions
?:
FindConditions
<
Entity
>
)
:
Promise
<
Entity
[]
>
find
And
Count
find
And
Count<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, options
?:
FindManyOptions
<
Entity
>
)
:
Promise
<
[
Entity
[]
,
number
]
>
find
And
Count<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, 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).
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
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).
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
Optional
conditions:
FindConditions
<
Entity
>
Returns
Promise
<
[
Entity
[]
,
number
]
>
find
ByIds
find
ByIds<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, ids
:
any
[]
, options
?:
FindManyOptions
<
Entity
>
)
:
Promise
<
Entity
[]
>
find
ByIds<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, ids
:
any
[]
, conditions
?:
FindConditions
<
Entity
>
)
:
Promise
<
Entity
[]
>
find
One
find
One<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, id
?:
string
|
number
|
Date
|
ObjectID
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
|
undefined
>
find
One<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
|
undefined
>
find
One<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, conditions
?:
FindConditions
<
Entity
>
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
|
undefined
>
find
One
OrFail
find
One
OrFail<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, id
?:
string
|
number
|
Date
|
ObjectID
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
>
find
One
OrFail<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
>
find
One
OrFail<Entity>
(
entityClass
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, conditions
?:
FindConditions
<
Entity
>
, options
?:
FindOneOptions
<
Entity
>
)
:
Promise
<
Entity
>
Finds first entity that matches given find options or rejects the returned promise on error.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
Optional
id:
string
|
number
|
Date
|
ObjectID
Optional
options:
FindOneOptions
<
Entity
>
Returns
Promise
<
Entity
>
Finds first entity that matches given find options or rejects the returned promise on error.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
Optional
options:
FindOneOptions
<
Entity
>
Returns
Promise
<
Entity
>
Finds first entity that matches given conditions or rejects the returned promise on error.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
Optional
conditions:
FindConditions
<
Entity
>
Optional
options:
FindOneOptions
<
Entity
>
Returns
Promise
<
Entity
>
Gets repository for the given entity class or name.
If single database connection mode is used, then repository is obtained from the
repository aggregator, where each repository is individually created for this entity manager.
When single database connection is not used, repository is being obtained from the connection.
Type parameters
Entity
Parameters
Gets tree repository for the given entity class or name.
If single database connection mode is used, then repository is obtained from the
repository aggregator, where each repository is individually created for this entity manager.
When single database connection is not used, repository is being obtained from the connection.
Type parameters
Entity
Parameters
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.
You can execute bulk inserts using this method.
Type parameters
Entity
Parameters
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.
Type parameters
Entity
Parameters
entityClass:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
entityLike:
DeepPartial
<
Entity
>
Returns
Promise
<
Entity
|
undefined
>
Releases all resources used by entity manager.
This is used when entity manager is created with a single query runner,
and this single query runner needs to be released after job with entity manager is done.
Returns
Promise
<
void
>
remove<Entity>
(
entity
:
Entity
, options
?:
RemoveOptions
)
:
Promise
<
Entity
>
remove<Entity>
(
targetOrEntity
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, entity
:
Entity
, options
?:
RemoveOptions
)
:
Promise
<
Entity
>
remove<Entity>
(
entity
:
Entity
[]
, options
?:
RemoveOptions
)
:
Promise
<
Entity
>
remove<Entity>
(
targetOrEntity
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, entity
:
Entity
[]
, options
?:
RemoveOptions
)
:
Promise
<
Entity
[]
>
save<Entity>
(
entities
:
Entity
[]
, options
?:
SaveOptions
)
:
Promise
<
Entity
[]
>
save<Entity>
(
entity
:
Entity
, options
?:
SaveOptions
)
:
Promise
<
Entity
>
save<Entity, T>
(
targetOrEntity
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, entities
:
T
[]
, options
?:
SaveOptions
)
:
Promise
<
T
[]
>
save<Entity, T>
(
targetOrEntity
:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
, entity
:
T
, options
?:
SaveOptions
)
:
Promise
<
T
>
Saves all given entities in the database.
If entities do not exist in the database then inserts, otherwise updates.
Type parameters
Entity
Parameters
entities:
Entity
[]
Returns
Promise
<
Entity
[]
>
Saves all given entities in the database.
If entities do not exist in the database then inserts, otherwise updates.
Type parameters
Entity
Parameters
entity:
Entity
Returns
Promise
<
Entity
>
Saves all given entities in the database.
If entities do not exist in the database then inserts, otherwise updates.
Type parameters
Entity
Parameters
targetOrEntity:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
entities:
T
[]
Returns
Promise
<
T
[]
>
Saves all given entities in the database.
If entities do not exist in the database then inserts, otherwise updates.
Type parameters
Entity
Parameters
targetOrEntity:
ObjectType
<
Entity
>
|
EntitySchema
<
Entity
>
|
string
entity:
T
Returns
Promise
<
T
>
Wraps given function execution (and all operations made there) in a transaction.
All database operations must be executed using provided entity manager.
Type parameters
Parameters
runInTransaction:
function
(
entityManger
:
EntityManager
)
:
Promise
<
T
>
Parameters
Returns
Promise
<
T
>
Updates entity partially. Entity can be found by a given condition(s).
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.
Condition(s) cannot be empty.
Type parameters
Entity
Parameters
criteria:
string
|
string
[]
|
number
|
number
[]
|
Date
|
Date
[]
|
ObjectID
|
ObjectID
[]
|
FindConditions
<
Entity
>
partialEntity:
DeepPartial
<
Entity
>