@knetik/micro-postgres

3.0.17 • Public • Published

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 app_id 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

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @knetik/micro-postgres

Weekly Downloads

0

Version

3.0.17

License

MIT

Unpacked Size

21.5 kB

Total Files

6

Last publish

Collaborators

  • knetik