sequelizemultitenantmodule
v1.4.0
Published
An implementation of the Sequlize module provided by nestjs that supports pooled connections multi tenant databases
Downloads
199
Readme
Installation
$ npm i --save @nestjs/sequelize sequelize-typescript sequelize sequelizemultitenantmodule
Description
Sequelize module for Nest. That supports pooled connections.
This module replaces the standard SequelizeModule
with SequelizeMultiTenantModule
How to use
@Injectable({scope:Scope.REQUEST})
export class SequelizeConfigService implements SequelizeOptionsFactory{
// The intention is you can resolve the DB from the request header or using what ever strategy you prefer
constructor(@Inject(REQUEST) private readonly request:RequestContext){}
createSequelizeOptions(): SequelizeModuleOptions {
//const dbName = this.request.dbName;
const database = 'postgres';
return {
dialect: DB_DIALECT,
host: DB_HOST,
port: Number(DB_PORT),
database: database,
username: DB_USERNAME,
password: DB_PASSWORD,
autoLoadModels: true,
synchronize: true,
};
}
}
SequelizeMultiTenantModule.forRootAsync({
imports: [DatabaseConfigModule],
useExisting: SequelizeConfigService,
}),