EntityManager API
dataSource
- The DataSource 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 properties which 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, then it 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 valueNULL
, 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.
upsert
- Inserts a new entity or array of entities unless they already exist in which case they are updated instead. Supported by AuroraDataApi, Cockroach, Mysql, Postgres, and Sqlite database drivers.
delete
- Deletes entities by entity id, ids or given conditions:
increment
- Increments some column by provided value of entities that match given options.
decrement
- Decrements some column by provided value that match given options.
exists
- Check whether any entity exists that matchesFindOptions
.
existsBy
- Checks whether any entity exists that matchesFindOptionsWhere
.
count
- Counts entities that matchFindOptions
. Useful for pagination.
countBy
- Counts entities that matchFindOptionsWhere
. Useful for pagination.
find
- Finds entities that match givenFindOptions
.
findBy
- Finds entities that match givenFindWhereOptions
.
findAndCount
- Finds entities that match givenFindOptions
. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).
findAndCountBy
- Finds entities that match givenFindOptionsWhere
. Also counts all entities that match given conditions, but ignores pagination settings (from and take options).
findOne
- Finds the first entity that matches givenFindOptions
.
findOneBy
- Finds the first entity that matches givenFindOptionsWhere
.
findOneOrFail
- Finds the first entity that matches some id or find options. Rejects the returned promise if nothing matches.
findOneByOrFail
- Finds the first entity that matches givenFindOptions
. 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.
withRepository
- Gets custom repository instance used in a transaction. 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