---
lang: en
title: 'API docs: repository.defaultcrudrepository'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
permalink: /doc/en/lb4/apidocs.repository.defaultcrudrepository.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [DefaultCrudRepository](./repository.defaultcrudrepository.md)

## DefaultCrudRepository class

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

<b>Signature:</b>

```typescript
export declare class DefaultCrudRepository<T extends Entity, ID, Relations extends object = {}> implements EntityCrudRepository<T, ID, Relations> 
```
<b>Implements:</b> [EntityCrudRepository](./repository.entitycrudrepository.md)

## Constructors

|  Constructor | Modifiers | Description |
|  --- | --- | --- |
|  [(constructor)(entityClass, dataSource)](./repository.defaultcrudrepository._constructor_.md) |  | Constructor of DefaultCrudRepository |

## Properties

|  Property | Modifiers | Type | Description |
|  --- | --- | --- | --- |
|  [dataSource](./repository.defaultcrudrepository.datasource.md) |  | juggler.DataSource |  |
|  [entityClass](./repository.defaultcrudrepository.entityclass.md) |  | typeof [Entity](./repository.entity.md) &amp; { prototype: T; } |  |
|  [inclusionResolvers](./repository.defaultcrudrepository.inclusionresolvers.md) |  | Map&lt;string, [InclusionResolver](./repository.inclusionresolver.md)<!-- -->&lt;T, [Entity](./repository.entity.md)<!-- -->&gt;&gt; |  |
|  [modelClass](./repository.defaultcrudrepository.modelclass.md) |  | juggler.PersistedModelClass |  |

## Methods

|  Method | Modifiers | Description |
|  --- | --- | --- |
|  [\_createBelongsToAccessorFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository._createbelongstoaccessorfor.md) |  |  |
|  [\_createHasManyRepositoryFactoryFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository._createhasmanyrepositoryfactoryfor.md) |  |  |
|  [\_createHasOneRepositoryFactoryFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository._createhasonerepositoryfactoryfor.md) |  |  |
|  [\_createReferencesManyAccessorFor(relationName, targetRepoGetter)](./repository.defaultcrudrepository._createreferencesmanyaccessorfor.md) |  |  |
|  [count(where, options)](./repository.defaultcrudrepository.count.md) |  |  |
|  [create(entity, options)](./repository.defaultcrudrepository.create.md) |  |  |
|  [createAll(entities, options)](./repository.defaultcrudrepository.createall.md) |  |  |
|  [createBelongsToAccessorFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository.createbelongstoaccessorfor.md) |  | Function to create a belongs to accessor |
|  [createHasManyRepositoryFactoryFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository.createhasmanyrepositoryfactoryfor.md) |  | Function to create a constrained relation repository factory |
|  [createHasManyThroughRepositoryFactoryFor(relationName, targetRepositoryGetter, throughRepositoryGetter)](./repository.defaultcrudrepository.createhasmanythroughrepositoryfactoryfor.md) |  | Function to create a constrained hasManyThrough relation repository factory |
|  [createHasOneRepositoryFactoryFor(relationName, targetRepositoryGetter)](./repository.defaultcrudrepository.createhasonerepositoryfactoryfor.md) |  | Function to create a constrained hasOne relation repository factory |
|  [createReferencesManyAccessorFor(relationName, targetRepoGetter)](./repository.defaultcrudrepository.createreferencesmanyaccessorfor.md) |  | Function to create a references many accessor |
|  [definePersistedModel(entityClass)](./repository.defaultcrudrepository.definepersistedmodel.md) |  | 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)](./repository.defaultcrudrepository.delete.md) |  |  |
|  [deleteAll(where, options)](./repository.defaultcrudrepository.deleteall.md) |  |  |
|  [deleteById(id, options)](./repository.defaultcrudrepository.deletebyid.md) |  |  |
|  [ensurePersistable(entity, options)](./repository.defaultcrudrepository.ensurepersistable.md) |  | Converts an entity object to a JSON object to check if it contains navigational property. Throws an error if <code>entity</code> contains navigational property. |
|  [entityToData(entity, options)](./repository.defaultcrudrepository.entitytodata.md) |  | 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 <code>DefaultCrudRepository</code> then override this function to execute custom persist hook. |
|  [execute(command, parameters, options)](./repository.defaultcrudrepository.execute.md) |  | 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)](./repository.defaultcrudrepository.execute_1.md) |  | 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)](./repository.defaultcrudrepository.execute_2.md) |  | Execute a raw database command using a connector that's not described by LoopBack's <code>execute</code> 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)](./repository.defaultcrudrepository.exists.md) |  |  |
|  [find(filter, options)](./repository.defaultcrudrepository.find.md) |  |  |
|  [findById(id, filter, options)](./repository.defaultcrudrepository.findbyid.md) |  |  |
|  [findOne(filter, options)](./repository.defaultcrudrepository.findone.md) |  |  |
|  [includeRelatedModels(entities, include, options)](./repository.defaultcrudrepository.includerelatedmodels.md) |  | Returns model instances that include related models of this repository that have a registered resolver. |
|  [normalizeFilter(filter)](./repository.defaultcrudrepository.normalizefilter.md) |  | Removes juggler's "include" filter as it does not apply to LoopBack 4 relations. |
|  [registerInclusionResolver(relationName, resolver)](./repository.defaultcrudrepository.registerinclusionresolver.md) |  | Register an inclusion resolver for the related model name. |
|  [replaceById(id, data, options)](./repository.defaultcrudrepository.replacebyid.md) |  |  |
|  [save(entity, options)](./repository.defaultcrudrepository.save.md) |  |  |
|  [toEntities(models)](./repository.defaultcrudrepository.toentities.md) |  |  |
|  [toEntity(model)](./repository.defaultcrudrepository.toentity.md) |  |  |
|  [update(entity, options)](./repository.defaultcrudrepository.update.md) |  |  |
|  [updateAll(data, where, options)](./repository.defaultcrudrepository.updateall.md) |  |  |
|  [updateById(id, data, options)](./repository.defaultcrudrepository.updatebyid.md) |  |  |


