Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

modellr

1.0.13 • Public • Published

modellr

Greenkeeper badge npm version Build Status Downloads

Database connection manager for Sequelize.
modellr will also load your models and map them to the DB instance, making them available throughout your application.

Install

$> npm i modellr

Basic example

const m = require('modellr');
const config = {
  database: 'database',
  username: 'username',
  password: 'password',
  dialect: 'postgres',
  logging: false
}

m.load(config, './models/').then(() => {
  // Start your application.
  // You have a persisted DB connection.
});

Have a look at the models in test/models to see how they should be defined.

Usage

You models are available throughout your application, simply require modellr and access whatever model you need.

If, for example, you have a model named User, you may use it like so:

const m = require('modellr');

m.User.findById(123).then((user) => {
  // "user" is your record.
});

All models export the basic Sequelize usage/functionality as documented here.

API

.load(config, models) : Prepare the DB connections (as Sequelize instance) and load all model definitions. Note that this method will read all model definitions files, thus it should only be called once, at application launch.

.instance(alias || null) : Use a particular instance. If the argument is null then the first valid instance will be used.

.close(alias || null) : Close DB connections and terminate the corresponding Sequelize instance. If the argument is null then all open connections will be terminated.

Test

$> npm test

Contribute

fork https://github.com/aichholzer/modellr

License

MIT

Install

npm i modellr

DownloadsWeekly Downloads

27

Version

1.0.13

License

MIT

Unpacked Size

43.9 kB

Total Files

25

Last publish

Collaborators

  • avatar