Page Contents

Home > @loopback/repository > DefaultCrudRepository

DefaultCrudRepository class

Default implementation of CRUD repository using legacy juggler model and data source


export declare class DefaultCrudRepository<T extends Entity, ID, Relations extends object = {}> implements EntityCrudRepository<T, ID, Relations> 

Implements: EntityCrudRepository<T, ID, Relations>


Constructor Modifiers Description
(constructor)(entityClass, dataSource)   Constructor of DefaultCrudRepository


Property Modifiers Type Description
dataSource   juggler.DataSource  
entityClass   typeof Entity & { prototype: T; }  
inclusionResolvers   Map<string, InclusionResolver<T, Entity>>  
modelClass   juggler.PersistedModelClass  


Method Modifiers Description
_createBelongsToAccessorFor(relationName, targetRepoGetter)    
_createHasManyRepositoryFactoryFor(relationName, targetRepoGetter)    
_createHasOneRepositoryFactoryFor(relationName, targetRepoGetter)    
count(where, options)    
create(entity, options)    
createAll(entities, options)    
createBelongsToAccessorFor(relationName, targetRepoGetter)   Function to create a belongs to accessor
createHasManyRepositoryFactoryFor(relationName, targetRepoGetter)   Function to create a constrained relation repository factory
createHasManyThroughRepositoryFactoryFor(relationName, targetRepoGetter, throughRepoGetter)   Function to create a constrained hasManyThrough relation repository factory
createHasOneRepositoryFactoryFor(relationName, targetRepoGetter)   Function to create a constrained hasOne relation repository factory
definePersistedModel(entityClass)   Creates a legacy persisted model class, attaches it to the datasource and returns it. This method can be overriden 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)   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)   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.User can extend DefaultCrudRepository then override this function to execute custom persist hook.
execute(command, parameters, options)    
exists(id, options)    
find(filter, options)    
findById(id, filter, options)    
findOne(filter, options)    
includeRelatedModels(entities, include, options)   Returns model instances that include related models of this repository that have a registered resolver.
normalizeFilter(filter)   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)    
update(entity, options)    
updateAll(data, where, options)    
updateById(id, data, options)