Skip to content

Commit

Permalink
Merge pull request #951 from alko89/sequelize-uri
Browse files Browse the repository at this point in the history
fix: Add Sequelize URI
  • Loading branch information
kamilmysliwiec committed Jun 24, 2022
2 parents 90e0e77 + dc68600 commit eaa391c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/interfaces/sequelize-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export type SequelizeModuleOptions = {
* Default: true
*/
synchronize?: boolean;
/**
* Sequelize connection string
*/
uri?: string;
} & Partial<SequelizeOptions>;

export interface SequelizeOptionsFactory {
Expand Down
7 changes: 5 additions & 2 deletions lib/sequelize-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ export class SequelizeCoreModule implements OnApplicationShutdown {
): Promise<Sequelize> {
return lastValueFrom(
defer(async () => {
const sequelize = options?.uri
? new Sequelize(options.uri, options)
: new Sequelize(options);

if (!options.autoLoadModels) {
return new Sequelize(options as SequelizeOptions);
return sequelize;
}

const connectionToken = options.name || DEFAULT_CONNECTION_NAME;
const sequelize = new Sequelize(options);
const models = EntitiesMetadataStorage.getEntitiesByConnection(
connectionToken,
);
Expand Down

0 comments on commit eaa391c

Please sign in to comment.