Repository APIs
Repository
API
Repository
APImanager
- TheEntityManager
used by this repository.
metadata
- TheEntityMetadata
of the entity managed by this repository. Learn more about transactions in Entity Metadata.
queryRunner
- The query runner used byEntityManager
. Used only in transactional instances of EntityManager.
target
- The target entity class managed by this repository. Used only in transactional instances of EntityManager.
createQueryBuilder
- Creates a query builder use to build SQL queries. Learn more about QueryBuilder.
hasId
- Checks if the given entity's primary column property is defined.
getId
- Gets the primary column property values of the given entity. If 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 exists 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 an entity loaded from the database 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.
save
- Saves a given entity or array of entities. If the entity already exist in the database, it is updated. If the entity does not exist in the database, it is 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. Returns the saved entity/entities.
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). Returns the removed entity/entities.
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:
softDelete
andrestore
- Soft deleting and restoring a row by id
softRemove
andrecover
- This is alternative tosoftDelete
andrestore
.
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.
sum
- Returns the sum of a numeric field for all entities that matchFindOptionsWhere
.
average
- Returns the average of a numeric field for all entities that matchFindOptionsWhere
.
minimum
- Returns the minimum of a numeric field for all entities that matchFindOptionsWhere
.
maximum
- Returns the maximum of a numeric field for all entities that matchFindOptionsWhere
.
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.
query
- Executes a raw SQL query.
clear
- Clears all the data from the given table (truncates/drops it).
Additional Options
Optional SaveOptions
can be passed as parameter for save
.
data
- Additional data to be passed with persist method. This data can be used in subscribers then.listeners
: boolean - Indicates if listeners and subscribers are called for this operation. By default they are enabled, you can disable them by setting{ listeners: false }
in save/remove options.transaction
: boolean - By default transactions are enabled and all queries in persistence operation are wrapped into the transaction. You can disable this behaviour by setting{ transaction: false }
in the persistence options.chunk
: number - Breaks save execution into multiple groups of chunks. For example, if you want to save 100.000 objects but you have issues with saving them, you can break them into 10 groups of 10.000 objects (by setting{ chunk: 10000 }
) and save each group separately. This option is needed to perform very big insertions when you have issues with underlying driver parameter number limitation.reload
: boolean - Flag to determine whether the entity that is being persisted should be reloaded during the persistence operation. It will work only on databases which does not support RETURNING / OUTPUT statement. Enabled by default.
Example:
Optional RemoveOptions
can be passed as parameter for remove
and delete
.
data
- Additional data to be passed with remove method. This data can be used in subscribers then.listeners
: boolean - Indicates if listeners and subscribers are called for this operation. By default they are enabled, you can disable them by setting{ listeners: false }
in save/remove options.transaction
: boolean - By default transactions are enabled and all queries in persistence operation are wrapped into the transaction. You can disable this behaviour by setting{ transaction: false }
in the persistence options.chunk
: number - Breaks removal execution into multiple groups of chunks. For example, if you want to remove 100.000 objects but you have issues doing so, you can break them into 10 groups of 10.000 objects, by setting{ chunk: 10000 }
, and remove each group separately. This option is needed to perform very big deletions when you have issues with underlying driver parameter number limitation.
Example:
TreeRepository
API
TreeRepository
APIFor TreeRepository
API refer to the Tree Entities documentation.
MongoRepository
API
MongoRepository
APIFor MongoRepository
API refer to the MongoDB documentation.
Last updated