@onivoro/server-typeorm-mysql 22.0.1 → 22.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
@@ -13,6 +13,20 @@ const typeorm_1 = require("typeorm");
13
13
  const data_source_factory_function_1 = require("./functions/data-source-factory.function");
14
14
  const dataSourceMap = new Map();
15
15
  let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormMysqlModule {
16
+ async onApplicationShutdown() {
17
+ for (let dataSourceKey in dataSourceMap.keys()) {
18
+ try {
19
+ const dataSource = dataSourceMap.get(dataSourceKey);
20
+ if (dataSource && dataSource.isInitialized) {
21
+ console.log(`destroying connection ${dataSourceKey}`);
22
+ await dataSource.destroy();
23
+ }
24
+ }
25
+ catch (e) {
26
+ console.error(e?.message);
27
+ }
28
+ }
29
+ }
16
30
  static configure(injectables, entities, options, name = 'default') {
17
31
  const providers = [
18
32
  {
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
@@ -13,6 +13,20 @@ const typeorm_1 = require("typeorm");
13
13
  const data_source_factory_function_1 = require("./functions/data-source-factory.function");
14
14
  const dataSourceMap = new Map();
15
15
  let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormMysqlModule {
16
+ async onApplicationShutdown() {
17
+ for (let dataSourceKey in dataSourceMap.keys()) {
18
+ try {
19
+ const dataSource = dataSourceMap.get(dataSourceKey);
20
+ if (dataSource && dataSource.isInitialized) {
21
+ console.log(`destroying connection ${dataSourceKey}`);
22
+ await dataSource.destroy();
23
+ }
24
+ }
25
+ catch (e) {
26
+ console.error(e?.message);
27
+ }
28
+ }
29
+ }
16
30
  static configure(injectables, entities, options, name = 'default') {
17
31
  const providers = [
18
32
  {
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-mysql",
3
- "version": "22.0.1",
3
+ "version": "22.0.3",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-mysql.git"
6
6
  },