multi-tenant

1.0.9 • Public • Published

Multi tenant with mongoose

npm version


Installation

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 the Model is stored Value default of path is.
  • Default value of path argument is path.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: tungduy.dev@gmail.com

Support

Reach out to me at one of the following places!

License

Copyright © 2020 FPT VPN. Crafted with ❤️ by Tùng Duy - tungduy.dev@gmail.com. Released under the MIT License.


This file was generated by Tùng Duy, v1.1.0, on Sept 23, 2021.

Package Sidebar

Install

npm i multi-tenant

Weekly Downloads

14

Version

1.0.9

License

MIT

Unpacked Size

10.5 kB

Total Files

7

Last publish

Collaborators

  • tungduy