// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved. // Node module: @loopback/example-todo-list // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; import {juggler} from '@loopback/repository'; const config = { name: 'db', connector: 'memory', localStorage: '', file: './data/db.json', }; // Observe application's life cycle to disconnect the datasource when // application is stopped. This allows the application to be shut down // gracefully. The `stop()` method is inherited from `juggler.DataSource`. // Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html @lifeCycleObserver('datasource') export class DbDataSource extends juggler.DataSource implements LifeCycleObserver { static dataSourceName = 'db'; static readonly defaultConfig = config; constructor( @inject('datasources.config.db', {optional: true}) dsConfig: object = config, ) { super(dsConfig); } }