Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions docs/site/OpenAPI-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,7 @@ connection to the endpoint that exposes an OpenAPI spec.
%}

```ts
import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
Expand All @@ -417,6 +412,10 @@ const config = {
positional: true,
};

// 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 Test2DataSource extends juggler.DataSource
implements LifeCycleObserver {
Expand All @@ -429,21 +428,6 @@ export class Test2DataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
```

Expand Down
22 changes: 1 addition & 21 deletions examples/multi-tenancy/src/datasources/db.datasource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
Expand All @@ -25,19 +20,4 @@ export class DbDataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
22 changes: 1 addition & 21 deletions examples/multi-tenancy/src/datasources/db1.datasource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
Expand All @@ -23,19 +18,4 @@ export class Db1DataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
22 changes: 1 addition & 21 deletions examples/multi-tenancy/src/datasources/db2.datasource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
Expand All @@ -23,19 +18,4 @@ export class Db2DataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
22 changes: 1 addition & 21 deletions examples/validation-app/src/datasources/ds.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
Expand All @@ -30,19 +25,4 @@ export class DsDataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
26 changes: 5 additions & 21 deletions packages/cli/generators/datasource/templates/datasource.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
inject,
lifeCycleObserver,
LifeCycleObserver,
ValueOrPromise,
} from '@loopback/core';
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = <%- dsConfigString %>;

// 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 <%= className %>DataSource extends juggler.DataSource
implements LifeCycleObserver {
Expand All @@ -20,19 +19,4 @@ export class <%= className %>DataSource extends juggler.DataSource
) {
super(dsConfig);
}

/**
* Start the datasource when application is started
*/
start(): ValueOrPromise<void> {
// Add your logic here to be invoked when the application is started
}

/**
* Disconnect the datasource when application is stopped. This allows the
* application to be shut down gracefully.
*/
stop(): ValueOrPromise<void> {
return super.disconnect();
}
}
Loading