tdumitrescu / sequelize-tools

Reduce Sequelize ORM boilerplate/config
13 stars 3 forks source link

providing the right sequelize.js object to connect to the database(multi-tenant application) #1

Open anoopsinghbayes opened 10 years ago

anoopsinghbayes commented 10 years ago

label Question

First some Background:

We are trying to create a multi-tenant application ,we thought of going on with using the mean stack first and create multiple collection for each tenant (eg order_tenant1,order_tenant2 etc) then we went through some blogs that suggested against this approach ,second we felt the need of transaction as a core requirement of our DB thus opened our self's to RDBMS lke mysql and mariaDB ,we stumbled upon a blog http://web.archive.org/web/20120211232457/http://www.reachcrm.com/2010/03/11/multi-tenant-strategy-for-saas-using-mysql5 which explained the approach in a lot of detail which says to create views to get ,update and insert data related to tenant and views parameter would be defined thorugh the connection string as we are using node.js i found ORM for mysql sequelizejs which is quite good .

the actual problem:

as per my experience of the mean stack we define the mongo connection in the server.js file and the application establishes those connection at the application start and keeps them alive , enter image description here how can i have multiple sequelizejs (or for that matter and database connection )objects to connect to the database according to the user belonging to a particular tenant and provide the right object to the application to carry on with the business logic

1)should i create a new connection object on every request the application get and then close it after the request is processed ?

2)or is there any better way to handle this in node ,express or sequelizejs!

yogeshbonzer commented 6 years ago

Is sequelize.js supports multi-tenant functionality?