0

I'm currently working on a project (SailsJS 0.11) with different databases. All my users have different read permissions on those databases. For example :

  • I have two databases DB_A and DB_B
  • There are two users USER_A and USER_B
  • USER_A has only the right to read on DB_A
  • USER_B has only the right to read on DB_B

Therefore, I would like to modify my models connection based on the user which is querying them. Is that possible ? How would you do that ?

Thanks for reading and have a nice day !

fwoelffel
  • 412
  • 7
  • 16
  • Possible duplicate of [sails.js - I want to add DB connection dynamically after sails lift](https://stackoverflow.com/questions/29454176/sails-js-i-want-to-add-db-connection-dynamically-after-sails-lift) – Veve Mar 02 '18 at 13:17

1 Answers1

0

In the current version of sails 0.11.x, this is not possible.

You could create a set of models around each connection and change what model your referencing based on each user. You can keep the code DRY, but importing your models definitions from a single place, but have them reference if their on the writeDatabase or the readDatabase. For instance, you could create the user model twice. userWrite.js & userRead.js, each one can import the same model definition with the exception that each references a different db connection.

Meeker
  • 5,979
  • 2
  • 20
  • 38