Page Contents
Home > @loopback/repository > DefaultCrudRepository
DefaultCrudRepository class
Default implementation of CRUD repository using legacy juggler model and data source
Signature:
export declare class DefaultCrudRepository<T extends Entity, ID, Relations extends object = {}> implements EntityCrudRepository<T, ID, Relations>
Implements: EntityCrudRepository<T, ID, Relations>
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(entityClass, dataSource) | Constructor of DefaultCrudRepository |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
dataSource | juggler.DataSource | ||
entityClass | typeof Entity & { prototype: T; } | ||
inclusionResolvers | readonly |
Map<string, InclusionResolver<T, Entity>> | |
modelClass | juggler.PersistedModelClass |
Methods
Method | Modifiers | Description |
---|---|---|
_createBelongsToAccessorFor(relationName, targetRepositoryGetter) | protected |
|
_createHasManyRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
|
_createHasOneRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
|
_createReferencesManyAccessorFor(relationName, targetRepoGetter) | protected |
|
count(where, options) | ||
create(entity, options) | ||
createAll(entities, options) | ||
createBelongsToAccessorFor(relationName, targetRepositoryGetter) | protected |
Function to create a belongs to accessor |
createHasManyRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
Function to create a constrained relation repository factory |
createHasManyThroughRepositoryFactoryFor(relationName, targetRepositoryGetter, throughRepositoryGetter) | protected |
Function to create a constrained hasManyThrough relation repository factory |
createHasOneRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
Function to create a constrained hasOne relation repository factory |
createReferencesManyAccessorFor(relationName, targetRepoGetter) | protected |
Function to create a references many accessor |
definePersistedModel(entityClass) | protected |
Creates a legacy persisted model class, attaches it to the datasource and returns it. This method can be overridden in sub-classes to acess methods and properties in the generated model class. |
delete(entity, options) | ||
deleteAll(where, options) | ||
deleteById(id, options) | ||
ensurePersistable(entity, options) | protected |
Converts an entity object to a JSON object to check if it contains navigational property. Throws an error if entity contains navigational property. |
entityToData(entity, options) | protected |
<p>This function works as a persist hook. It converts an entity from the CRUD operations’ caller to a persistable data that can will be stored in the back-end database.</p><p>User can extend DefaultCrudRepository then override this function to execute custom persist hook.</p> |
execute(command, parameters, options) | <p>Execute a SQL command.</p><p>**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing SQL may lead to unexpected results, corrupted data, security vulnerabilities and other issues.</p> | |
execute(collectionName, command, parameters) | <p>Execute a MongoDB command.</p><p>**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing MongoDB commands may lead to unexpected results and other issues.</p> | |
execute(args) | <p>Execute a raw database command using a connector that’s not described by LoopBack’s execute API yet.</p><p>**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing database commands may lead to unexpected results and other issues.</p> |
|
exists(id, options) | ||
find(filter, options) | ||
findById(id, filter, options) | ||
findOne(filter, options) | ||
includeRelatedModels(entities, include, options) | protected |
Returns model instances that include related models of this repository that have a registered resolver. |
normalizeFilter(filter) | protected |
Removes juggler’s “include” filter as it does not apply to LoopBack 4 relations. |
registerInclusionResolver(relationName, resolver) | Register an inclusion resolver for the related model name. | |
replaceById(id, data, options) | ||
save(entity, options) | ||
toEntities(models) | protected |
|
toEntity(model) | protected |
|
update(entity, options) | ||
updateAll(data, where, options) | ||
updateById(id, data, options) |