modellr
v1.0.13
Published
Database connection manager for Sequelize.
Downloads
7
Maintainers
Readme
modellr
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