@loopback/docs
Version:
Documentation for LoopBack 4
54 lines (33 loc) • 1.32 kB
Markdown
lang: en
title: 'API docs: repository.repositorymixindoc.datasource'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.repository.repositorymixindoc.datasource.html
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/repository](./repository.md) > [RepositoryMixinDoc](./repository.repositorymixindoc.md) > [dataSource](./repository.repositorymixindoc.datasource.md)
## RepositoryMixinDoc.dataSource() method
Add the dataSource to this application.
<b>Signature:</b>
```typescript
dataSource(dataSource: Class<juggler.DataSource> | juggler.DataSource, name?: string): Binding;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| dataSource | <code>Class<juggler.DataSource> | juggler.DataSource</code> | The dataSource to add. |
| name | <code>string</code> | The binding name of the datasource; defaults to dataSource.name |
<b>Returns:</b>
`Binding`
## Example
```ts
const ds: juggler.DataSource = new juggler.DataSource({
name: 'db',
connector: 'memory',
});
app.dataSource(ds);
// The datasource can be injected with
constructor(@inject('datasources.db') dataSource: DataSourceType) {
}
```