1.2.1 • Published 12 years ago
sequelize-import v1.2.1
sequelize-import
Importing sequelize modules with ease.
Installation
npm install sequelize-importHow to use?
Let we say we have following directory structure:
/path/to/models
├── Contacts
│ └── Contact.js
└── User.jsModel definitions inside *.js files can be something like this:
module.exports = function (sequelize, DataTypes) {
return sequelize.define('User', {
email: DataTypes.STRING,
password: DataTypes.STRING
});
};To include all defined models inside /path/to/models directory and its subdirectories you can use following:
var models = require('sequelize-import')('/path/to/models', sequelize_connection, {
exclude: ['index.js']
});Now you can access to Contact and User models in this way:
models.User
models.Contacts.ContactNote that sequelize-import will recursively search for js files inside specified directory.
With this you can separate models definitions into multiple files, and then load it into some central place, then define relations between models, etc.
Options
exclude
List of files to exclude when generating models
{
exclude: ['index.js', 'something.js']
}Questions
You can send me mail to pusic007@gmail.com if you have any questions.