@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
54 lines (34 loc) • 1.45 kB
Markdown
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) > [@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 | [Class](./repository.class.md)<!-- --><juggler.DataSource> \| juggler.DataSource | The dataSource to add. |
| name | string | The binding name of the datasource; defaults to dataSource.name |
<b>Returns:</b>
[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) {
}
```