Entity Manager API
EntityManager API
connection
- The connection used byEntityManager
.
queryRunner
- The query runner used byEntityManager
.Used only in transactional instances of EntityManager.
transaction
- Provides a transaction where multiple database requests will be executed in a single database transaction.Learn more Transactions.
query
- Executes a raw SQL query.
createQueryBuilder
- Creates a query builder use to build SQL queries.Learn more about QueryBuilder.
hasId
- Checks if given entity has its primary column property defined.
getId
- Gets given entity's primary column property value.If the entity has composite primary keys then the returned value will be an object with names and values of primary columns.
create
- Creates a new instance ofUser
. Optionally accepts an object literal with user propertieswhich will be written into newly created user object.
merge
- Merges multiple entities into a single entity.
preload
- Creates a new entity from the given plain javascript object. If the entity already exist in the database, thenit loads it (and everything related to it), replaces all values with the new ones from the given object,
and returns the new entity. The new entity is actually loaded from the database entity with all properties
replaced from the new object.
save
- Saves a given entity or array of entities.If the entity already exists in the database, then it's updated.
If the entity does not exist in the database yet, it's inserted.
It saves all given entities in a single transaction (in the case of entity manager is not transactional).
Also supports partial updating since all undefined properties are skipped. In order to make a value
NULL
, you must manually set the property to equalnull
.
remove
- Removes a given entity or array of entities.It removes all given entities in a single transaction (in the case of entity, manager is not transactional).
insert
- Inserts a new entity, or array of entities.
update
- Partially updates entity by a given update options or entity id.
delete
- Deletes entities by entity id, ids or given conditions:
count
- Counts entities that match given options. Useful for pagination.
increment
- Increments some column by provided value of entities that match given options.
decrement
- Decrements some column by provided value that match given options.find
- Finds entities that match given options.
findAndCount
- Finds entities that match given find options.Also counts all entities that match given conditions,
but ignores pagination settings (from and take options).
findByIds
- Finds multiple entities by id.
findOne
- Finds the first entity that matches some id or find options.
findOneOrFail
- Finds the first entity that matches some id or find options.Rejects the returned promise if nothing matches.
clear
- Clears all the data from the given table (truncates/drops it).
getRepository
- GetsRepository
to perform operations on a specific entity.Learn more about Repositories.
getTreeRepository
- GetsTreeRepository
to perform operations on a specific entity.Learn more about Repositories.
getMongoRepository
- GetsMongoRepository
to perform operations on a specific entity.Learn more about MongoDB.
getCustomRepository
- Gets custom entity repository.Learn more about Custom repositories.
release
- Releases query runner of an entity manager.Used only when query runner was created and managed manually.
Last updated
Was this helpful?