5

Our team decided to go with Nest.js for SaaS based application and are new to node.js environment. For the DB store we used postgres which supports multiple schemas per tenant and sequelise is our ORM. Right now we are facing a issue of how to dynamically switch the schema. After doing a lot of research, we could not find a solid way to go about. Below are few things which we came across,

Now my question is since node.js is a single threaded environment, I want to know which of the below mentioned way's is a best use case for sequelise.

  • create a middle ware and set the schema name dynamically to the request headers.

Option 1:

From the documentation of sequelise, there is a an option to set the search path using 'options.searchPath' for each of the orm method's(find, findAll ...). Since node.js is single threaded, passing the schema name in request header and using it in the queries like this,does it cause any issue's to be aware of. In Ruby On Rails we have separate threads using "thread.current" to handle this, can any one explain this approach?

Option 2:

Since we have a code based already, is there a way like the typeOrm version of getting the sequelise db connection dynamically as mentioned above so that we don't change anywhere else in the existing code, if so how to do that?

Thanks

rajesh023
  • 704
  • 1
  • 5
  • 15

0 Answers0