Skip to content
Open
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
5 changes: 5 additions & 0 deletions lib/interfaces/sequelize-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export type SequelizeModuleOptions = {
* Sequelize connection string
*/
uri?: string;
/**
* If `true`, Sequelize connection will close automatically by `onApplicationShutdown` hook handler if shutdown lifecycle hooks are enabled.
* Default value is `true`
*/
autoCloseConnection?: boolean;
} & Partial<SequelizeOptions>;

/**
Expand Down
12 changes: 10 additions & 2 deletions lib/sequelize-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
generateString,
getConnectionToken,
handleRetry,
} from './common/sequelize.utils';
} from './common';
import { EntitiesMetadataStorage } from './entities-metadata.storage';
import {
SequelizeModuleAsyncOptions,
SequelizeModuleOptions,
SequelizeOptionsFactory,
} from './interfaces/sequelize-options.interface';
} from './interfaces';
import {
DEFAULT_CONNECTION_NAME,
SEQUELIZE_MODULE_ID,
Expand Down Expand Up @@ -85,6 +85,14 @@ export class SequelizeCoreModule implements OnApplicationShutdown {
}

async onApplicationShutdown() {
if (
typeof this.options.autoCloseConnection !== 'undefined' &&
!this.options.autoCloseConnection
) {
/* Skip closing Sequelize connection automatically by shutdown hook */
return;
}

const connection = this.moduleRef.get<Sequelize>(
getConnectionToken(this.options as SequelizeOptions) as Type<Sequelize>,
);
Expand Down
39 changes: 13 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.