multi-tenant
v1.0.9
Published
Mongoose multi tenant
Downloads
18
Maintainers
Readme
Multi tenant with mongoose
Installation
Before installing, download and install Node.js. Node.js 14 or higher is required.
Installation is done using the
npm install
command:
Using npm:
# Install package with npm
$ npm install multi-tenant
Using yarn:
# Install package with yarn
$ yarn add multi-tenant
Import module
ES5
const multiTenant = require('multi-tenant');
multiTenant.connectionDb();
#Or
const { connectionDb } = require('multi-tenant');
connectionDb();
ES6
import * as multiTenant from 'multi-tenant';
multiTenant.connectionDb();
#Or
import { connectionDb } from 'multi-tenant';
connectionDb();
Get Model
Inside the function that handles the logic where to connect to the database. Usually in controller, service files or anywhere you want to use.
Let's use getModelByTenant
function to call Model.
import { getModelByTenant } from 'multi-tenant';
const User = await getModelByTenant({ name: 'ModelName' });
API Documentation
getModelByTenant
function expose following api:
connectionDb(options)
The exported connectionDb
function a data object one optional argument.
connectionDb(Object):
Default: { path }
path
argument is path to the directory where theModel
is stored Value default of path is.- Default value of
path
argument ispath.resolve(process.cwd(), 'models')
. This is the path to the Model folder located at the root of the project. - If you have a different directory map architecture, use this parameter as an option. You can completely customize this input parameter.
Authors and acknowledgment
- Project manager:
[email protected]
Support
Reach out to me at one of the following places!
- Email: [email protected]
- Phone: 0358001357
License
Copyright © 2020 FPT VPN. Crafted with :heart: by Tùng Duy - [email protected]. Released under the MIT License.
This file was generated by Tùng Duy, v1.1.0, on Sept 23, 2021.