This package adds postgres support using sequelize to any [micro-core](https://www.npmjs.com/package/@knetik/micro-core) application as a multi tenant adaptor.

Downloads in past


3.0.174 years ago5 years agoMinified + gzip package size for @knetik/micro-postgres in KB


Knetik Micro Postgres
This package adds postgres support using sequelize to any micro-core application as a multi tenant adaptor.
When a customer connects to a micro-core application, the required appid is passed into the postgres initializer and used as the database name. Then creating a connection and loading any sequelize models defined in the models directory.

Example Usage

In app/models/example.postgres.js
const Sequelize = require('sequelize');

module.exports = (sequelize) => {
  return sequelize.define('example', {
    prop: {
      type: Sequelize.NUMBER
    timestamps  : true,
    underscored : true

In micro-console
App.connect(app_id, access_token)
.then(App => App.Postgres.get('Example'))
.then(Example => Example.create({ prop: 42 }))
.then(res => console.log(res))
.catch(err => console.log(err))

In a micro-core module
module.exports (App) => {
  cosnt Example = App.Postgres.get('Exmaple')
  Example.create({ prop: 42 })


Migrations are handled with umzug: https://github.com/sequelize/umzug
  1. Add migrations to APP_ROOT/db/migrations
  2. Migration status will be checked on each request.
  3. If there are pending migrations, they will be run and then the status will
be cached in the mc_internal_metadata table per client.
Feel free to add migration hook into your deploy tooling.