Skip to content

Commit 38c1405

Browse files
Merge branch 'n-nik-opional-connection-closing-on-shutdown-hook'
2 parents f17279f + 3015f2b commit 38c1405

File tree

3 files changed

+806
-1963
lines changed

3 files changed

+806
-1963
lines changed

lib/interfaces/sequelize-options.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export type SequelizeModuleOptions = {
3333
* Sequelize connection string
3434
*/
3535
uri?: string;
36+
/**
37+
* If `true`, Sequelize connection will close automatically by `onApplicationShutdown` hook handler if shutdown lifecycle hooks are enabled.
38+
* Default value is `true`
39+
*/
40+
autoCloseConnection?: boolean;
3641
} & Partial<SequelizeOptions>;
3742

3843
/**

lib/sequelize-core.module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import {
1414
generateString,
1515
getConnectionToken,
1616
handleRetry,
17-
} from './common/sequelize.utils';
17+
} from './common';
1818
import { EntitiesMetadataStorage } from './entities-metadata.storage';
1919
import {
2020
SequelizeModuleAsyncOptions,
2121
SequelizeModuleOptions,
2222
SequelizeOptionsFactory,
23-
} from './interfaces/sequelize-options.interface';
23+
} from './interfaces';
2424
import {
2525
DEFAULT_CONNECTION_NAME,
2626
SEQUELIZE_MODULE_ID,
@@ -85,6 +85,14 @@ export class SequelizeCoreModule implements OnApplicationShutdown {
8585
}
8686

8787
async onApplicationShutdown() {
88+
if (
89+
typeof this.options.autoCloseConnection !== 'undefined' &&
90+
!this.options.autoCloseConnection
91+
) {
92+
/* Skip closing Sequelize connection automatically by shutdown hook */
93+
return;
94+
}
95+
8896
const connection = this.moduleRef.get<Sequelize>(
8997
getConnectionToken(this.options as SequelizeOptions) as Type<Sequelize>,
9098
);

0 commit comments

Comments
 (0)