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   Map<string, InclusionResolver<T, Entity>>  
modelClass   juggler.PersistedModelClass  

Methods

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)   Execute a SQL command.**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.
execute(collectionName, command, parameters)   Execute a MongoDB command.**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.
execute(args)   Execute a raw database command using a connector that’s not described by LoopBack’s execute API yet.**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.
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)    
toEntities(models)    
toEntity(model)    
update(entity, options)    
updateAll(data, where, options)    
updateById(id, data, options)