A Sails.js 1.x hook that transforms Waterline ORM into a multitenant ORM by providing per-request datasource switching. Current stable version is 0.6.2. It is plug-and-play, non-invasive, and compatible with existing Sails models when models have `multitenant: true`. The hook supports dynamic tenant selection via a custom function that returns datasource connection details (host, port, adapter, etc.). It is maintained but has low activity; last release was in 2020. Key differentiator: full backward compatibility with standard Waterline operations, no need to rewrite model code.
npm install sails-hook-multitenantNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to configure a tenant selector function and mark a model as multitenant to enable per-request datasource switching.
Ensure all multitenant models have `multitenant: true` in their definition.
Use `host`, `port`, `schema`, `adapter`, `user`, `password`, `database`, `identity` in the datasource object.
Use `const Datasource = require('sails-hook-multitenant/datasource');` and create a new instance.Wrap your tenant selection logic in `new Promise((resolve) => { ... resolve(datasource); })`.Always define a multitenancy function in config/. Create e.g. config/tenancy.js with the required function.
Ensure the hook is properly installed and the model has `multitenant: true` (not string). The hook reads this property at lift time.
Return a plain object with the required keys or use `new Datasource(...)`. Ensure function returns the value inside the Promise.
Upgrade to v0.6.2. Use `require('sails-hook-multitenant/datasource')` (with a forward slash, not a dot).Install with `npm install sails-hook-multitenant@0.6.2 --save`. Remove any previous versions and reinstall.