Skip to content

aichholzer/modellr

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy