Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-tenanty

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-tenanty

Multi tenant knex middleware. Allows for multiple clients using the same application saving data in different schemas.

  • 0.0.1-beta.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by150%
Maintainers
1
Weekly downloads
 
Created
Source

knex-tenanty

Build Status

Knex middleware to handle multiple tenants.

You can run your application for several clients and the database will be created in different schemas.

Example usage

KnexTenanty(
  /* knex config object */,
  /* function to extract client-id from request object */
);

Sample project

https://github.com/brunolm/knex-mt

Setting up the middleware

import * as express from 'express';

import { KnexTenanty } from 'knex-tenanty';
import knexSettings from '../knexfile';

const app = express.Router();

const settings = knexSettings[process.env.NODE_ENV];
const extractClientId = (req) => req.headers['x-client-id'];

const middleware = KnexTenanty(settings, extractClientId);
app.use(middleware);

export default app;

Using knex to access the database

app.get('/', async (req, res) => {
  console.log('route /');
  const knex = req['knex'] as Knex.QueryBuilder;

  const values = await knex.from('test');
  res.send(values);
});

app.get('/insert', async (req, res) => {
  console.log('route /insert');
  const knex = req['knex'] as Knex.QueryBuilder;

  const values = await knex.insert({ name: req.query.name || 'bruno' }).into('test');
  res.send(values);
});

Keywords

FAQs

Package last updated on 04 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc