---
lang: en
title: 'API docs: repository.repositorymixindoc.datasource'
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.repositorymixindoc.datasource.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [RepositoryMixinDoc](./repository.repositorymixindoc.md) &gt; [dataSource](./repository.repositorymixindoc.datasource.md)

## RepositoryMixinDoc.dataSource() method

Add the dataSource to this application.

**Signature:**

```typescript
dataSource(dataSource: Class<juggler.DataSource> | juggler.DataSource, name?: string): Binding;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  dataSource | [Class](./repository.class.md)<!-- -->&lt;juggler.DataSource&gt; \| juggler.DataSource | The dataSource to add. |
|  name | string | _(Optional)_ The binding name of the datasource; defaults to dataSource.name |

**Returns:**

[Binding](./context.binding.md)

## 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) {

}
```


