Page Contents
Home > @loopback/repository > defineRepositoryClass
defineRepositoryClass() function
Create (define) a repository class for the given model.
See also defineCrudRepositoryClass
and defineKeyValueRepositoryClass
for convenience wrappers providing repository class factory for the default CRUD and KeyValue implementations.
**❗️IMPORTANT: The compiler (TypeScript 3.8) is not able to correctly infer generic arguments M
and R
from the class constructors provided in function arguments. You must always provide both M and R types explicitly.**
Signature:
export declare function defineRepositoryClass<M extends typeof Model, R extends Repository<PrototypeOf<M>>>(modelClass: M, baseRepositoryClass: BaseRepositoryClass<M, R>): ModelRepositoryClass<PrototypeOf<M>, R>;
Parameters
Parameter | Type | Description |
---|---|---|
modelClass | M | A model class such as Address . |
baseRepositoryClass | BaseRepositoryClass<M, R> | Repository implementation to use as the base, e.g. DefaultCrudRepository . |
Returns:
ModelRepositoryClass<PrototypeOf<M>, R>
Example
const AddressRepository = defineRepositoryClass<
typeof Address,
DefaultEntityCrudRepository<
Address,
typeof Address.prototype.id,
AddressRelations
>,
>(Address, DefaultCrudRepository);