Page Contents
Home > @loopback/repository > repository
repository() function
Decorator for DefaultCrudRepository generation and injection on properties or method arguments based on the given model and dataSource (or their names)
Signature:
export declare function repository(model: string | typeof Entity, dataSource: string | juggler.DataSource): RepositoryDecorator;
Parameters
Parameter | Type | Description |
---|---|---|
model | string | typeof Entity | Name/class of the model |
dataSource | string | juggler.DataSource | Name/instance of the dataSource |
Returns:
Example
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
>,
) {}
// ...
}