Page Contents

Home > @loopback/repository > CrudRepositoryImpl

CrudRepositoryImpl class

Repository implementation

Signature:

export declare class CrudRepositoryImpl<T extends Entity, ID> implements EntityCrudRepository<T, ID> 

Constructors

Constructor Modifiers Description
(constructor)(dataSource, entityClass)   Constructs a new instance of the CrudRepositoryImpl class

Properties

Property Modifiers Type Description
dataSource   DataSource  
entityClass   typeof Entity & {
prototype: T;
}
 

Methods

Method Modifiers Description
count(where, options)    
create(entity, options)    
createAll(entities, options)    
delete(entity, options)    
deleteAll(where, options)    
deleteById(id, options)    
execute(command, parameters, options)    
exists(id, options)    
find(filter, options)    
findById(id, filter, options)    
replaceById(id, data, options)    
save(entity, options)    
update(entity, options)    
updateAll(data, where, options)    
updateById(id, data, options)    

Example

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}