@loopback/docs
Version:
Documentation for LoopBack 4
58 lines (40 loc) • 1.43 kB
Markdown
lang: en
title: 'API docs: repository.repository_1'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.repository.repository_1.html
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/repository](./repository.md) > [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 | <code>string | typeof Entity</code> | Name/class of the model |
| dataSource | <code>string | juggler.DataSource</code> | Name/instance of the dataSource |
<b>Returns:</b>
`RepositoryDecorator`
## 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
>,
) {}
// ...
}
```