Page Contents

Home > @loopback/repository > RepositoryMixinDoc > dataSource

RepositoryMixinDoc.dataSource() method

Add the dataSource to this application.

Signature:

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

Parameters

Parameter Type Description
dataSource Class<juggler.DataSource> | juggler.DataSource The dataSource to add.
name string The binding name of the datasource; defaults to dataSource.name

Returns:

Binding

Example


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

}