UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

58 lines (41 loc) 1.57 kB
--- lang: en title: 'API docs: repository.repository_1' 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.repository_1.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [repository](./repository.repository_1.md) ## repository() function Decorator for DefaultCrudRepository generation and injection on properties or method arguments based on the given model and dataSource (or their names) <b>Signature:</b> ```typescript export declare function repository(model: string | typeof Entity, dataSource: string | juggler.DataSource): RepositoryDecorator; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | model | string \| typeof [Entity](./repository.entity.md) | Name/class of the model | | dataSource | string \| juggler.DataSource | Name/instance of the dataSource | <b>Returns:</b> [RepositoryDecorator](./repository.repositorydecorator.md) ## Example ```ts class CustomerController { @repository('Customer', 'mySqlDataSource') public custRepo: DefaultCrudRepository< Customer, typeof Customer.prototype.id >; constructor( @repository(Product, mySqlDataSource) public prodRepo: DefaultCrudRepository< Product, typeof Product.prototype.id >, ) {} // ... } ```